diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f73e981..2bcb687 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,5 +46,6 @@ deploy: - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' - eval $(ssh-agent -s) - 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 - - 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 diff --git a/gitlab/main.go b/gitlab/main.go index f889616..a0bc260 100644 --- a/gitlab/main.go +++ b/gitlab/main.go @@ -1,7 +1,10 @@ package gitlab import ( + "bytes" + "encoding/json" "fmt" + "io" "net/http" @@ -89,6 +92,27 @@ func init() { err = libHTTP.Read(r, &pl) 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: err = nil msg = fmt.Sprintf("unknown gitlab event '%s' received", gitLabEvent) diff --git a/gitlab/request.go b/gitlab/request.go index 56c354f..df45537 100644 --- a/gitlab/request.go +++ b/gitlab/request.go @@ -19,6 +19,7 @@ const ( WikiPageEvents Event = "Wiki Page Hook" PipelineEvents Event = "Pipeline Hook" BuildEvents Event = "Build Hook" + SystemEvents Event = "System Hook" ) type customTime struct { @@ -91,6 +92,7 @@ func (pl *MergeRequestEventPayload) String() string { // PushEventPayload contains the information for GitLab's push event type PushEventPayload struct { + EventName string `json:"event_name"` ObjectKind string `json:"object_kind"` Before string `json:"before"` After string `json:"after"` @@ -98,10 +100,11 @@ type PushEventPayload struct { CheckoutSHA string `json:"checkout_sha"` UserID int64 `json:"user_id"` UserName string `json:"user_name"` + UserUsername string `json:"user_username"` UserEmail string `json:"user_email"` UserAvatar string `json:"user_avatar"` ProjectID int64 `json:"project_id"` - Project Project `json:"Project"` + Project Project `json:"project"` Repository Repository `json:"repository"` Commits []Commit `json:"commits"` TotalCommitsCount int64 `json:"total_commits_count"` @@ -331,10 +334,13 @@ type Project struct { // Repository contains all of the GitLab repository information type Repository struct { - Name string `json:"name"` - URL string `json:"url"` - Description string `json:"description"` - Homepage string `json:"homepage"` + Name string `json:"name"` + URL string `json:"url"` + Description string `json:"description"` + 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 diff --git a/main.go b/main.go index 9a83b71..f158306 100644 --- a/main.go +++ b/main.go @@ -62,7 +62,7 @@ func main() { Addr: config.WebserverBind, } go func() { - if err := srv.ListenAndServe(); err != nil { + if err := srv.ListenAndServe(); err != http.ErrServerClosed { panic(err) } }()