This repository was archived by the owner on Nov 1, 2017. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork1.1k
Merge master#428
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Merge master#428
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletionsRules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioncontent/v3/repos/deployments.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
46 changes: 23 additions & 23 deletionscontent/v3/repos/hooks.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletionscontent/v3/troubleshooting.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletionscontent/webhooks/configuring/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
title: Configuring Your Server | GitHub API | ||
layout: webhooks | ||
--- | ||
# Configuring Your Server | ||
* TOC | ||
{:toc} | ||
Now that our webhook is ready to deliver messages, we'll set up a basic Sinatra server | ||
to handle incoming payloads. | ||
Recall that we specifically set our webhook URL to `http://localhost:4567/payload`. | ||
Since we're developing locally, we'll need to expose our local development environment | ||
to the Internet, so that GitHub can send out messages, and our local server can | ||
process them. | ||
Note: you can download the complete source code for this project | ||
[from the platform-samples repo][platform samples]. | ||
## Using ngrok | ||
First, we'll install a program to expose our local host to the Internet. We'll use | ||
ngrok to do this. [ngrok is a free download](https://ngrok.com/download) available | ||
for all major operating systems. | ||
When you're done with that, you can expose your localhost by running `./ngrok 4567` | ||
on the command line. You should see a line that looks something like this: | ||
#!bash | ||
Forwarding http://7e9ea9dc.ngrok.com -> 127.0.0.1:4567 | ||
Copy that funky `*.ngrok.com` URL! We're now going to go *back* to the Payload | ||
URL and pasting this server into that field. It should look something like `http://7e9ea9dc.ngrok.com/payload`. | ||
By doing this, we've set ourselves up to expose our localhost at path `/payload` | ||
to the Internet. | ||
## Writing the server | ||
Now comes the fun part! We want out server to listen to `POST` requests, at `/payload`, | ||
because that's where we told GitHub our webhook URL was. Since ngrok is exposing | ||
our local environment, we don't need to set up a real server someone online, and | ||
can happily test out our code locally. | ||
Let's set up a little Sinatra app to do something with the information. Our initial | ||
setup might look something like this: | ||
#!ruby | ||
require 'sinatra' | ||
require 'json' | ||
post '/payload' do | ||
push = JSON.parse(params[:payload]) | ||
puts "I got some JSON: #{push.inspect}" | ||
end | ||
(If you're unfamiliar with how Sinatra works, we recommend [reading the Sinatra guide][Sinatra guide].) | ||
Start this server up. | ||
Since we set up our webhook to listen to events dealing with `Issues`, go ahead | ||
and create a new Issue on the repository you're testing with. Once you create | ||
it, switch back to your terminal. You should see something like this in your output: | ||
#!bash | ||
[adding-hooks]* ~/github/platform-samples/hooks/ruby/configuring-your-server $ ruby server.rb | ||
== Sinatra/1.4.4 has taken the stage on 4567 for development with backup from Thin | ||
>> Thin web server (v1.5.1 codename Straight Razor) | ||
>> Maximum connections set to 1024 | ||
>> Listening on localhost:4567, CTRL+C to stop | ||
I got some JSON: {"action"=>"opened", "issue"=>{"url"=>"... | ||
Success! You've successfully configured your server to listen to webhooks. Your | ||
server can now process this information any way you see fit. For example, if you | ||
were setting up a "real" web application, you might want to log some of the JSON | ||
output to a database. | ||
For additional information on working with webhooks for fun and profit, head on | ||
over to the [Testing Webhooks](/hooks/testing) guide. | ||
[platform samples]: https://github.com/github/platform-samples/tree/master/hooks/ruby/configuring-your-server | ||
[Sinatra]: http://www.sinatrarb.com/ |
57 changes: 57 additions & 0 deletionscontent/webhooks/creating/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
title: Creating Webhooks | GitHub API | ||
layout: webhooks | ||
--- | ||
# Creating Webhooks | ||
* TOC | ||
{:toc} | ||
At their core, webhooks are events generated by GitHub that deliver a payload of | ||
information about activity in a repository. Webhooks can trigger across several | ||
different actions. For example, you can fire a payload of information any time | ||
a commit is made, a repository is forked, or an issue is created. | ||
In this tutorial, our webhook will be responsible for listing out how popular our | ||
repository is, based on the number of Issues it receives per day. | ||
Creating a webhook is a two-step process. You'll first need to set up how you want | ||
your webhook to behave through GitHub--what events should it listen to. After that, | ||
you'll set up your server to receive and manage the payload. | ||
## Setting up a Webhook | ||
To set up a webhook on GitHub, head over to the **Settings** page of your repository, | ||
and click on **Webhooks & services**. After that, click on **Add webhook**. | ||
You'll be presented with a page that lists all the capabilities your webhook | ||
can take advantage of. We'll go through each of these below. | ||
## Payload URL | ||
This is the server endpoint that will receive the webhook payload. | ||
Since we're developing locally for our tutorial, let's set it to `http://localhost:4567/payload`. | ||
We'll explain why in the [Configuring Your Server](/hooks/configuring/) docs. | ||
## Payload version | ||
Webhooks can deliver various [media types](/v3/media/) as defined by the GitHub API. | ||
Choose the one that best fits your needs. For this tutorial, the default format is fine. | ||
## Events | ||
Events are at the core of webhooks. These webhooks fire whenever a certain action is | ||
taken on the repository, which your server's payload URL intercepts and acts upon. | ||
A full list of webhook events, and when they execute, can be found in [the webhooks API][hooks-api] reference. | ||
Since our webhook is dealing with Issues in a repository, we'll click on **Issues**, | ||
and toggle the options there. | ||
When you're finished, click on **Add webhook**. Phew! Now that the webhook is created, | ||
it's time to set up our local server to test the webhook. Head on over to | ||
[Configuring Your Server](/hooks/configuring/) to learn how to do that. | ||
[hooks-api]: http://developer.github.com/v3/repos/hooks/#events |
12 changes: 12 additions & 0 deletionscontent/webhooks/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: Webhooks | GitHub API | ||
layout: webhooks | ||
--- | ||
Every GitHub repository has the option to communicate with a web server whenever | ||
the repository is pushed to. These "webhooks" can be used to update an external | ||
issue tracker, trigger CI builds, update a backup mirror, or even deploy to your | ||
production server. | ||
This section of the GitHub Developer Guide will instruct you on how to develop, configure, | ||
and test your first webhook. |
40 changes: 40 additions & 0 deletionscontent/webhooks/testing/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: Testing Webhooks | GitHub API | ||
layout: webhooks | ||
--- | ||
# Testing Webhooks | ||
* TOC | ||
{:toc} | ||
Now that you've [configured your local server](/hooks/configuring/), you might | ||
be interested in pushing your code to the limits. To that end, GitHub's webhooks | ||
view provides some tooling for testing your deployed payloads. | ||
## Listing recent deliveries | ||
Every webhook has its own "Recent Deliveries" section, which lists, at a glance | ||
whether a deployment was successful (green dot) or failed (red dot). | ||
 | ||
You can also identify when each delivery was attempted. | ||
## Digging into results | ||
By expanding an individual delivery, you'll be able to witness *precisely* | ||
what information GitHub is attempting to send to your server. This includes | ||
both the HTTP Request and Response. | ||
### Request | ||
The webhook delivery view provides information on which Headers were sent by GitHub. | ||
It also includes details about the JSON payload. | ||
## Response | ||
The response tab lists how your server replied once it received the payload from | ||
GitHub. This includes the status code, the headers, and any additional data | ||
within the response body. |
10 changes: 5 additions & 5 deletionslayouts/guides.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionslayouts/header.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.