Skip to content

gh-training/gh-app-starter-python

Repository files navigation

Python GitHub App

This app is meant to serve as an application to help you onboard to the GitHub ecosystem and start using GitHub Webhooks & Apps.

Getting Started

Initial Project Setup

  • Clone/Fork this repo
  • Generate your virutal environment
python3 -m venv venv
  • Activate your environment
source venv/bin/activate
  • Install dependencies
pip3 install -r requirements.txt
  • Run the app
flask run

Connecting to GitHub

  • Create a new public repository at https://github.com/new
  • Visit https://smee.io/ and click on Start a new Channel and note the URL
  • Create a new GitHub App - https://github.com/settings/apps/new
  • Give it a distinct name and description (prefix your LDAP)
  • Set Homepage URL = http://localhost:5000/
  • Set User authorization callback URL = http://localhost:5000/authenticate/
  • Check the checkbox for Request user authorization (OAuth) during installation
  • Set Webhook URL = <SMEE_URL>
  • Select the Radio Button for Enable SSL verification
  • Under permissions, give Read & Write permissions for Pull Requests
  • Under Subscribe to Events, check Pull Request
  • Generate and Download the Private key, move it to your app folder on local machine and name it ./private/gh-app.key
  • Hit Save Changes

Now you should be redirected to the App Settings -

  • Under the General tab on the left, find out your App ID

  • Append this App ID to User authorization callback URL, for instance, https://localhost:5000/authenticate/40221

  • Hit Save Changes

  • Go to the Install tab and install the application on only your repository.

  • If you were redirected to GitHub Home Page, your app installation was successful.

  • Open a new terminal window and navigate to where you checked out this repo and activate virual environment as above - source venv/bin/activate

  • Run pysmee forward <SMEE_URL> http://127.0.0.1:5000/webhook - this will forward all events to your app.

See it in action

  • Go ahead and create a new Pull Request in the repository you just added the webhook to
  • Voila! A new comment should be added to it.

Legal

© 2019 LinkedIn