Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example: Listen for New Events with PyGithub and Pyramid #930

Merged
merged 20 commits into from
Oct 16, 2018

Conversation

LeviMatus
Copy link
Contributor

@LeviMatus LeviMatus commented Oct 13, 2018

What does this change do?

Adds a small demo implementation of how one might use webhooks to listen for
new events in a given repository.

Additions

doc/examples/Webhook.rst

Adds a new .rst file, Webhook.rst, which can be used for demonstrating the usage of Webhooks in PyGithub.

The example that I've added shows how to continually listen for events using Pyramid in conjunction with PyGithub.

Motivation

This example is in the spirit of #874. It was asked that someone provide an example of how to listen to events from a repository.

How has this been tested?

I've built the docs locally and made sure the HTML is generated as expected.

Screenshots

webhook1
webhook2

@sfdye
Copy link
Member

sfdye commented Oct 13, 2018

I thought this hub endpoint is deprecated? The 2018 way is to use webhook?

@LeviMatus
Copy link
Contributor Author

LeviMatus commented Oct 13, 2018

I thought it was the Github Services that was being deprecated. The PubSubHubHub section mentions that callback strings using github:// will cease to work due to Services being deprecated. I don't see a mention of deprecation regarding the hub endpoints, though I'm not super well versed on the API so I might (probably) have missed something.

Using webhooks to do this would certainly be good. I'll see if I can get that to either replace/go along with this example.

@sfdye
Copy link
Member

sfdye commented Oct 13, 2018

@LeviMatus At least I've only used webhooks in my projects and it's been good so far. But I may be wrong too 😄

some ref:
https://developer.github.com/v3/guides/replacing-github-services/
https://developer.github.com/v3/guides/building-a-ci-server/

@LeviMatus
Copy link
Contributor Author

LeviMatus commented Oct 13, 2018

I probably just misunderstand the deprecation of Github Services and its relation to Hub. However, you're correct in saying that webhooks are the right way of doing this.

I've updated my example accordingly. I've removed the subscription and created a webhook that results in the same usage.

@sfdye
Copy link
Member

sfdye commented Oct 13, 2018

I am thinking whether to make it one level higher and more generic as a webhook example itself, because this will be applicable for not just repo event, but all webhook events. Also FYI there is an official example here by Github which happens to be authored by me some time ago, this may give you some ideas. Let me know what you think ;)

@LeviMatus
Copy link
Contributor Author

Having this be a more generic webhook example makes sense.

This example from Github is cool. I particularly like that you can specify which functions to call based on a header value, like X-Github-Event:push. I wish Flask supported this type of filtering!

I'll rename and/or move this to a place more suitable for working with Webhooks. I'll also get around to trying this out in a fashion similar to that example.

@LeviMatus LeviMatus changed the title Example: Listen for New Events with PyGithub and Flask Example: Listen for New Events with PyGithub and Pyramid Oct 16, 2018
@sfdye
Copy link
Member

sfdye commented Oct 16, 2018

Don't forget to add the index for the new file in examples.rst

if __name__ == "__main__":
config = Configurator()

create_webhook()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can add a mention this step can also be done from Github itself. (under repo settings)

@LeviMatus
Copy link
Contributor Author

Good catches and ideas. I've added a commit to address them.


This is a programatic approach to creating webhooks with PyGithub's API. If you wish, this can be done
manually at your repository's page on Github in the "Settings" section. There is a option there to work with
and confgurd Webhooks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo here

@sfdye sfdye merged commit 9d2129c into PyGithub:master Oct 16, 2018
@sfdye
Copy link
Member

sfdye commented Oct 16, 2018

@LeviMatus Awesome stuff!

candrikos pushed a commit to candrikos/PyGithub that referenced this pull request Sep 25, 2020
## What does this change do?
Adds a small demo implementation of how one might use webhooks to listen for
new events in a given repository.

### Additions
#### doc/examples/Webhook.rst
Adds a new `.rst` file, `Webhook.rst`, which can be used for demonstrating the usage of Webhooks in PyGithub.

The example that I've added shows how to continually listen for events using Pyramid in conjunction with PyGithub.

## Motivation
This example is in the spirit of PyGithub#874. [It was asked](PyGithub#874 (comment)) that someone provide an example of how to listen to events from a repository.

## How has this been tested?
I've built the docs locally and made sure the HTML is generated as expected.

## Screenshots
![webhook1](https://user-images.githubusercontent.com/16039329/46991191-40e58900-d0db-11e8-87e4-d5cf2cc18b0a.png)
![webhook2](https://user-images.githubusercontent.com/16039329/46991193-42af4c80-d0db-11e8-9b20-678f70e6baee.png)
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.

None yet

2 participants