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 )'
|
||||
- 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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue