Skip to content
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

[GH-719] Pushed commits events: add option to show Author instead of committer #729

Merged
merged 10 commits into from
Feb 8, 2024

Conversation

cpatulea
Copy link
Contributor

Summary

Pushed commits events: add option to show Author instead of Committer.

Screenshot

image

What to test?

Before starting, some Mattermost channel should be subscribed to pushed commits notifications for a repo.

  1. Go to plugin settings and set "Pushed commits events: show Author instead of Committer:" to true.
  2. Create a git commit with committer != author. For example, "git am" a patch from someone else, or "git commit --author 'Test author test@example.com'" (example: FOULAB/eigma-test@65ed778)
  3. Push commit to GitHub
  4. Observe the pushed commits notification.

Ticket Link

Fixes #719

@cpatulea cpatulea requested a review from hanzei as a code owner January 10, 2024 09:47
@mattermost-build
Copy link
Contributor

Hello @cpatulea,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

@hanzei hanzei added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Jan 10, 2024
plugin.json Outdated Show resolved Hide resolved
server/plugin/configuration.go Outdated Show resolved Hide resolved
cpatulea and others added 3 commits January 12, 2024 12:57
Co-authored-by: Raghav Aggarwal <raghav.aggarwal@brightscout.com>
Co-authored-by: Raghav Aggarwal <raghav.aggarwal@brightscout.com>
Copy link
Contributor

@raghavaggarwal2308 raghavaggarwal2308 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏽

@cpatulea
Copy link
Contributor Author

Hi @hanzei would you be able to approve for merge, or reassign to someone else if needed? Thanks in advance.

@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (5aa2450) 15.79% compared to head (5e0a5f2) 15.81%.
Report is 1 commits behind head on master.

❗ Current head 5e0a5f2 differs from pull request most recent head fe1ed95. Consider uploading reports for the commit fe1ed95 to get more accurate results

Files Patch % Lines
server/plugin/template.go 44.44% 4 Missing and 1 partial ⚠️
server/plugin/webhook.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #729      +/-   ##
==========================================
+ Coverage   15.79%   15.81%   +0.01%     
==========================================
  Files          15       15              
  Lines        5767     5779      +12     
==========================================
+ Hits          911      914       +3     
- Misses       4814     4822       +8     
- Partials       42       43       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @cpatulea 👍

I would love to see a test for the changes before merging it.

plugin.json Outdated Show resolved Hide resolved
server/plugin/configuration.go Outdated Show resolved Hide resolved
@@ -273,7 +283,7 @@ Assignees: {{range $i, $el := .Assignees -}} {{- if $i}}, {{end}}{{template "use
template.Must(masterTemplate.New("pushedCommits").Funcs(funcMap).Parse(`
{{template "user" .GetSender}} {{if .GetForced}}force-{{end}}pushed [{{len .Commits}} new commit{{if ne (len .Commits) 1}}s{{end}}]({{.GetCompare}}) to [\[{{.GetRepo.GetFullName}}:{{.GetRef | trimRef}}\]]({{.GetRepo.GetHTMLURL}}/tree/{{.GetRef | trimRef}}):
{{range .Commits -}}
[` + "`{{.GetID | substr 0 6}}`" + `]({{.GetURL}}) {{.GetMessage}} - {{.GetCommitter.GetName}}
[` + "`{{.GetID | substr 0 6}}`" + `]({{.GetURL}}) {{.GetMessage}} - {{with . | commitAuthor}}{{.GetName}}{{end}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Is the with needed?

Suggested change
[` + "`{{.GetID | substr 0 6}}`" + `]({{.GetURL}}) {{.GetMessage}} - {{with . | commitAuthor}}{{.GetName}}{{end}}
[` + "`{{.GetID | substr 0 6}}`" + `]({{.GetURL}}) {{.GetMessage}} - {{commitAuthor .}}{{.GetName}}{{end}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm new to Go template language and couldn't get it working without with.

My attempt with:

[` + "`{{.GetID | substr 0 6}}`" + `]({{.GetURL}}) {{.GetMessage}} - {{commitAuthor . | .GetName}}

gives this runtime error:

=== RUN   TestPushedCommitsTemplate/single_commit,_with_'Show_Author_in_commit_notifications'
    template_test.go:785:
        	Error Trace:	/Users/catalinp/src/mattermost-plugin-github/server/plugin/template_test.go:785
        	Error:      	Received unexpected error:
        	            	template: pushedCommits:4:78: executing "pushedCommits" at <.GetName>: can't evaluate field GetName in type *github.HeadCommit
        	            	Could not execute template named pushedCommits
        	            	github.com/mattermost/mattermost-plugin-github/server/plugin.renderTemplate
        	            		/Users/catalinp/src/mattermost-plugin-github/server/plugin/template.go:459
        	            	github.com/mattermost/mattermost-plugin-github/server/plugin.TestPushedCommitsTemplate.func5
        	            		/Users/catalinp/src/mattermost-plugin-github/server/plugin/template_test.go:765
        	            	testing.tRunner
        	            		/opt/homebrew/Cellar/go/1.21.1/libexec/src/testing/testing.go:1595
        	            	runtime.goexit
        	            		/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/asm_arm64.s:1197
        	Test:       	TestPushedCommitsTemplate/single_commit,_with_'Show_Author_in_commit_notifications'

Please let me know if you're aware of a better approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should work with

Suggested change
[` + "`{{.GetID | substr 0 6}}`" + `]({{.GetURL}}) {{.GetMessage}} - {{with . | commitAuthor}}{{.GetName}}{{end}}
[` + "`{{.GetID | substr 0 6}}`" + `]({{.GetURL}}) {{.GetMessage}} - {{commitAuthor .}}{{.GetName}}{{end}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, that is not valid template syntax due to imbalanced end:

$ go test -v ./server/... -run 'TestPushedCommitsTemplate.*'
?   	github.com/mattermost/mattermost-plugin-github/server	[no test files]
?   	github.com/mattermost/mattermost-plugin-github/server/testutils	[no test files]
?   	github.com/mattermost/mattermost-plugin-github/server/plugin/graphql	[no test files]
panic: template: pushedCommits:5: unexpected {{end}}

goroutine 1 [running]:
text/template.Must(...)
	/opt/homebrew/Cellar/go/1.21.6/libexec/src/text/template/helper.go:26
github.com/mattermost/mattermost-plugin-github/server/plugin.init.0()
	/Users/catalinp/src/mattermost-plugin-github/server/plugin/template.go:283 +0x4498
FAIL	github.com/mattermost/mattermost-plugin-github/server/plugin	0.493s
FAIL

@cpatulea
Copy link
Contributor Author

cpatulea commented Jan 23, 2024

I would love to see a test for the changes before merging it.

Done, PTAL.

@cpatulea cpatulea requested a review from hanzei January 23, 2024 15:09
Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a test 👍

server/plugin/template_test.go Outdated Show resolved Hide resolved
server/plugin/template.go Outdated Show resolved Hide resolved
@hanzei
Copy link
Contributor

hanzei commented Jan 23, 2024

@cpatulea I've left two nit pick, but the change LGTM. Please let me know if you want to address them.

@hanzei hanzei removed the 2: Dev Review Requires review by a core committer label Jan 23, 2024
cpatulea and others added 2 commits January 23, 2024 15:51
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
@cpatulea
Copy link
Contributor Author

@cpatulea I've left two nit pick, but the change LGTM. Please let me know if you want to address them.

Yep, I have addressed them.

Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is still complaining about a linter error:

Running golangci-lint
golangci-lint run ./...
server/plugin/template.go:112: File is not `gofmt`-ed with `-s` (gofmt)

@cpatulea
Copy link
Contributor Author

server/plugin/template.go:112: File is not gofmt-ed with -s (gofmt)

Done.

@cpatulea cpatulea requested a review from hanzei January 25, 2024 17:34
Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 👍

My comment in #729 (comment) is non-blocking.

Copy link
Member

@mickmister mickmister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution @cpatulea! LGTM, just one comment for discussion

server/plugin/webhook.go Show resolved Hide resolved
@cpatulea
Copy link
Contributor Author

cpatulea commented Feb 4, 2024

Hey @AayushChaudhary0001 would you be able to take a look when you have a second?

@AayushChaudhary0001
Copy link

@cpatulea Yes, I will review it mostly by this week.

Copy link

@AayushChaudhary0001 AayushChaudhary0001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has been tested for the following scenarios:-

  • Commit shown by author name
  • Commit shown by commiter name

The PR was working fine for both the above conditions, LGTM. Approved

@mickmister mickmister added 4: Reviews Complete All reviewers have approved the pull request and removed 3: QA Review Requires review by a QA tester labels Feb 8, 2024
@mickmister
Copy link
Member

Thanks @cpatulea!

@mickmister mickmister merged commit 87db4b0 into mattermost:master Feb 8, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request Contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Push events: option to show commit author instead of committer
7 participants