forked from forgejo/forgejo
Add more webhooks support and refactor webhook templates directory (#3929)
* add more webhook support * move hooks templates to standalone dir and add more webhooks ui * fix tests * update vendor checksum * add more webhook support * move hooks templates to standalone dir and add more webhooks ui * fix tests * update vendor checksum * update vendor Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * load attributes when created release * update comparsion doc
This commit is contained in:
parent
188fe6c301
commit
24941a1046
33 changed files with 1010 additions and 118 deletions
|
@ -49,6 +49,38 @@ func getDingtalkCreatePayload(p *api.CreatePayload) (*DingtalkPayload, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func getDingtalkDeletePayload(p *api.DeletePayload) (*DingtalkPayload, error) {
|
||||
// created tag/branch
|
||||
refName := git.RefEndName(p.Ref)
|
||||
title := fmt.Sprintf("[%s] %s %s deleted", p.Repo.FullName, p.RefType, refName)
|
||||
|
||||
return &DingtalkPayload{
|
||||
MsgType: "actionCard",
|
||||
ActionCard: dingtalk.ActionCard{
|
||||
Text: title,
|
||||
Title: title,
|
||||
HideAvatar: "0",
|
||||
SingleTitle: fmt.Sprintf("view branch %s", refName),
|
||||
SingleURL: p.Repo.HTMLURL + "/src/" + refName,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getDingtalkForkPayload(p *api.ForkPayload) (*DingtalkPayload, error) {
|
||||
title := fmt.Sprintf("%s is forked to %s", p.Forkee.FullName, p.Repo.FullName)
|
||||
|
||||
return &DingtalkPayload{
|
||||
MsgType: "actionCard",
|
||||
ActionCard: dingtalk.ActionCard{
|
||||
Text: title,
|
||||
Title: title,
|
||||
HideAvatar: "0",
|
||||
SingleTitle: fmt.Sprintf("view forked repo %s", p.Repo.FullName),
|
||||
SingleURL: p.Repo.HTMLURL,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getDingtalkPushPayload(p *api.PushPayload) (*DingtalkPayload, error) {
|
||||
var (
|
||||
branchName = git.RefEndName(p.Ref)
|
||||
|
@ -98,6 +130,80 @@ func getDingtalkPushPayload(p *api.PushPayload) (*DingtalkPayload, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func getDingtalkIssuesPayload(p *api.IssuePayload) (*DingtalkPayload, error) {
|
||||
var text, title string
|
||||
switch p.Action {
|
||||
case api.HookIssueOpened:
|
||||
title = fmt.Sprintf("[%s] Issue opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
|
||||
text = p.Issue.Body
|
||||
case api.HookIssueClosed:
|
||||
title = fmt.Sprintf("[%s] Issue closed: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
|
||||
text = p.Issue.Body
|
||||
case api.HookIssueReOpened:
|
||||
title = fmt.Sprintf("[%s] Issue re-opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
|
||||
text = p.Issue.Body
|
||||
case api.HookIssueEdited:
|
||||
title = fmt.Sprintf("[%s] Issue edited: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
|
||||
text = p.Issue.Body
|
||||
case api.HookIssueAssigned:
|
||||
title = fmt.Sprintf("[%s] Issue assigned to %s: #%d %s", p.Repository.FullName,
|
||||
p.Issue.Assignee.UserName, p.Index, p.Issue.Title)
|
||||
text = p.Issue.Body
|
||||
case api.HookIssueUnassigned:
|
||||
title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
|
||||
text = p.Issue.Body
|
||||
case api.HookIssueLabelUpdated:
|
||||
title = fmt.Sprintf("[%s] Pull request labels updated: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
|
||||
text = p.Issue.Body
|
||||
case api.HookIssueLabelCleared:
|
||||
title = fmt.Sprintf("[%s] Pull request labels cleared: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
|
||||
text = p.Issue.Body
|
||||
case api.HookIssueSynchronized:
|
||||
title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title)
|
||||
text = p.Issue.Body
|
||||
}
|
||||
|
||||
return &DingtalkPayload{
|
||||
MsgType: "actionCard",
|
||||
ActionCard: dingtalk.ActionCard{
|
||||
Text: text,
|
||||
Title: title,
|
||||
HideAvatar: "0",
|
||||
SingleTitle: "view pull request",
|
||||
SingleURL: p.Issue.URL,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getDingtalkIssueCommentPayload(p *api.IssueCommentPayload) (*DingtalkPayload, error) {
|
||||
title := fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title)
|
||||
url := fmt.Sprintf("%s/issues/%d#%s", p.Repository.HTMLURL, p.Issue.Index, CommentHashTag(p.Comment.ID))
|
||||
var content string
|
||||
switch p.Action {
|
||||
case api.HookIssueCommentCreated:
|
||||
title = "New comment: " + title
|
||||
content = p.Comment.Body
|
||||
case api.HookIssueCommentEdited:
|
||||
title = "Comment edited: " + title
|
||||
content = p.Comment.Body
|
||||
case api.HookIssueCommentDeleted:
|
||||
title = "Comment deleted: " + title
|
||||
url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index)
|
||||
content = p.Comment.Body
|
||||
}
|
||||
|
||||
return &DingtalkPayload{
|
||||
MsgType: "actionCard",
|
||||
ActionCard: dingtalk.ActionCard{
|
||||
Text: content,
|
||||
Title: title,
|
||||
HideAvatar: "0",
|
||||
SingleTitle: "view pull request",
|
||||
SingleURL: url,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getDingtalkPullRequestPayload(p *api.PullRequestPayload) (*DingtalkPayload, error) {
|
||||
var text, title string
|
||||
switch p.Action {
|
||||
|
@ -182,6 +288,27 @@ func getDingtalkRepositoryPayload(p *api.RepositoryPayload) (*DingtalkPayload, e
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func getDingtalkReleasePayload(p *api.ReleasePayload) (*DingtalkPayload, error) {
|
||||
var title, url string
|
||||
switch p.Action {
|
||||
case api.HookReleasePublished:
|
||||
title = fmt.Sprintf("[%s] Release created", p.Release.TagName)
|
||||
url = p.Release.URL
|
||||
return &DingtalkPayload{
|
||||
MsgType: "actionCard",
|
||||
ActionCard: dingtalk.ActionCard{
|
||||
Text: title,
|
||||
Title: title,
|
||||
HideAvatar: "0",
|
||||
SingleTitle: "view repository",
|
||||
SingleURL: url,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetDingtalkPayload converts a ding talk webhook into a DingtalkPayload
|
||||
func GetDingtalkPayload(p api.Payloader, event HookEventType, meta string) (*DingtalkPayload, error) {
|
||||
s := new(DingtalkPayload)
|
||||
|
@ -189,12 +316,22 @@ func GetDingtalkPayload(p api.Payloader, event HookEventType, meta string) (*Din
|
|||
switch event {
|
||||
case HookEventCreate:
|
||||
return getDingtalkCreatePayload(p.(*api.CreatePayload))
|
||||
case HookEventDelete:
|
||||
return getDingtalkDeletePayload(p.(*api.DeletePayload))
|
||||
case HookEventFork:
|
||||
return getDingtalkForkPayload(p.(*api.ForkPayload))
|
||||
case HookEventIssues:
|
||||
return getDingtalkIssuesPayload(p.(*api.IssuePayload))
|
||||
case HookEventIssueComment:
|
||||
return getDingtalkIssueCommentPayload(p.(*api.IssueCommentPayload))
|
||||
case HookEventPush:
|
||||
return getDingtalkPushPayload(p.(*api.PushPayload))
|
||||
case HookEventPullRequest:
|
||||
return getDingtalkPullRequestPayload(p.(*api.PullRequestPayload))
|
||||
case HookEventRepository:
|
||||
return getDingtalkRepositoryPayload(p.(*api.RepositoryPayload))
|
||||
case HookEventRelease:
|
||||
return getDingtalkReleasePayload(p.(*api.ReleasePayload))
|
||||
}
|
||||
|
||||
return s, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue