-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MM-356] Add feature to subscribe to release and workflow events #765
base: master
Are you sure you want to change the base?
Changes from 2 commits
5dc7a26
e5c50fd
ec69c2d
32882a1
28cdb5a
0d050ac
612a259
96ed032
ab37277
f9034c4
b629477
e5385bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,12 @@ const ( | |
actionLabeled = "labeled" | ||
actionAssigned = "assigned" | ||
|
||
actionCreated = "created" | ||
actionDeleted = "deleted" | ||
actionEdited = "edited" | ||
actionCreated = "created" | ||
actionDeleted = "deleted" | ||
actionEdited = "edited" | ||
actionCompleted = "completed" | ||
|
||
workflowJobFail = "failure" | ||
|
||
postPropGithubRepo = "gh_repo" | ||
postPropGithubObjectID = "gh_object_id" | ||
|
@@ -282,6 +285,11 @@ func (p *Plugin) handleWebhook(w http.ResponseWriter, r *http.Request) { | |
handler = func() { | ||
p.postStarEvent(event) | ||
} | ||
case *github.WorkflowJobEvent: | ||
repo = event.GetRepo() | ||
handler = func() { | ||
p.postWorkflowJobEvent(event) | ||
} | ||
} | ||
|
||
if handler == nil { | ||
|
@@ -1377,3 +1385,44 @@ func (p *Plugin) postStarEvent(event *github.StarEvent) { | |
} | ||
} | ||
} | ||
|
||
func (p *Plugin) postWorkflowJobEvent(event *github.WorkflowJobEvent) { | ||
if event.GetAction() != actionCompleted { | ||
return | ||
} | ||
|
||
// Create a post only when the workflow job is completed and fails | ||
if event.GetWorkflowJob().GetConclusion() != workflowJobFail { | ||
return | ||
} | ||
|
||
repo := event.GetRepo() | ||
subs := p.GetSubscribedChannelsForRepository(repo) | ||
|
||
if len(subs) == 0 { | ||
return | ||
} | ||
|
||
newWorkflowJobMessage, err := renderTemplate("newWorkflowJob", event) | ||
if err != nil { | ||
p.client.Log.Warn("Failed to render template", "Error", err.Error()) | ||
return | ||
} | ||
|
||
for _, sub := range subs { | ||
if !sub.Workflows() { | ||
continue | ||
} | ||
Comment on lines
+1374
to
+1377
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1/5 I think we should support (or require) a Just the
All workflows
@hanzei What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me 👍 Limiting the notifications to a specific branch seems like a common use case. Can we include that in there as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@mickmister Are you suggesting here to add a subscription on the basis of the workflow name, which is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@mickmister @hanzei For the above case, what should be the slash command format? Should we keep something like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Mainly thinking of the complexity of the |
||
|
||
post := &model.Post{ | ||
UserId: p.BotUserID, | ||
Type: "custom_git_workflow_job", | ||
Message: newWorkflowJobMessage, | ||
ChannelId: sub.ChannelID, | ||
} | ||
|
||
if err = p.client.Post.CreatePost(post); err != nil { | ||
p.client.Log.Warn("Error webhook post", "Post", post, "Error", err.Error()) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should rename the flag to
workflow-failures
to make it clear that only these get notifications. Or add an option toworkflows
that specifies if only failed or also successful runs should trigger a notification.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the flag to
workflow-failures
. Let me know if I should do the latter one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we should have separate
workflow-success
andworkflow-failure
subscription typesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mickmister Added the
workflow_success
. Please have a lookThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hanzei are you still requesting changes here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did the
README.md
updates go?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hanzei Since the plugin functionality details have been moved to mattermost docs repo, I have made a PR on it for the same