React on note when feedback is given
What does this MR do and why?
There is no feedback loop back to the user, when running @gitlab-bot feedback
you don't know if it was received:
1.) The bot could be down 2.) Slack could be down 3.) The request to slack could have failed in rare events
In addition, as an user - it would be more comfortable to be confident the feedback was received.
So, this MR implements two things:
-
add_emoji_award
inreactions.rb
(https://docs.gitlab.com/ee/user/award_emojis.html) - A feedback loop to the user by adding
✅ (:white_check_mark:
) to any feedback comment AFTER it has been submitted to Slack.
Expected impact & dry-runs
Type | Request URI |
---|---|
dry run | POST https://gitlab.com/api/v4/projects/278964/merge_requests/79545/notes/826964861/award_emoji, params: {:name=>\"white_check_mark\"} |
localhost | POST http://127.0.0.1:3000/api/v4/projects/2/merge_requests/1/notes/209/award_emoji |
gitlab.org | POST https://gitlab.com/api/v4/projects/7776928/merge_requests/2418/notes/1553641859/award_emoji, params: {:name=>\"white_check_mark\"} |
- https://gitlab.com/api/v4/projects/7776928/merge_requests/2418/notes/1553641859/award_emoji
- https://github.com/NARKOZ/gitlab/blob/master/lib/gitlab/client/award_emojis.rb#L84
Dry run
GITLAB_COM_API_TOKEN=0 DRY_RUN=1 bundle exec rack-console
slack_messenger = Slack::Messenger.new(ENV.fetch('SLACK_WEBHOOK_URL', "https://foo.bar/baxz"), {}); # note: i added a try/catch on post_mr_feedback_request
ev = Triage::MergeRequestNoteEvent.new(JSON.parse(File.read('spec/fixtures/reactive/note_on_merge_request.json')));
Triage::CommandMrFeedback.new(ev, messenger: slack_messenger).process
=> "POST https://gitlab.com/api/v4/projects/278964/merge_requests/79545/notes/137882768/award_emoji, params: `{:name=>\"white_check_mark\"}`"
Against gitlab.com
Fetching the payload from setting a reaction and adding that on the note_on_merge_request.json
mock, we can simulate a rough production scenario to ensure it maps correctly:
# ...
Triage::CommandMrFeedback.new(ev, messenger: slack_messenger).process
=> "POST https://gitlab.com/api/v4/projects/7776928/merge_requests/2418/notes/1553641849/award_emoji, params: `{:name=>\"white_check_mark\"}`"
You can also visit this directly (GET): https://gitlab.com/api/v4/projects/7776928/merge_requests/2418/notes/1553641859/award_emoji Or use CURL (POST):
curl --location 'https://gitlab.com/api/v4/projects/7776928/merge_requests/2418/notes/1553641859/award_emoji' \
--header 'Content-Type: application/json' \
--header 'X-Gitlab-Token: glpat-PATTOKEN' \
--data '{"name":"thumbsup"}'
Testing instructions for reviewers
- Check out the branch
- Follow the local gdk setup, I had to work around some cases due to local failures.
- Set up a webhook that listens to Note events, send yourself a Note type Webhook.
- It does not need to be a valid url, you can view the payload in Gitlab
- Replace the contents of note_on_merge_request.json
- Comment out
command_mr_feedback
=>post_mr_feedback_request
, or set up a (in)valid slack hook. This is not relevant to this MR and just makes testing complicated. - Run the following snippet of code in
bundle exec rack-console
:
slack_messenger = Slack::Messenger.new(ENV.fetch('SLACK_WEBHOOK_URL', "https://foo.bar/baxz"), {});
ev = Triage::MergeRequestNoteEvent.new(JSON.parse(File.read('spec/fixtures/reactive/note_on_merge_request.json')));
Triage::CommandMrFeedback.new(ev, messenger: slack_messenger).process
- Observe comment now having a slack emoji
✅ on it. (may fail with{"message": "404 Award Emoji Name has already been taken Not Found"}
if it's already given
Alternatively, you may know of better ways, this is just how I did it :)
Action items
-
If adding environment variables for reactive processors, update config/triage-web.yaml
and.gitlab/ci/triage-web.yml
-
(If applicable) Add documentation to the handbook pages for Triage Operations => - (If applicable) Identify the affected groups and how to communicate to them:
-
/cc @ person_or_group
=> -
Relevant Slack channels => -
Engineering week-in-review
-
Edited by Jos Ahrens