Skip to content

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

Merged
mickmister merged 10 commits into
mattermost:masterfrom
FOULAB:master
Feb 8, 2024
Merged

[GH-719] Pushed commits events: add option to show Author instead of committer#729
mickmister merged 10 commits into
mattermost:masterfrom
FOULAB:master

Conversation

@cpatulea

Copy link
Copy Markdown
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: https://github.com/FOULAB/eigma-test/commit/65ed77834f659a0498c5d02cc319e38bd12c50f3)
  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
Copy Markdown
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
Comment thread plugin.json Outdated
Comment thread server/plugin/configuration.go Outdated
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>

@raghavaggarwal2308 raghavaggarwal2308 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM 👍🏽

@cpatulea

Copy link
Copy Markdown
Contributor Author

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

@codecov-commenter

codecov-commenter commented Jan 23, 2024

Copy link
Copy Markdown

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.

@hanzei hanzei left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread plugin.json Outdated
Comment thread server/plugin/configuration.go Outdated
Comment thread server/plugin/template.go
{{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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

cpatulea commented Jan 23, 2024

Copy link
Copy Markdown
Contributor Author

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

@hanzei hanzei left a comment

Copy link
Copy Markdown
Contributor

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 👍

Comment thread server/plugin/template_test.go Outdated
Comment thread server/plugin/template.go Outdated
@hanzei

hanzei commented Jan 23, 2024

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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.

@hanzei hanzei left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

@hanzei hanzei left a comment

Copy link
Copy Markdown
Contributor

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.

@mickmister mickmister left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread server/plugin/webhook.go
@cpatulea

cpatulea commented Feb 4, 2024

Copy link
Copy Markdown
Contributor Author

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

@AayushChaudhary0001

Copy link
Copy Markdown

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

@AayushChaudhary0001 AayushChaudhary0001 left a comment

Copy link
Copy Markdown

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
Copy Markdown
Contributor

Thanks @cpatulea!

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