diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-07-10 19:37:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-10 11:37:16 +0000 |
commit | 72b6bc8cafe1d64ff30481170cd68b85a710c67e (patch) | |
tree | 1156e8b92053cb588863ee1ea05db3e804a0831f /services/webhook/dingtalk.go | |
parent | 4ea2a6de81ab6adde436d77e2743095fafa6a7a9 (diff) | |
download | gitea-72b6bc8cafe1d64ff30481170cd68b85a710c67e.tar.gz gitea-72b6bc8cafe1d64ff30481170cd68b85a710c67e.zip |
Refactor webhook (#31587)
A more complete fix for #31588
1. Make "generic" code more readable
2. Clarify HTML or Markdown for the payload content
Diffstat (limited to 'services/webhook/dingtalk.go')
-rw-r--r-- | services/webhook/dingtalk.go | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index f6018f7374..e382f5a9df 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -20,8 +20,8 @@ import ( ) type ( - // DingtalkPayload represents - DingtalkPayload dingtalk.Payload + DingtalkPayload dingtalk.Payload + dingtalkConvertor struct{} ) // Create implements PayloadConvertor Create method @@ -92,9 +92,9 @@ func (dc dingtalkConvertor) Push(p *api.PushPayload) (DingtalkPayload, error) { // Issue implements PayloadConvertor Issue method func (dc dingtalkConvertor) Issue(p *api.IssuePayload) (DingtalkPayload, error) { - text, issueTitle, attachmentText, _ := getIssuesPayloadInfo(p, noneLinkFormatter, true) + text, issueTitle, extraMarkdown, _ := getIssuesPayloadInfo(p, noneLinkFormatter, true) - return createDingtalkPayload(issueTitle, text+"\r\n\r\n"+attachmentText, "view issue", p.Issue.HTMLURL), nil + return createDingtalkPayload(issueTitle, text+"\r\n\r\n"+extraMarkdown, "view issue", p.Issue.HTMLURL), nil } // Wiki implements PayloadConvertor Wiki method @@ -114,9 +114,9 @@ func (dc dingtalkConvertor) IssueComment(p *api.IssueCommentPayload) (DingtalkPa // PullRequest implements PayloadConvertor PullRequest method func (dc dingtalkConvertor) PullRequest(p *api.PullRequestPayload) (DingtalkPayload, error) { - text, issueTitle, attachmentText, _ := getPullRequestPayloadInfo(p, noneLinkFormatter, true) + text, issueTitle, extraMarkdown, _ := getPullRequestPayloadInfo(p, noneLinkFormatter, true) - return createDingtalkPayload(issueTitle, text+"\r\n\r\n"+attachmentText, "view pull request", p.PullRequest.HTMLURL), nil + return createDingtalkPayload(issueTitle, text+"\r\n\r\n"+extraMarkdown, "view pull request", p.PullRequest.HTMLURL), nil } // Review implements PayloadConvertor Review method @@ -186,10 +186,7 @@ func createDingtalkPayload(title, text, singleTitle, singleURL string) DingtalkP } } -type dingtalkConvertor struct{} - -var _ payloadConvertor[DingtalkPayload] = dingtalkConvertor{} - func newDingtalkRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) { - return newJSONRequest(dingtalkConvertor{}, w, t, true) + var pc payloadConvertor[DingtalkPayload] = dingtalkConvertor{} + return newJSONRequest(pc, w, t, true) } |