MobilityData / mobility-feed-api

Apache License 2.0
8 stars 3 forks source link

Slack and Github webhooks in feed submission cloud function #663

Open Alessandro100 opened 1 month ago

Alessandro100 commented 1 month ago

Slack Webhook info can be found in 1Password: "Slack webhook URLs"

And these two POST requests should normally send a notification for sucess or failure in the add-feeds channel. A webhook is usally for one channel, but I add the channel ID in the payload to make sure it ends up in the correct channel

POST https://hooks.slack.com/services/.....
Content-type: application/json
{
    "channel": "C072DF86VQB",
    "blocks": [
      {
        "type": "header",
        "text": {
          "type": "plain_text",
          "text": ":white_check_mark: Added/updated feed(s)",
          "emoji": true
        }
      },
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "${{ steps.process-csv.outputs.NUMBER_OF_FEEDS }} feed(s) were added or updated in a new branch on the https://github.com/MobilityData/mobility-database-catalogs repo."
        }
      },
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "New branch name: `${{ steps.create_branch_name.outputs.BRANCH }}`\n\n*Open the new branch:* [https://github.com/MobilityData/mobility-database-catalogs/tree/${{](https://github.com/MobilityData/mobility-database-catalogs/tree/$%7B%7B) steps.create_branch_name.outputs.BRANCH }}\n\n*Open the corresponding PR:* ${{ steps.create-pr.outputs.pull-request-url }}"
        }
      },
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "See the source document here: https://docs.google.com/spreadsheets/d/1Q96KDppKsn2khdrkraZCQ7T_qRSfwj7WsvqXvuMt4Bc/edit#gid=2061813733"
        }
      }
    ]
  }

POST https://hooks.slack.com/services/.....
Content-type: application/json
{
    "channel": "C072DF86VQB",
    "blocks": [
    {
        "type": "header",
        "text": {
        "type": "plain_text",
        "text": ":x: FAILED — Add/update feed(s)",
        "emoji": true
        }
    },
    {
        "type": "section",
        "text": {
        "type": "mrkdwn",
        "text": "The GitHub action has failed on the https://github.com/MobilityData/mobility-database-catalogs repo."
        }
    },
    {
        "type": "section",
        "text": {
        "type": "mrkdwn",
        "text": "*Open the action run:* [https://github.com/MobilityData/mobility-database-catalogs/actions/runs/${{](https://github.com/MobilityData/mobility-database-catalogs/actions/runs/$%7B%7B) env.RUN_ID }}"
        }
    },
    {
        "type": "section",
        "text": {
        "type": "mrkdwn",
        "text": "See the source document here: https://docs.google.com/spreadsheets/d/1Q96KDppKsn2khdrkraZCQ7T_qRSfwj7WsvqXvuMt4Bc/edit#gid=2061813733"
        }
    }
    ]
}

https://api.slack.com/messaging/webhooks

Github

  1. The repo is mobility-database-catalogs
  2. For the issue content, see the attached MKDocs file. You will need to put in your own vars of course, I’ve put a few placeholders. If possible, whenever a field is empty if it could be omitted from that content, it would be great. That’s something I couldn’t do with Zapier.
  3. We usually use the io@mobilitydata.org account to do this kind of stuff so automations aren’t linked to one person.
  4. If you need a GitHub Token, use the generic one stored under “GitHub generic action token for all repos” in 1Password. Ideally a separate token just for this would be ideal.
  5. As for creating an issue via GitHub’s API, here’s the docs: https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#create-an-issue
Alessandro100 commented 3 weeks ago

Tasks [] Have a slack message "Feed was added" appear in "internal-add-feeds" slack channel [M] [] Create a github issue in mobility-database-catalogs with label "feed submission" [M]

Note: Can be split