mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Improve webhooks (#8583)
* Improve webhooks Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update MSTeams and ReviewPayload comment Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add repo.FullName to comments Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
		| @@ -74,7 +74,7 @@ func getMSTeamsCreatePayload(p *api.CreatePayload) (*MSTeamsPayload, error) { | ||||
| 	return &MSTeamsPayload{ | ||||
| 		Type:       "MessageCard", | ||||
| 		Context:    "https://schema.org/extensions", | ||||
| 		ThemeColor: fmt.Sprintf("%x", successColor), | ||||
| 		ThemeColor: fmt.Sprintf("%x", greenColor), | ||||
| 		Title:      title, | ||||
| 		Summary:    title, | ||||
| 		Sections: []MSTeamsSection{ | ||||
| @@ -117,7 +117,7 @@ func getMSTeamsDeletePayload(p *api.DeletePayload) (*MSTeamsPayload, error) { | ||||
| 	return &MSTeamsPayload{ | ||||
| 		Type:       "MessageCard", | ||||
| 		Context:    "https://schema.org/extensions", | ||||
| 		ThemeColor: fmt.Sprintf("%x", warnColor), | ||||
| 		ThemeColor: fmt.Sprintf("%x", yellowColor), | ||||
| 		Title:      title, | ||||
| 		Summary:    title, | ||||
| 		Sections: []MSTeamsSection{ | ||||
| @@ -159,7 +159,7 @@ func getMSTeamsForkPayload(p *api.ForkPayload) (*MSTeamsPayload, error) { | ||||
| 	return &MSTeamsPayload{ | ||||
| 		Type:       "MessageCard", | ||||
| 		Context:    "https://schema.org/extensions", | ||||
| 		ThemeColor: fmt.Sprintf("%x", successColor), | ||||
| 		ThemeColor: fmt.Sprintf("%x", greenColor), | ||||
| 		Title:      title, | ||||
| 		Summary:    title, | ||||
| 		Sections: []MSTeamsSection{ | ||||
| @@ -228,7 +228,7 @@ func getMSTeamsPushPayload(p *api.PushPayload) (*MSTeamsPayload, error) { | ||||
| 	return &MSTeamsPayload{ | ||||
| 		Type:       "MessageCard", | ||||
| 		Context:    "https://schema.org/extensions", | ||||
| 		ThemeColor: fmt.Sprintf("%x", successColor), | ||||
| 		ThemeColor: fmt.Sprintf("%x", greenColor), | ||||
| 		Title:      title, | ||||
| 		Summary:    title, | ||||
| 		Sections: []MSTeamsSection{ | ||||
| @@ -272,48 +272,48 @@ func getMSTeamsIssuesPayload(p *api.IssuePayload) (*MSTeamsPayload, error) { | ||||
| 	case api.HookIssueOpened: | ||||
| 		title = fmt.Sprintf("[%s] Issue opened: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
| 		text = p.Issue.Body | ||||
| 		color = warnColor | ||||
| 		color = orangeColor | ||||
| 	case api.HookIssueClosed: | ||||
| 		title = fmt.Sprintf("[%s] Issue closed: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
| 		color = failedColor | ||||
| 		color = redColor | ||||
| 		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 | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueEdited: | ||||
| 		title = fmt.Sprintf("[%s] Issue edited: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
| 		text = p.Issue.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	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 | ||||
| 		color = successColor | ||||
| 		color = greenColor | ||||
| 	case api.HookIssueUnassigned: | ||||
| 		title = fmt.Sprintf("[%s] Issue unassigned: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
| 		text = p.Issue.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueLabelUpdated: | ||||
| 		title = fmt.Sprintf("[%s] Issue labels updated: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
| 		text = p.Issue.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueLabelCleared: | ||||
| 		title = fmt.Sprintf("[%s] Issue labels cleared: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
| 		text = p.Issue.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueSynchronized: | ||||
| 		title = fmt.Sprintf("[%s] Issue synchronized: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
| 		text = p.Issue.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueMilestoned: | ||||
| 		title = fmt.Sprintf("[%s] Issue milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
| 		text = p.Issue.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueDemilestoned: | ||||
| 		title = fmt.Sprintf("[%s] Issue clear milestone: #%d %s", p.Repository.FullName, p.Index, p.Issue.Title) | ||||
| 		text = p.Issue.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	} | ||||
|  | ||||
| 	return &MSTeamsPayload{ | ||||
| @@ -356,26 +356,41 @@ func getMSTeamsIssuesPayload(p *api.IssuePayload) (*MSTeamsPayload, error) { | ||||
| } | ||||
|  | ||||
| func getMSTeamsIssueCommentPayload(p *api.IssueCommentPayload) (*MSTeamsPayload, error) { | ||||
| 	title := fmt.Sprintf("#%d %s", p.Issue.Index, p.Issue.Title) | ||||
| 	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)) | ||||
| 	content := "" | ||||
| 	var color int | ||||
| 	switch p.Action { | ||||
| 	case api.HookIssueCommentCreated: | ||||
| 		title = "New comment: " + title | ||||
| 		if p.IsPull { | ||||
| 			title = "New comment on pull request " + title | ||||
| 			color = greenColorLight | ||||
| 		} else { | ||||
| 			title = "New comment on issue " + title | ||||
| 			color = orangeColorLight | ||||
| 		} | ||||
| 		content = p.Comment.Body | ||||
| 		color = successColor | ||||
| 	case api.HookIssueCommentEdited: | ||||
| 		title = "Comment edited: " + title | ||||
| 		if p.IsPull { | ||||
| 			title = "Comment edited on pull request " + title | ||||
| 		} else { | ||||
| 			title = "Comment edited on issue " + title | ||||
| 		} | ||||
| 		content = p.Comment.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueCommentDeleted: | ||||
| 		title = "Comment deleted: " + title | ||||
| 		if p.IsPull { | ||||
| 			title = "Comment deleted on pull request " + title | ||||
| 		} else { | ||||
| 			title = "Comment deleted on issue " + title | ||||
| 		} | ||||
| 		url = fmt.Sprintf("%s/issues/%d", p.Repository.HTMLURL, p.Issue.Index) | ||||
| 		content = p.Comment.Body | ||||
| 		color = warnColor | ||||
| 		color = redColor | ||||
| 	} | ||||
|  | ||||
| 	title = fmt.Sprintf("[%s] %s", p.Repository.FullName, title) | ||||
|  | ||||
| 	return &MSTeamsPayload{ | ||||
| 		Type:       "MessageCard", | ||||
| 		Context:    "https://schema.org/extensions", | ||||
| @@ -422,24 +437,24 @@ func getMSTeamsPullRequestPayload(p *api.PullRequestPayload) (*MSTeamsPayload, e | ||||
| 	case api.HookIssueOpened: | ||||
| 		title = fmt.Sprintf("[%s] Pull request opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		color = greenColor | ||||
| 	case api.HookIssueClosed: | ||||
| 		if p.PullRequest.HasMerged { | ||||
| 			title = fmt.Sprintf("[%s] Pull request merged: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 			color = successColor | ||||
| 			color = purpleColor | ||||
| 		} else { | ||||
| 			title = fmt.Sprintf("[%s] Pull request closed: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 			color = failedColor | ||||
| 			color = redColor | ||||
| 		} | ||||
| 		text = p.PullRequest.Body | ||||
| 	case api.HookIssueReOpened: | ||||
| 		title = fmt.Sprintf("[%s] Pull request re-opened: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueEdited: | ||||
| 		title = fmt.Sprintf("[%s] Pull request edited: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueAssigned: | ||||
| 		list := make([]string, len(p.PullRequest.Assignees)) | ||||
| 		for i, user := range p.PullRequest.Assignees { | ||||
| @@ -449,31 +464,31 @@ func getMSTeamsPullRequestPayload(p *api.PullRequestPayload) (*MSTeamsPayload, e | ||||
| 			strings.Join(list, ", "), | ||||
| 			p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = successColor | ||||
| 		color = greenColor | ||||
| 	case api.HookIssueUnassigned: | ||||
| 		title = fmt.Sprintf("[%s] Pull request unassigned: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueLabelUpdated: | ||||
| 		title = fmt.Sprintf("[%s] Pull request labels updated: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueLabelCleared: | ||||
| 		title = fmt.Sprintf("[%s] Pull request labels cleared: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueSynchronized: | ||||
| 		title = fmt.Sprintf("[%s] Pull request synchronized: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueMilestoned: | ||||
| 		title = fmt.Sprintf("[%s] Pull request milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	case api.HookIssueDemilestoned: | ||||
| 		title = fmt.Sprintf("[%s] Pull request clear milestone: #%d %s", p.Repository.FullName, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	} | ||||
|  | ||||
| 	return &MSTeamsPayload{ | ||||
| @@ -526,8 +541,18 @@ func getMSTeamsPullRequestApprovalPayload(p *api.PullRequestPayload, event HookE | ||||
| 		} | ||||
|  | ||||
| 		title = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title) | ||||
| 		text = p.PullRequest.Body | ||||
| 		color = warnColor | ||||
| 		text = p.Review.Content | ||||
|  | ||||
| 		switch event { | ||||
| 		case HookEventPullRequestApproved: | ||||
| 			color = greenColor | ||||
| 		case HookEventPullRequestRejected: | ||||
| 			color = redColor | ||||
| 		case HookEventPullRequestComment: | ||||
| 			color = greyColor | ||||
| 		default: | ||||
| 			color = yellowColor | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return &MSTeamsPayload{ | ||||
| @@ -576,10 +601,10 @@ func getMSTeamsRepositoryPayload(p *api.RepositoryPayload) (*MSTeamsPayload, err | ||||
| 	case api.HookRepoCreated: | ||||
| 		title = fmt.Sprintf("[%s] Repository created", p.Repository.FullName) | ||||
| 		url = p.Repository.HTMLURL | ||||
| 		color = successColor | ||||
| 		color = greenColor | ||||
| 	case api.HookRepoDeleted: | ||||
| 		title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName) | ||||
| 		color = warnColor | ||||
| 		color = yellowColor | ||||
| 	} | ||||
|  | ||||
| 	return &MSTeamsPayload{ | ||||
| @@ -623,15 +648,15 @@ func getMSTeamsReleasePayload(p *api.ReleasePayload) (*MSTeamsPayload, error) { | ||||
| 	case api.HookReleasePublished: | ||||
| 		title = fmt.Sprintf("[%s] Release created", p.Release.TagName) | ||||
| 		url = p.Release.URL | ||||
| 		color = successColor | ||||
| 		color = greenColor | ||||
| 	case api.HookReleaseUpdated: | ||||
| 		title = fmt.Sprintf("[%s] Release updated", p.Release.TagName) | ||||
| 		url = p.Release.URL | ||||
| 		color = successColor | ||||
| 		color = greenColor | ||||
| 	case api.HookReleaseDeleted: | ||||
| 		title = fmt.Sprintf("[%s] Release deleted", p.Release.TagName) | ||||
| 		url = p.Release.URL | ||||
| 		color = successColor | ||||
| 		color = greenColor | ||||
| 	} | ||||
|  | ||||
| 	return &MSTeamsPayload{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user