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

leverage templates for webhook messages #73

Merged
merged 5 commits into from
Jun 18, 2019
Merged

Conversation

lieut-data
Copy link
Member

This change replaces the fmt.Sprintf strategy for rendering webhook messages with Go's text/template package, extracting sub-templates for common components. A few minor changes were made along the way:

  • "Issue ... closed by" now links the repo vs just wrapping it with brackets
  • (force-)pushed now pluralizes "commits" only when necessary

In addition, whenever rendering a GitHub username, if there is a linked Mattermost user, the rendered message replaces this with an @username mention for the corresponding Mattermost user. In the future, I hope to be able to expose this mapping for other plugins to do the same.

I need some feedback on how to properly test this -- there are unit tests for all the templates, but of course I have to populate sample data, and I really want to see the markdown rendering on a real Mattermost server. Do we have a shared testing OAuth app that can be used for localhost testing as such?

This change replaces the `fmt.Sprintf` strategy for rendering messages with Go's `text/template` package, extracting sub-templates for common components. A few minor changes were made along the way:

* "Issue ... closed by" now links the repo vs just wrapping it with brackets
* (force-)pushed now pluralizes "commits" only when necessary

In addition, whenever rendering a GitHub username, if there is a linked Mattermost user, the rendered message replaces this with an @username mention for the corresponding Mattermost user.
@lieut-data lieut-data added the 2: Dev Review Requires review by a core committer label May 21, 2019
Copy link
Member

@jwilander jwilander left a comment

Choose a reason for hiding this comment

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

Much cleaner, really nice 👍 Translating usernames is awesome too

@lieut-data
Copy link
Member Author

@crspeller, I've been able to test the issue/pull request open/close/comment flows via a fork of the mattermost-server (and I fixed an escape issue with brackets), but it's going to be hard to test the review flow without another test user on GitHub. Wondering if it made sense for me to register my webhook on the real mattermost-server instead and consume all the real events there to vet everything?

@crspeller
Copy link
Member

@lieut-data I don't quite understand the ask. What exactly are you looking to capture?

@lieut-data
Copy link
Member Author

@crspeller, essentially I'm looking for a low-friction way of forcing the plugin to render all the various messages "for real". Right now, the testing amounts to simulating all the events by hand on a repository I control, but I'm now at the point of doing multi-actor testing (e.g. a reviewer and an author), and I'm hoping not to jump through those hoops. Hooking up a repository like mattermost-server temporarily to my ngrok-exposed GitHub plugin would probably give me the coverage I need.

Ideally, we would capture these webhooks, store them and replay for future testing. Maybe something we can build into the GitHub plugin itself to stream all events to disk.

@crspeller
Copy link
Member

Chatted offline with @lieut-data setup the webhook for him and more tests are going to be added before this is merged.

@hanzei hanzei added Work In Progress Not yet ready for review and removed 2: Dev Review Requires review by a core committer labels Jun 3, 2019
@lieut-data
Copy link
Member Author

@jwilander & @crspeller, I was able to verify a number of other events, but didn't end up getting a full set to provide 100% coverage of these changes with "real data". (The new unit tests cover all the new code, except that the event data is of course faked.)

With 5.12 having been cut, what are your thoughts on merging this now and letting it soak in master over the next two months while we iterate separately on a test framework that would give us the desired coverage here?

@jwilander
Copy link
Member

I'm completely fine with that 👍

@lieut-data lieut-data added 2: Dev Review Requires review by a core committer and removed Work In Progress Not yet ready for review labels Jun 7, 2019
@crspeller
Copy link
Member

Sounds good. Going to hold off merging for a couple days though, because I am probably patching github again for this release.

@crspeller crspeller added Do Not Merge Should not be merged until this label is removed and removed 2: Dev Review Requires review by a core committer labels Jun 7, 2019
@crspeller crspeller self-assigned this Jun 7, 2019
@lieut-data lieut-data added the 4: Reviews Complete All reviewers have approved the pull request label Jun 7, 2019
@jasonblais
Copy link
Contributor

@crspeller / @lieut-data Is this one ready to merge?

@crspeller crspeller merged commit 8aad9df into master Jun 18, 2019
@crspeller crspeller deleted the leverage-go-templates branch June 18, 2019 18:38
@crspeller
Copy link
Member

@jasonblais Thanks for the reminder!

@crspeller crspeller removed the Do Not Merge Should not be merged until this label is removed label Jun 18, 2019
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants