Skip to content

Instantly share code, notes, and snippets.

@Gaurav2728
Last active December 10, 2018 10:49
Show Gist options
  • Save Gaurav2728/bb670c94102e901202400a6b5696c1e4 to your computer and use it in GitHub Desktop.
Save Gaurav2728/bb670c94102e901202400a6b5696c1e4 to your computer and use it in GitHub Desktop.

Print-friendly Assignment

Instructions:

  • Use gitlab private repositories for code and add https://gitlab.com/manu_j as collaborator. Email [email protected] once finished.
  • You can use a webhook testing platform instead of slack but it should follow the slack webhook payload format.

Coding Challenge:

Create a ruby web application, which accepts webhook requests from github.

  • When a label is added to an issue, send a notification to a slack channel.
  • The slack webhook URL should be provided to the app as an environment variable - SLACK_WEBHOOK_URL .
  • Set the username of slack webhook as your email.
  • The notification should be “Label xxxx was added to issue 201”. The issue number should be a link to the github issue.

Extra Credit:

  • Add tests and use the gitlab CI to test
  • Dockerize the application

Sample Github Json Payload

{
  "action": "new_label",
  "controller": "api\/v1\/git_label",
  "git_label": {
    "action": "unlabeled",
    "issue": {
      "url": "https:\/\/api.github.com\/repos\/Gaurav2728\/shoping\/issues\/1",
      "repository_url": "https:\/\/api.github.com\/repos\/Gaurav2728\/shoping",
      "labels_url": "https:\/\/api.github.com\/repos\/Gaurav2728\/shoping\/issues\/1\/labels{\/name}",
      "id": 384074233,
      "node_id": "MDU6SXNzdWUzODQwNzQyMzM=",
      "number": 1,
      "title": "githubhook test issue",
      "user": {
        "login": "Gaurav2728",
        "id": 1284716,
        "node_id": "MDQ6VXNlcjEyODQ3MTY=",
        "received_events_url": "https:\/\/api.github.com\/users\/Gaurav2728\/received_events",
        "type": "User",
        "site_admin": false
      },
      "labels": [
        {
          "id": 21254536,
          "node_id": "MDU6TGFiZWwyMTI1NDUzNg==",
          "url": "https:\/\/api.github.com\/repos\/Gaurav2728\/shoping\/labels\/invalid",
          "name": "invalid",
          "color": "e6e6e6",
          "default": true
        }
      ],
      "state": "open",
      "locked": false,
      "assignee": null,
      "assignees": [

      ],
      "milestone": null,
      "body": ""
    },
    "label": {
      "id": 21254535,
      "node_id": "MDU6TGFiZWwyMTI1NDUzNQ==",
      "url": "https:\/\/api.github.com\/repos\/Gaurav2728\/shoping\/labels\/enhancement",
      "name": "enhancement",
      "color": "84b6eb",
      "default": true
    }
  }
}

Github Repo. URL

https://github.com/Gaurav2728/shoping/

Expected Output

Request Catcher

https://gaurav.requestcatcher.com/

Output

{"text":"Label 'question' added to issue","url":"https://github.com/Gaurav2728/shoping/issues/1"}

{"text":"Label 'duplicate' removed to issue","url":"https://github.com/Gaurav2728/shoping/issues/1"}

Slack

https://ruby-rockers.slack.com/ Channel - test

Output

Label duplicate removed to issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment