SlideShare a Scribd company logo
1 of 57
Simple Ruby/Sinatra Github
webhook script
KYOSS July 2015
Jeff Squyres
Github: A popular Git-hosting service
www.github.com
Github hosts
your Git repos
Git
repo
Git
repo
Git
repo
Github hosts
your Organization’s Git repos
Git
repo
Git
repo
Git
repo
Yoyodyne
Organization
Github hosts
your Organization’s Git repos
Git
repo
Git
repo
Git
repo
Yoyodyne
Organization
Git
repo
Git
repo
Git
repo
Git
repo
Github has other services
Wiki
Github has other services
WikiAPI hooks
The Github Webhook
Hey!
Something just
happened!
The Github Webhook
Hey!
Something just
happened!
Github servers
The Github Webhook
Your serverGithub servers
HTTP post
{
"action": "opened",
"number": 1138,
"pull_request": {
"url": "https://api.github.com/repos/ofiwg/libfabric/pulls/1138",
"id": 39149978,
"html_url": "https://github.com/ofiwg/libfabric/pull/1138",
"diff_url": "https://github.com/ofiwg/libfabric/pull/1138.diff",
"patch_url": "https://github.com/ofiwg/libfabric/pull/1138.patch",
"issue_url": "https://api.github.com/repos/ofiwg/libfabric/issues/1138",
"number": 1138,
"state": "open",
"locked": false,
"title": "replace usd_open with usd_open_for_attrs ",
…
}
Hey!
Something just
happened!
This is what
happened
What can you do with Github
webhooks?
A common Github webhook use
Your serverGithub servers
A pull request
was just opened
Kick off a build
of the pull request
and test the result
Send results
back to Github
Example: Github kicked off tests
Example: all tests passed
Let’s look at another case
The Libfabric project
• Next generation high
performance
networking user stack
• Multi-vendor /
organization
• Open source
• Hosted on Github
Libfabric commits
Require a “Signed-off-by” line in Git commit messages
commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417
Author: Jeff Squyres <jsquyres@cisco.com>
Date: Thu Jul 2 15:03:42 2015 -0700
libfabric.so: bump the Libtool .so version to 2:0:1
Per https://www.gnu.org/software/libtool/manual/libtool.html. Fixes #1118.
Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
Libfabric commits
Require a “Signed-off-by” line in Git commit messages
commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417
Author: Jeff Squyres <jsquyres@cisco.com>
Date: Thu Jul 2 15:03:42 2015 -0700
libfabric.so: bump the Libtool .so version to 2:0:1
Per https://www.gnu.org/software/libtool/manual/libtool.html. Fixes #1118.
Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
commit efd7a5c878f53ba12ed771fa006d57b7f9d264fd
Author: Jithin Jose <jithin.jose@intel.com>
Date: Thu Jul 2 09:05:16 2015 -0700
sockets: fix resource leak in comm buffer
Signed-off-by: Jithin Jose <jithin.jose@intel.com>
Libfabric commits
Require a “Signed-off-by” line in Git commit messages
commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417
Author: Jeff Squyres <jsquyres@cisco.com>
Date: Thu Jul 2 15:03:42 2015 -0700
libfabric.so: bump the Libtool .so version to 2:0:1
Per https://www.gnu.org/software/libtool/manual/libtool.html. Fixes #1118.
Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
commit efd7a5c878f53ba12ed771fa006d57b7f9d264fd
Author: Jithin Jose <jithin.jose@intel.com>
Date: Thu Jul 2 09:05:16 2015 -0700
sockets: fix resource leak in comm buffer
Signed-off-by: Jithin Jose <jithin.jose@intel.com>
commit 621dd04cbe2c9e066602393d508c85d175bebbb9
Author: James Swaro <jswaro@cray.com>
Date: Mon Jun 29 12:28:32 2015 -0500
Initialize param_list to avoid crashing in library destructor
Libfabric commits
Require a “Signed-off-by” line in Git commit messages
commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417
Author: Jeff Squyres <jsquyres@cisco.com>
Date: Thu Jul 2 15:03:42 2015 -0700
libfabric.so: bump the Libtool .so version to 2:0:1
Per https://www.gnu.org/software/libtool/manual/libtool.html. Fixes #1118.
Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
commit efd7a5c878f53ba12ed771fa006d57b7f9d264fd
Author: Jithin Jose <jithin.jose@intel.com>
Date: Thu Jul 2 09:05:16 2015 -0700
sockets: fix resource leak in comm buffer
Signed-off-by: Jithin Jose <jithin.jose@intel.com>
commit 621dd04cbe2c9e066602393d508c85d175bebbb9
Author: James Swaro <jswaro@cray.com>
Date: Mon Jun 29 12:28:32 2015 -0500
Initialize param_list to avoid crashing in library destructor
commit 621dd04cbe2c9e066602393d508c85d175bebbb9
Author: James Swaro <jswaro@cray.com>
Date: Mon Jun 29 12:28:32 2015 -0500
Initialize param_list to avoid crashing in library destructor
Missing Signed-off-by line!
Libfabric only accepts commits
via pull requests
Libfabric Github
Git repo
Libfabric only accepts commits
via pull requests
Libfabric Github
Git repo
jsquyres Github
forked libfabric repo
Step 1: Jeff makes a Gihub “fork”
of the upstream Libfabric repo
Libfabric only accepts commits
via pull requests
Libfabric Github
Git repo
jsquyres Github
forked libfabric repo commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417
Author: Jeff Squyres <jsquyres@cisco.com>
Date: Thu Jul 2 15:03:42 2015 -0700
libfabric.so: bump the Libtool .so version to 2:0:1
Per https://www.gnu.org/software/libtool/manual/...
Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
Step 2: Jeff makes a commit on his
libfabric fork
Libfabric only accepts commits
via pull requests
Libfabric Github
Git repo
jsquyres Github
forked libfabric repo commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417
Author: Jeff Squyres <jsquyres@cisco.com>
Date: Thu Jul 2 15:03:42 2015 -0700
libfabric.so: bump the Libtool .so version to 2:0:1
Per https://www.gnu.org/software/libtool/manual/...
Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
Step 3: Jeff files a pull request to ask
if his commit can be accepted into
the main Libfabric repo
Libfabric only accepts commits
via pull requests
Libfabric Github
Git repo
jsquyres Github
forked libfabric repo commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417
Author: Jeff Squyres <jsquyres@cisco.com>
Date: Thu Jul 2 15:03:42 2015 -0700
libfabric.so: bump the Libtool .so version to 2:0:1
Per https://www.gnu.org/software/libtool/manual/...
Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
Step 4: A libfabric maintainer accepts
Jeff’s pull request
commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417
Author: Jeff Squyres <jsquyres@cisco.com>
Date: Thu Jul 2 15:03:42 2015 -0700
libfabric.so: bump the Libtool .so version to 2:0:1
Per https://www.gnu.org/software/libtool/manual/...
Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
commit d70ebb7b6f7afb51e3026c92c40b
Author: Jeff Squyres <jsquyres@cisc
Date: Thu Jul 2 15:03:42 2015 -07
libfabric.so: bump the Libtool
Per https://www.gnu.org/softwar
Signed-off-by: Jeff Squyres <js
Wait – you missed a step
The missing step
1. Jeff makes a Gihub “fork” of the upstream
Libfabric repo
2. Jeff makes a commit on his libfabric fork
3. Jeff files a pull request to ask if his commit
can be accepted into the main Libfabric repo
4. Libfabric maintainers review the pull request
commit(s)
5. A libfabric maintainer accepts Jeff’s pull
request
The missing step
1. Jeff makes a Gihub “fork” of the upstream
Libfabric repo
2. Jeff makes a commit on his libfabric fork
3. Jeff files a pull request to ask if his commit
can be accepted into the main Libfabric repo
4. Libfabric maintainers review the pull request
commit(s)
5. A libfabric maintainer accepts Jeff’s pull
request
The missing step
1. Jeff makes a Gihub “fork” of the upstream
Libfabric repo
2. Jeff makes a commit on his libfabric fork
3. Jeff files a pull request to ask if his commit
can be accepted into the main Libfabric repo
4. Libfabric maintainers review the pull request
commit(s)
5. A libfabric maintainer accepts Jeff’s pull
request
Is there a Signed-off-by line?
The Signed-off-by line
It’s kind of a silly thing
It has nothing to do with the code itself
The Signed-off-by line
But the lawyers tell us we must have it
The Signed-off-by line
We developers don’t want to have to deal with it
We just want to make sure it happens, but at zero cost to us
The Signed-off-by line
Sounds like a perfect job
for automation
Example: PR with three commits
Example: PR with three commits
Example PR with Badness
Example PR with Badness
Example PR with Badness
Why is this one marked bad?
Example PR with Badness
Why is this one marked bad?
Github uses the status of the last commit as the status
of the overall pull request
That’s what it does
Now let’s look what it is
Sinatra
sinatrarb.com
Sinatra
sinatrarb.com
Sinatra: logistics
Sinatra processLocal browser
http://localhost:4567
Sinatra: logistics
Sinatra process
http://localhost:4567
nginx processRemote browser
http://example.com
Sinatra “Signed-off-by” Github webhook
Your serverGithub servers
A pull request
was just opened
(or modified)
Check to make sure
each commit has a
Signed-off-by line
Send results
back to Github
Github to Sinatra logistics
Github servers
Some web server
verify-
signed-off.rb
Send results
back to Github
“Signed-off-by” checker
Source code:
https://github.com/ofiwg/libfabric/blob/master/config/github-webhook/verify-signed-off.rb
github.com/ofiwg/libfabric
config subdir
github-webhook subdir
verify-signed-off.rb
Heavily inspired by
http://git-scm.com/book/en/v2/GitHub-Scripting-GitHub
Setup
require 'rubygems’ # Required by RHEL 6
require 'httparty’ # Used in the body below for HTTP requests
require 'sinatra’ # All the Sinatra glue
require 'json’ # Used in the body below for JSON stuff
# Put Sinatra on port 5000 (a fairly arbitrary choice)
set :port, 5000
# Globals
user_agent = 'ofiwg/signed-off-by-checker'
# Read the Github auth token in from the environment (it wouldn't do
# the hard-code it where it would show up in a public Github repo!)
auth_token = ENV['GITHUB_AUTH_TOKEN
if auth_token == nil then
puts "Someone forgot to set $GITHUB_AUTH_TOKEN before launching me. Aborting!n"
exit 1
end
Handle HTTP Get
# Github webhooks are not delivered as HTTP GETs. If we don't have
# this Sinatra method here, Sinatra displays a goofy error message if
# someone just visits "http[s]://url_to_this_script".
# Responds to an HTTP Get for “/”
get '/' do
# Output this plain string and exit
'Nothing to see here but us chickens'
end
Handle HTTP Post
# Respond to an HTTP Post to “/”
post '/' do
# Parse the JSON into the “push” variable
push = JSON.parse(request.body.read)
repo_name = push['repository']['full_name']
# If this is not a push on a pull request (i.e., if there's no
# commits to examine, such as if this is a test webhook ping from
# github), then just return HTTP status 200 (i.e., success) with a
# handy message that you can see in the Github webhook debug logs.
if push['action'] == nil || (push['action'] != 'synchronize' &&
push['action'] != 'opened') then
# Returns an HTTP 200 status and a plain string
return [200, ‘Nothing for this bot to do!']
end
…continues…
Get all commits on this pull request
# Get _all_ commits associated with this pull request
commits_url = push['pull_request']['commits_url']
commits = HTTParty.get(commits_url,
:headers => {
'Content-Type' => 'application/json',
'User-Agent' => user_agent,
'Authorization' => "token #{auth_token}" }
)
# Setup some variables
happy = true
targetURL = 'https://github.com/ofiwg/libfabric/wiki#how-to-contribute'
debug_message = "checking debug URL: #{commits_url}nn"
final_message = ''
…continues…
Start analyzing the commit messages
# Loop over all the commit meta data we just downloaded
commits.each_with_index do |commit, index|
sha = commit['sha']
status_url = “https://api.github.com/repos/#{repo_name}/statuses/#{sha}”
status = { 'context' => 'Signed-off-by checker’ }
# Look for a Signed-off-by string in this commit
if /Signed-off-by/.match commit['commit']['message']
status['state'] = 'success'
status['description'] = 'This commit is signed off'
else
status['state'] = 'failure'
status['description'] = 'This commit is not signed off'
status['target_url'] = targetURL
happy = false
end
final_message = status['description']
…continues…
Is this the last commit?
if index == (commits.length - 1) && index > 0 then
if happy then
status['state'] = 'success'
status['description'] = 'All commits were signed off. Yay!'
else
status['state'] = 'failure'
status['description'] = 'At least one commit was not signed off'
status['target_url’] = targetURL
end
final_message = status['description']
end
…continues…
Send back the results for this commit
HTTParty.post(status_url,
:body => status.to_json,
:headers => {
'Content-Type' => 'application/json',
'User-Agent' => user_agent,
'Authorization' => "token #{auth_token}" }
)
end
…continues…
All done!
# Return HTTP status 200 and a message that shows up in the
# Github webhook debug logs
return [200, ”Thanks for playing -- #{final_message}"]
end
Example / reminder of output
Yay!

More Related Content

What's hot

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 

What's hot (20)

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
MPI Sessions: a proposal to the MPI Forum
MPI Sessions: a proposal to the MPI ForumMPI Sessions: a proposal to the MPI Forum
MPI Sessions: a proposal to the MPI Forum
 
Dependency management in golang
Dependency management in golangDependency management in golang
Dependency management in golang
 
Create a PHP Library the right way
Create a PHP Library the right wayCreate a PHP Library the right way
Create a PHP Library the right way
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
Evolution of Version Control In Open Source
Evolution of Version Control In Open SourceEvolution of Version Control In Open Source
Evolution of Version Control In Open Source
 
new ifnet(9) KPI for FreeBSD network stack
new ifnet(9) KPI for FreeBSD network stacknew ifnet(9) KPI for FreeBSD network stack
new ifnet(9) KPI for FreeBSD network stack
 
Inroduction to golang
Inroduction to golangInroduction to golang
Inroduction to golang
 
OpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-SideOpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-Side
 
GitLab as an Alternative Development Platform for Github.com
GitLab as an Alternative Development Platform for Github.comGitLab as an Alternative Development Platform for Github.com
GitLab as an Alternative Development Platform for Github.com
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPC
 
lwref: insane idea on reference counting
lwref: insane idea on reference countinglwref: insane idea on reference counting
lwref: insane idea on reference counting
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
 
Docker & PHP - Practical use case
Docker & PHP - Practical use caseDocker & PHP - Practical use case
Docker & PHP - Practical use case
 
Understanding and Using Git at Eclipse
Understanding and Using Git at EclipseUnderstanding and Using Git at Eclipse
Understanding and Using Git at Eclipse
 
Frontend Performance: Expert to Crazy Person
Frontend Performance: Expert to Crazy PersonFrontend Performance: Expert to Crazy Person
Frontend Performance: Expert to Crazy Person
 
Python for IoT, A return of experience
Python for IoT, A return of experiencePython for IoT, A return of experience
Python for IoT, A return of experience
 
Creating an api from design to security.
Creating an api from design to security.Creating an api from design to security.
Creating an api from design to security.
 
Frontend Performance: De débutant à Expert à Fou Furieux
Frontend Performance: De débutant à Expert à Fou FurieuxFrontend Performance: De débutant à Expert à Fou Furieux
Frontend Performance: De débutant à Expert à Fou Furieux
 
Wonders of Golang
Wonders of GolangWonders of Golang
Wonders of Golang
 

Similar to Fun with Github webhooks: verifying Signed-off-by

Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
Victor Wong
 

Similar to Fun with Github webhooks: verifying Signed-off-by (20)

Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for Artists
 
Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015
 
Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010
 
.Git for WordPress Developers
.Git for WordPress Developers.Git for WordPress Developers
.Git for WordPress Developers
 
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a BossGit Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
 
Git for Beginners
Git for BeginnersGit for Beginners
Git for Beginners
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Git
GitGit
Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Github
GithubGithub
Github
 
DWX 2022 - DevSecOps mit GitHub
DWX 2022 - DevSecOps mit GitHubDWX 2022 - DevSecOps mit GitHub
DWX 2022 - DevSecOps mit GitHub
 
Lagos GitHub Meetup - What is Git?
Lagos GitHub Meetup - What is Git?Lagos GitHub Meetup - What is Git?
Lagos GitHub Meetup - What is Git?
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
 
Git for a newbie
Git for a newbieGit for a newbie
Git for a newbie
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
SydJS.com
SydJS.comSydJS.com
SydJS.com
 
Git 201
Git 201Git 201
Git 201
 
GIT By Sivakrishna
GIT By SivakrishnaGIT By Sivakrishna
GIT By Sivakrishna
 
Migrating from Subversion to Git and GitHub
Migrating from Subversion to Git and GitHubMigrating from Subversion to Git and GitHub
Migrating from Subversion to Git and GitHub
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 

More from Jeff Squyres

Cisco EuroMPI'13 vendor session presentation
Cisco EuroMPI'13 vendor session presentationCisco EuroMPI'13 vendor session presentation
Cisco EuroMPI'13 vendor session presentation
Jeff Squyres
 

More from Jeff Squyres (14)

MPI Fourm SC'15 BOF
MPI Fourm SC'15 BOFMPI Fourm SC'15 BOF
MPI Fourm SC'15 BOF
 
2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback
 
(Open) MPI, Parallel Computing, Life, the Universe, and Everything
(Open) MPI, Parallel Computing, Life, the Universe, and Everything(Open) MPI, Parallel Computing, Life, the Universe, and Everything
(Open) MPI, Parallel Computing, Life, the Universe, and Everything
 
Cisco usNIC: how it works, how it is used in Open MPI
Cisco usNIC: how it works, how it is used in Open MPICisco usNIC: how it works, how it is used in Open MPI
Cisco usNIC: how it works, how it is used in Open MPI
 
Cisco EuroMPI'13 vendor session presentation
Cisco EuroMPI'13 vendor session presentationCisco EuroMPI'13 vendor session presentation
Cisco EuroMPI'13 vendor session presentation
 
Open MPI Explorations in Process Affinity (EuroMPI'13 presentation)
Open MPI Explorations in Process Affinity (EuroMPI'13 presentation)Open MPI Explorations in Process Affinity (EuroMPI'13 presentation)
Open MPI Explorations in Process Affinity (EuroMPI'13 presentation)
 
MPI History
MPI HistoryMPI History
MPI History
 
MOSSCon 2013, Cisco Open Source talk
MOSSCon 2013, Cisco Open Source talkMOSSCon 2013, Cisco Open Source talk
MOSSCon 2013, Cisco Open Source talk
 
Ethernet and TCP optimizations
Ethernet and TCP optimizationsEthernet and TCP optimizations
Ethernet and TCP optimizations
 
Friends don't let friends leak MPI_Requests
Friends don't let friends leak MPI_RequestsFriends don't let friends leak MPI_Requests
Friends don't let friends leak MPI_Requests
 
MPI-3 Timer requests proposal
MPI-3 Timer requests proposalMPI-3 Timer requests proposal
MPI-3 Timer requests proposal
 
MPI_Mprobe is good for you
MPI_Mprobe is good for youMPI_Mprobe is good for you
MPI_Mprobe is good for you
 
The Message Passing Interface (MPI) in Layman's Terms
The Message Passing Interface (MPI) in Layman's TermsThe Message Passing Interface (MPI) in Layman's Terms
The Message Passing Interface (MPI) in Layman's Terms
 
What is [Open] MPI?
What is [Open] MPI?What is [Open] MPI?
What is [Open] MPI?
 

Recently uploaded

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Recently uploaded (20)

IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
 

Fun with Github webhooks: verifying Signed-off-by

  • 1. Simple Ruby/Sinatra Github webhook script KYOSS July 2015 Jeff Squyres
  • 2. Github: A popular Git-hosting service www.github.com
  • 3. Github hosts your Git repos Git repo Git repo Git repo
  • 4. Github hosts your Organization’s Git repos Git repo Git repo Git repo Yoyodyne Organization
  • 5. Github hosts your Organization’s Git repos Git repo Git repo Git repo Yoyodyne Organization Git repo Git repo Git repo Git repo
  • 6. Github has other services Wiki
  • 7. Github has other services WikiAPI hooks
  • 9. The Github Webhook Hey! Something just happened! Github servers
  • 10. The Github Webhook Your serverGithub servers HTTP post { "action": "opened", "number": 1138, "pull_request": { "url": "https://api.github.com/repos/ofiwg/libfabric/pulls/1138", "id": 39149978, "html_url": "https://github.com/ofiwg/libfabric/pull/1138", "diff_url": "https://github.com/ofiwg/libfabric/pull/1138.diff", "patch_url": "https://github.com/ofiwg/libfabric/pull/1138.patch", "issue_url": "https://api.github.com/repos/ofiwg/libfabric/issues/1138", "number": 1138, "state": "open", "locked": false, "title": "replace usd_open with usd_open_for_attrs ", … } Hey! Something just happened! This is what happened
  • 11. What can you do with Github webhooks?
  • 12. A common Github webhook use Your serverGithub servers A pull request was just opened Kick off a build of the pull request and test the result Send results back to Github
  • 15. Let’s look at another case
  • 16. The Libfabric project • Next generation high performance networking user stack • Multi-vendor / organization • Open source • Hosted on Github
  • 17. Libfabric commits Require a “Signed-off-by” line in Git commit messages commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417 Author: Jeff Squyres <jsquyres@cisco.com> Date: Thu Jul 2 15:03:42 2015 -0700 libfabric.so: bump the Libtool .so version to 2:0:1 Per https://www.gnu.org/software/libtool/manual/libtool.html. Fixes #1118. Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
  • 18. Libfabric commits Require a “Signed-off-by” line in Git commit messages commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417 Author: Jeff Squyres <jsquyres@cisco.com> Date: Thu Jul 2 15:03:42 2015 -0700 libfabric.so: bump the Libtool .so version to 2:0:1 Per https://www.gnu.org/software/libtool/manual/libtool.html. Fixes #1118. Signed-off-by: Jeff Squyres <jsquyres@cisco.com> commit efd7a5c878f53ba12ed771fa006d57b7f9d264fd Author: Jithin Jose <jithin.jose@intel.com> Date: Thu Jul 2 09:05:16 2015 -0700 sockets: fix resource leak in comm buffer Signed-off-by: Jithin Jose <jithin.jose@intel.com>
  • 19. Libfabric commits Require a “Signed-off-by” line in Git commit messages commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417 Author: Jeff Squyres <jsquyres@cisco.com> Date: Thu Jul 2 15:03:42 2015 -0700 libfabric.so: bump the Libtool .so version to 2:0:1 Per https://www.gnu.org/software/libtool/manual/libtool.html. Fixes #1118. Signed-off-by: Jeff Squyres <jsquyres@cisco.com> commit efd7a5c878f53ba12ed771fa006d57b7f9d264fd Author: Jithin Jose <jithin.jose@intel.com> Date: Thu Jul 2 09:05:16 2015 -0700 sockets: fix resource leak in comm buffer Signed-off-by: Jithin Jose <jithin.jose@intel.com> commit 621dd04cbe2c9e066602393d508c85d175bebbb9 Author: James Swaro <jswaro@cray.com> Date: Mon Jun 29 12:28:32 2015 -0500 Initialize param_list to avoid crashing in library destructor
  • 20. Libfabric commits Require a “Signed-off-by” line in Git commit messages commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417 Author: Jeff Squyres <jsquyres@cisco.com> Date: Thu Jul 2 15:03:42 2015 -0700 libfabric.so: bump the Libtool .so version to 2:0:1 Per https://www.gnu.org/software/libtool/manual/libtool.html. Fixes #1118. Signed-off-by: Jeff Squyres <jsquyres@cisco.com> commit efd7a5c878f53ba12ed771fa006d57b7f9d264fd Author: Jithin Jose <jithin.jose@intel.com> Date: Thu Jul 2 09:05:16 2015 -0700 sockets: fix resource leak in comm buffer Signed-off-by: Jithin Jose <jithin.jose@intel.com> commit 621dd04cbe2c9e066602393d508c85d175bebbb9 Author: James Swaro <jswaro@cray.com> Date: Mon Jun 29 12:28:32 2015 -0500 Initialize param_list to avoid crashing in library destructor commit 621dd04cbe2c9e066602393d508c85d175bebbb9 Author: James Swaro <jswaro@cray.com> Date: Mon Jun 29 12:28:32 2015 -0500 Initialize param_list to avoid crashing in library destructor Missing Signed-off-by line!
  • 21. Libfabric only accepts commits via pull requests Libfabric Github Git repo
  • 22. Libfabric only accepts commits via pull requests Libfabric Github Git repo jsquyres Github forked libfabric repo Step 1: Jeff makes a Gihub “fork” of the upstream Libfabric repo
  • 23. Libfabric only accepts commits via pull requests Libfabric Github Git repo jsquyres Github forked libfabric repo commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417 Author: Jeff Squyres <jsquyres@cisco.com> Date: Thu Jul 2 15:03:42 2015 -0700 libfabric.so: bump the Libtool .so version to 2:0:1 Per https://www.gnu.org/software/libtool/manual/... Signed-off-by: Jeff Squyres <jsquyres@cisco.com> Step 2: Jeff makes a commit on his libfabric fork
  • 24. Libfabric only accepts commits via pull requests Libfabric Github Git repo jsquyres Github forked libfabric repo commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417 Author: Jeff Squyres <jsquyres@cisco.com> Date: Thu Jul 2 15:03:42 2015 -0700 libfabric.so: bump the Libtool .so version to 2:0:1 Per https://www.gnu.org/software/libtool/manual/... Signed-off-by: Jeff Squyres <jsquyres@cisco.com> Step 3: Jeff files a pull request to ask if his commit can be accepted into the main Libfabric repo
  • 25. Libfabric only accepts commits via pull requests Libfabric Github Git repo jsquyres Github forked libfabric repo commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417 Author: Jeff Squyres <jsquyres@cisco.com> Date: Thu Jul 2 15:03:42 2015 -0700 libfabric.so: bump the Libtool .so version to 2:0:1 Per https://www.gnu.org/software/libtool/manual/... Signed-off-by: Jeff Squyres <jsquyres@cisco.com> Step 4: A libfabric maintainer accepts Jeff’s pull request commit d70ebb7b6f7afb51e3026c92c40b6aedae8b1417 Author: Jeff Squyres <jsquyres@cisco.com> Date: Thu Jul 2 15:03:42 2015 -0700 libfabric.so: bump the Libtool .so version to 2:0:1 Per https://www.gnu.org/software/libtool/manual/... Signed-off-by: Jeff Squyres <jsquyres@cisco.com> commit d70ebb7b6f7afb51e3026c92c40b Author: Jeff Squyres <jsquyres@cisc Date: Thu Jul 2 15:03:42 2015 -07 libfabric.so: bump the Libtool Per https://www.gnu.org/softwar Signed-off-by: Jeff Squyres <js
  • 26. Wait – you missed a step
  • 27. The missing step 1. Jeff makes a Gihub “fork” of the upstream Libfabric repo 2. Jeff makes a commit on his libfabric fork 3. Jeff files a pull request to ask if his commit can be accepted into the main Libfabric repo 4. Libfabric maintainers review the pull request commit(s) 5. A libfabric maintainer accepts Jeff’s pull request
  • 28. The missing step 1. Jeff makes a Gihub “fork” of the upstream Libfabric repo 2. Jeff makes a commit on his libfabric fork 3. Jeff files a pull request to ask if his commit can be accepted into the main Libfabric repo 4. Libfabric maintainers review the pull request commit(s) 5. A libfabric maintainer accepts Jeff’s pull request
  • 29. The missing step 1. Jeff makes a Gihub “fork” of the upstream Libfabric repo 2. Jeff makes a commit on his libfabric fork 3. Jeff files a pull request to ask if his commit can be accepted into the main Libfabric repo 4. Libfabric maintainers review the pull request commit(s) 5. A libfabric maintainer accepts Jeff’s pull request Is there a Signed-off-by line?
  • 30. The Signed-off-by line It’s kind of a silly thing It has nothing to do with the code itself
  • 31. The Signed-off-by line But the lawyers tell us we must have it
  • 32. The Signed-off-by line We developers don’t want to have to deal with it We just want to make sure it happens, but at zero cost to us
  • 33. The Signed-off-by line Sounds like a perfect job for automation
  • 34. Example: PR with three commits
  • 35. Example: PR with three commits
  • 36. Example PR with Badness
  • 37. Example PR with Badness
  • 38. Example PR with Badness Why is this one marked bad?
  • 39. Example PR with Badness Why is this one marked bad? Github uses the status of the last commit as the status of the overall pull request
  • 40. That’s what it does Now let’s look what it is
  • 43. Sinatra: logistics Sinatra processLocal browser http://localhost:4567
  • 44. Sinatra: logistics Sinatra process http://localhost:4567 nginx processRemote browser http://example.com
  • 45. Sinatra “Signed-off-by” Github webhook Your serverGithub servers A pull request was just opened (or modified) Check to make sure each commit has a Signed-off-by line Send results back to Github
  • 46. Github to Sinatra logistics Github servers Some web server verify- signed-off.rb Send results back to Github
  • 47. “Signed-off-by” checker Source code: https://github.com/ofiwg/libfabric/blob/master/config/github-webhook/verify-signed-off.rb github.com/ofiwg/libfabric config subdir github-webhook subdir verify-signed-off.rb Heavily inspired by http://git-scm.com/book/en/v2/GitHub-Scripting-GitHub
  • 48. Setup require 'rubygems’ # Required by RHEL 6 require 'httparty’ # Used in the body below for HTTP requests require 'sinatra’ # All the Sinatra glue require 'json’ # Used in the body below for JSON stuff # Put Sinatra on port 5000 (a fairly arbitrary choice) set :port, 5000 # Globals user_agent = 'ofiwg/signed-off-by-checker' # Read the Github auth token in from the environment (it wouldn't do # the hard-code it where it would show up in a public Github repo!) auth_token = ENV['GITHUB_AUTH_TOKEN if auth_token == nil then puts "Someone forgot to set $GITHUB_AUTH_TOKEN before launching me. Aborting!n" exit 1 end
  • 49. Handle HTTP Get # Github webhooks are not delivered as HTTP GETs. If we don't have # this Sinatra method here, Sinatra displays a goofy error message if # someone just visits "http[s]://url_to_this_script". # Responds to an HTTP Get for “/” get '/' do # Output this plain string and exit 'Nothing to see here but us chickens' end
  • 50. Handle HTTP Post # Respond to an HTTP Post to “/” post '/' do # Parse the JSON into the “push” variable push = JSON.parse(request.body.read) repo_name = push['repository']['full_name'] # If this is not a push on a pull request (i.e., if there's no # commits to examine, such as if this is a test webhook ping from # github), then just return HTTP status 200 (i.e., success) with a # handy message that you can see in the Github webhook debug logs. if push['action'] == nil || (push['action'] != 'synchronize' && push['action'] != 'opened') then # Returns an HTTP 200 status and a plain string return [200, ‘Nothing for this bot to do!'] end …continues…
  • 51. Get all commits on this pull request # Get _all_ commits associated with this pull request commits_url = push['pull_request']['commits_url'] commits = HTTParty.get(commits_url, :headers => { 'Content-Type' => 'application/json', 'User-Agent' => user_agent, 'Authorization' => "token #{auth_token}" } ) # Setup some variables happy = true targetURL = 'https://github.com/ofiwg/libfabric/wiki#how-to-contribute' debug_message = "checking debug URL: #{commits_url}nn" final_message = '' …continues…
  • 52. Start analyzing the commit messages # Loop over all the commit meta data we just downloaded commits.each_with_index do |commit, index| sha = commit['sha'] status_url = “https://api.github.com/repos/#{repo_name}/statuses/#{sha}” status = { 'context' => 'Signed-off-by checker’ } # Look for a Signed-off-by string in this commit if /Signed-off-by/.match commit['commit']['message'] status['state'] = 'success' status['description'] = 'This commit is signed off' else status['state'] = 'failure' status['description'] = 'This commit is not signed off' status['target_url'] = targetURL happy = false end final_message = status['description'] …continues…
  • 53. Is this the last commit? if index == (commits.length - 1) && index > 0 then if happy then status['state'] = 'success' status['description'] = 'All commits were signed off. Yay!' else status['state'] = 'failure' status['description'] = 'At least one commit was not signed off' status['target_url’] = targetURL end final_message = status['description'] end …continues…
  • 54. Send back the results for this commit HTTParty.post(status_url, :body => status.to_json, :headers => { 'Content-Type' => 'application/json', 'User-Agent' => user_agent, 'Authorization' => "token #{auth_token}" } ) end …continues…
  • 55. All done! # Return HTTP status 200 and a message that shows up in the # Github webhook debug logs return [200, ”Thanks for playing -- #{final_message}"] end
  • 56. Example / reminder of output
  • 57. Yay!