Documentation
¶
Overview ¶
Package webhook defines payload format of GitLab webhook
It also provides a simple wrapper for you to easily create applications handle webhooks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Build ¶
type Build struct { ID int `json:"id"` Stage string `json:"stage"` Name string `json:"name"` Status string `json:"status"` CreatedAt string `json:"created_at"` StartedAt string `json:"started_at,omitempty"` FinishedAt string `json:"finished_at,omitempty"` When string `json:"when"` Manual bool `json:"manual"` User User `json:"user"` Runner string `json:"runner"` ArtifactsFile struct { Filename string `json:"filename,omitempty"` Size int `json:"size,omitempty"` } `json:"artifacts_file"` }
Build represents build info in webhook payload
type CommentEvent ¶
type CommentEvent struct { ObjectKind string `json:"object_kind"` User User `json:"user"` Project Project `json:"project"` Commit Commit `json:"commit,omitempty"` MergeRequest MergeRequest `json:"merge_request,omitempty"` Issue Issue `json:"issue,omitempty"` Snippet Snippet `json:"snippet,omitempty"` ObjectAttributes struct { CommonAttribute ObjectAttribute Note string `json:"note"` NoteableType string `json:"noteable_type"` Attachment string `json:"attachment,omitempty"` LineCode string `json:"line_code,omitempty"` CommitID string `json:"commit_id,omitempty"` NoteableID int `json:"noteable_id"` System bool `json:"system,omitempty"` STDiff Diff `json:"st_diff,omitempty"` } `json:"object_attributes"` }
CommentEvent defines payload format for comment on commit
type Commit ¶
type Commit struct { ID string `json:"id"` Message string `json:"message"` Timestamp string `json:"timestamp"` URL string `json:"url"` Author struct { Name string `json:"name"` Email string `json:"email"` } `json:"author"` Added []string `json:"added,omitempty"` Modified []string `json:"modified,omitempty"` Removed []string `json:"removed,omitempty"` }
Commit represents commit info in webhook payload
type CommonAttribute ¶
type CommonAttribute struct { ID int `json:"id"` AuthorID int `json:"author_id"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` }
CommonAttribute represents common attributes
type Diff ¶
type Diff struct { Diff string `json:"diff"` NewPath string `json:"new_path"` OldPath string `json:"old_path"` AMode string `json:"a_mode"` BMode string `json:"b_mode"` NewFile bool `json:"new_file,omitempty"` RenamedFile bool `json:"renamed_file,omitempty"` DeletedFile bool `json:"deleted_file,omitempty"` }
Diff represents diff info in webhook payload
type Handler ¶
type Handler struct { Token string Push chan PushEvent Tag chan TagEvent Issue chan IssueEvent Comment chan CommentEvent MergeRequest chan MergeRequestEvent Wiki chan WikiEvent Pipeline chan PipelineEvent }
Handler handles webhook requests and dispatch events via channel. You just set channels you want to receive, and pass the channel to your application.
func handlePushEvent(ch chan PushEvent) { for e := range ch { log.Printf( "%s pushed %d commits to %s", e.UserName, e.TotalCommitCount, e.Project.PathWithNamespace, ) } } handler := &Handler{Push: make(chan PushEvent)} go handlePushEvent(handler.Push) http.Handle("/webhook", handler) http.ListenAndServe(":80", nil)
You can set Token for enabling secret token verification
type Issue ¶
type Issue struct { CommonAttribute Title string `json:"title"` AssigneeID int `json:"assignee_id"` Position int `json:"position,omitempty"` BranchName string `json:"branch_name,omitempty"` Description string `json:"description"` MilestoneID int `json:"milestone_id"` State string `json:"state"` IID int `json:"iid"` }
Issue represents issue info in webhook payload
type IssueEvent ¶
type IssueEvent struct { ObjectKind string `json:"object_kind"` User User `json:"user"` Assignee User `json:"assignee"` ObjectKindAttributes struct { Issue ObjectAttribute } `json:"object_attributes"` }
IssueEvent defines payload format of issue event
type MergeRequest ¶
type MergeRequest struct { Issue TargetBranch string `json:"target_branch"` SourceBranch string `json:"source_branch"` TargetProjectID int `json:"target_project_id"` SourceProjectID int `json:"source_project_id"` MergeStatus string `json:"merge_status"` LockedAt string `json:"locaked_at,omitempty"` Target Project `json:"target"` Source Project `json:"source"` LastCommit Commit `json:"last_commit"` WorkInProgress bool `json:"work_in_progress"` Assignee User `json:"assignee"` }
MergeRequest represents merge request in webhook payload
type MergeRequestEvent ¶
type MergeRequestEvent struct { ObjectKind string `json:"object_kind"` User User `json:"user,omitempty"` ObjectAttributes struct { MergeRequest ObjectAttribute STCommits []Commit `json:"st_commits,omitempty"` STDiffs []Diff `json:"st_diffs,omitempty"` } `json:"object_attributes"` }
MergeRequestEvent defines payload format of merge request event
type ObjectAttribute ¶
type ObjectAttribute struct { ProjectID int `json:"project_id,omitempty"` URL string `json:"url"` Action string `json:"action,omitempty"` }
ObjectAttribute represents common object attributes.
To prevent name collision, CommonAttribute is not embbeded.
type PipelineEvent ¶
type PipelineEvent struct { ObjectKind string `json:"object_kind"` User User `json:"user"` Project Project `json:"project"` Commit Commit `json:"commit"` Builds []Build `json:"builds"` ObjectAttributes struct { ID int `json:"id"` Ref string `json:"ref"` Tag bool `json:"tag"` SHA string `json:"sha"` BeforeSHA string `json:"before_sha"` Status string `json:"status"` Stages []string `json:"stages"` CreatedAt string `json:"created_at"` FinishedAt string `json:"finished_at"` Duration int `json:"duration"` } `json:"object_attributes"` }
PipelineEvent defines payload format for pipeline event
type Project ¶
type Project struct { Wiki Name string `json:"name"` Description string `json:"description"` AvatarURL string `json:"avatar_url,omitempty"` Namespace string `json:"namespace"` VisibilityLevel int `json:"visibility_level"` Homepage string `json:"homepage,omitempty"` URL string `json:"url,omitempty"` }
Project represents project info in webhook payload
type PushEvent ¶
type PushEvent struct { ObjectKind string `json:"object_kind"` Before string `json:"before"` After string `json:"after"` Ref string `json:"ref"` CheckoutSHA string `json:"checkout_sha"` UserID int `json:"user_id"` UserName string `json:"user_name"` UserEmail string `json:"user_email"` UserAvatar string `json:"user_avatar"` ProjectID int `json:"project_id"` Project Project `json:"project"` Commits []Commit `json:"commits"` TotalCommitCount int `json:"total_commit_count"` }
PushEvent defines payload format of push event
type Snippet ¶
type Snippet struct { CommonAttribute Title string `json:"title"` Content string `json:"content"` ProjectID int `json:"project_id"` FileName string `json:"file_name"` ExpiresAt string `json:"expires_at"` Type string `json:"type"` VisibilityLevel int `json:"visibility_level"` }
Snippet represents snippet info in webhook payload
type TagEvent ¶
type TagEvent struct { ObjectKind string `json:"object_kind"` Before string `json:"before"` After string `json:"after"` Ref string `json:"ref"` CheckoutSHA string `json:"checkout_sha"` UserID int `json:"user_id"` UserName string `json:"user_name"` UserAvatar string `json:"user_avatar"` ProjectID int `json:"project_id"` Project Project `json:"project"` Commits []Commit `json:"commits"` TotalCommitCount int `json:"total_commit_count"` }
TagEvent defines payload format of tag push event
type User ¶
type User struct { Name string `json:"name,omitempty"` Username string `json:"username,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` }
User represents user info in webhook payload
type Wiki ¶
type Wiki struct { WebURL string `json:"web_url"` GitSshURL string `json:"git_ssh_url,omitempty"` GitHttpURL string `json:"git_http_url,omitempty"` PathWithNamespace string `json:"path_with_namespace"` DefaultBranch string `json:"default_branch"` }
Wiki represents wiki info in webhook payload
type WikiEvent ¶
type WikiEvent struct { ObjectKind string `json:"object_kind"` User User `json:"user"` Project Project `json:"project"` Wiki Wiki `json:"wiki"` ObjectAttributes struct { ObjectAttribute Title string `json:"title"` Content string `json:"content"` Format string `json:"format"` Message string `json:"message"` Slug string `json:"slug"` } `json:"object_attributes"` }
WikiEvent defines payload format of wiki event