handle system events
This commit is contained in:
parent
a0493bd805
commit
bef47512bc
|
@ -46,5 +46,6 @@ deploy:
|
||||||
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
|
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
|
||||||
- eval $(ssh-agent -s)
|
- eval $(ssh-agent -s)
|
||||||
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
|
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
|
||||||
|
- ssh -6 -o StrictHostKeyChecking=no -p $SSH_PORT "$CI_PROJECT_NAME@$SSH_HOST" sudo /usr/bin/systemctl stop $CI_PROJECT_NAME
|
||||||
- scp -6 -o StrictHostKeyChecking=no -P $SSH_PORT "/go/bin/$CI_PROJECT_NAME" "$CI_PROJECT_NAME@$SSH_HOST":/opt/$CI_PROJECT_NAME/bin
|
- scp -6 -o StrictHostKeyChecking=no -P $SSH_PORT "/go/bin/$CI_PROJECT_NAME" "$CI_PROJECT_NAME@$SSH_HOST":/opt/$CI_PROJECT_NAME/bin
|
||||||
- ssh -6 -o StrictHostKeyChecking=no -p $SSH_PORT "$CI_PROJECT_NAME@$SSH_HOST" sudo /usr/bin/systemctl restart $CI_PROJECT_NAME
|
- ssh -6 -o StrictHostKeyChecking=no -p $SSH_PORT "$CI_PROJECT_NAME@$SSH_HOST" sudo /usr/bin/systemctl start $CI_PROJECT_NAME
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package gitlab
|
package gitlab
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -89,6 +92,27 @@ func init() {
|
||||||
err = libHTTP.Read(r, &pl)
|
err = libHTTP.Read(r, &pl)
|
||||||
msg = pl.String()
|
msg = pl.String()
|
||||||
|
|
||||||
|
case SystemEvents:
|
||||||
|
var data map[string]interface{}
|
||||||
|
var buf bytes.Buffer
|
||||||
|
tee := io.TeeReader(r.Body, &buf)
|
||||||
|
if err = json.NewDecoder(tee).Decode(&data); err != nil {
|
||||||
|
msg = fmt.Sprintf("unable to decode gitlab system event")
|
||||||
|
} else if event, ok := data["event_name"]; ok {
|
||||||
|
switch event {
|
||||||
|
case "push":
|
||||||
|
var pl PushEventPayload
|
||||||
|
err = json.NewDecoder(&buf).Decode(&pl)
|
||||||
|
msg = fmt.Sprintf("[S]%s", pl.String())
|
||||||
|
default:
|
||||||
|
err = nil
|
||||||
|
msg = fmt.Sprintf("unknown gitlab system event '%s' received", event)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = nil
|
||||||
|
msg = fmt.Sprintf("unable to get 'event_name' of gitlab '%s'", gitLabEvent)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = nil
|
err = nil
|
||||||
msg = fmt.Sprintf("unknown gitlab event '%s' received", gitLabEvent)
|
msg = fmt.Sprintf("unknown gitlab event '%s' received", gitLabEvent)
|
||||||
|
|
|
@ -19,6 +19,7 @@ const (
|
||||||
WikiPageEvents Event = "Wiki Page Hook"
|
WikiPageEvents Event = "Wiki Page Hook"
|
||||||
PipelineEvents Event = "Pipeline Hook"
|
PipelineEvents Event = "Pipeline Hook"
|
||||||
BuildEvents Event = "Build Hook"
|
BuildEvents Event = "Build Hook"
|
||||||
|
SystemEvents Event = "System Hook"
|
||||||
)
|
)
|
||||||
|
|
||||||
type customTime struct {
|
type customTime struct {
|
||||||
|
@ -91,6 +92,7 @@ func (pl *MergeRequestEventPayload) String() string {
|
||||||
|
|
||||||
// PushEventPayload contains the information for GitLab's push event
|
// PushEventPayload contains the information for GitLab's push event
|
||||||
type PushEventPayload struct {
|
type PushEventPayload struct {
|
||||||
|
EventName string `json:"event_name"`
|
||||||
ObjectKind string `json:"object_kind"`
|
ObjectKind string `json:"object_kind"`
|
||||||
Before string `json:"before"`
|
Before string `json:"before"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
|
@ -98,10 +100,11 @@ type PushEventPayload struct {
|
||||||
CheckoutSHA string `json:"checkout_sha"`
|
CheckoutSHA string `json:"checkout_sha"`
|
||||||
UserID int64 `json:"user_id"`
|
UserID int64 `json:"user_id"`
|
||||||
UserName string `json:"user_name"`
|
UserName string `json:"user_name"`
|
||||||
|
UserUsername string `json:"user_username"`
|
||||||
UserEmail string `json:"user_email"`
|
UserEmail string `json:"user_email"`
|
||||||
UserAvatar string `json:"user_avatar"`
|
UserAvatar string `json:"user_avatar"`
|
||||||
ProjectID int64 `json:"project_id"`
|
ProjectID int64 `json:"project_id"`
|
||||||
Project Project `json:"Project"`
|
Project Project `json:"project"`
|
||||||
Repository Repository `json:"repository"`
|
Repository Repository `json:"repository"`
|
||||||
Commits []Commit `json:"commits"`
|
Commits []Commit `json:"commits"`
|
||||||
TotalCommitsCount int64 `json:"total_commits_count"`
|
TotalCommitsCount int64 `json:"total_commits_count"`
|
||||||
|
@ -335,6 +338,9 @@ type Repository struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Homepage string `json:"homepage"`
|
Homepage string `json:"homepage"`
|
||||||
|
GitSSSHURL string `json:"git_ssh_url"`
|
||||||
|
GitHTTPURL string `json:"git_http_url"`
|
||||||
|
VisibilityLevel int64 `json:"visibility_level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectAttributes contains all of the GitLab object attributes information
|
// ObjectAttributes contains all of the GitLab object attributes information
|
||||||
|
|
Loading…
Reference in New Issue