Skip to content

Conversation

@github-learning-lab
Copy link

Triggering GitHub Apps

Actions that a person or tool takes on GitHub can be used to trigger events. Creating an issue, making a commit, or leaving a comment, to name a few, are logged on GitHub. If GitHub doesn't use it, it can still be useful to other applications.

When you install an app, you give the app permission to receive some of this data from GitHub. That data allows the apps to react in ways that are useful to you. You can also allow the app to send information back, or change information completely.

It's important to mention that GitHub Apps are not people. You can't interact with them by doing things like using an @mention, or assigning them to review your work. On the other hand, they can do things that humans can't - like crunch big data, piece together networks of information and find bugs or errors that people wouldn't.

App components

An app is like a home security system. It's equipped to watch your house at all times, but only notifies you for specific criteria. When you install a home security system, you need to worry about a few components:

  • Electricity to have the power to run continuously. You don't want failure when you aren't watching.
  • Standard behaviors to detect things like movement, noise, and doors opening. You don't want to have to program it to understand these actions -- you want to select how it responds to them.
  • A location that will be watched.
  • A notification delivery service -- either to your phone, a dedicated security service, or both.

Just like a home security system, a GitHub App only watches for specific actions, and then responds in predetermined ways.

Step 2: Trigger the WIP app

WIP is a common abbreviation to mean work in progress.

The app you've just installed is concerned with one action: changing the title of a pull request. Let's test it out and see what the result is by updating the title of this pull request.

⌨️ Activity: Test the app by editing the pull request title

  1. To the right of the pull request title, click the Edit button
  2. Add WIP to the beginning of the title
  3. Click Save

After changing the title, look for my response in this pull request

@johnlugton johnlugton changed the title Trigger the app WIP Trigger the app Dec 9, 2020
@github-learning-lab
Copy link
Author

Nice job! Something changed on this repo when you added the "WIP" command. Let's try to get more insight into our app before we look at those changes.

Breaking down the WIP app components

  • Electricity: Since this is a Probot app, the power to run comes from deployment, set up by the app creators. We don't need to worry about this until we build an app ourselves.
  • Standard behaviors: GitHub has a list of documented events that can alert an app.
  • Location: Apps are designed to look for pre-determined events in whichever repositories they've been installed. On installation, it has to ask permission for each event type that it wants to monitor.
  • Notification service: If the expected action occurs, a notification delivery is sent to the app as a webhook payload -- a specific set of data transmitted via GitHub's API.

GitHub Apps will then process this data in the background, responding to the repository with their expected default actions.

Extra credit: For more information about webhooks, we recommend this GitHub Community Forum article.

Step 3: Looking under the hood

For the next exercise, let's add our own notification service to get a better idea of what apps are receiving behind the scenes.

⌨️ Activity: Adding a webhook payload delivery service

  1. Navigate to https://smee.io/ in another tab or window (keep this tab open for the rest of the course).
  2. Click Start a new channel
  3. Copy your unique "Webhook Proxy URL"
  4. In your webhooks settings, click Add webhook
  5. Paste your unique smee.io URL in the "Payload URL" field
  6. Choose application/json in the Content type dropdown
  7. Leave the "Secret" field blank
  8. For "Which events would you like to trigger this webhook?", select Send me everything
  9. Click Add webhook
  10. Return to this pull request and paste your smee.io URL as a comment

Look for my response in a comment on this pull request

Sometimes I respond too fast for the page to update! If you perform an expected action and don't see a response from me, wait a few seconds and refresh the page for your next steps.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant