Skip to content

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:

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\"}

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

  1. Check out the branch
  2. Follow the local gdk setup, I had to work around some cases due to local failures.
  3. Set up a webhook that listens to Note events, send yourself a Note type Webhook.
    1. It does not need to be a valid url, you can view the payload in Gitlab
  4. Replace the contents of note_on_merge_request.json
  5. 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.
  6. 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
  1. 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

Edited by Jos Ahrens

Merge request reports