Automated GitHub Organization Invites

with Ruby, Sinatra, Slim, Octokit and ngrok

I’m working as a TA for a university course (Software Specification and Design), and I’m creating a GitHub organization for students to submit assignments.

The problem is getting all students into this organization.

At first, I thought of using Google Spreadsheet to create a form and letting students fill in their GitHub username, but…

  • I’d have to take care of inviting each username into the organization.

That’s too much work for me, so I started thinking of a solution:

a website where the student fills in their GitHub username,
clicks a button, and an invite is sent.


We are going to write it in Ruby, as tools (gems) to accomplish this are readily available:

  • Sinatra is a very simple DSL for quickly creating web applications;

…and all we need to do is to put them together.


So, first, I ran bundle init and add some gems to the Gemfile:

Then I wrote a Ruby script to display a home page and a POST request handler to add the user to GitHub repository:

Here’s views/index.slim that displays a form that POSTs to /add:


After the server’s done, let’s run it:

ruby app.rb== Sinatra/1.4.5 has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop

…and also run ngrok to create a publicly-accessible tunnel:

ngrok 4567Tunnel Status        online
Version 1.7/1.7
Forwarding http://2fc3c02e.ngrok.com -> 127.0.0.1:4567
Forwarding https://2fc3c02e.ngrok.com -> 127.0.0.1:4567
Web Interface 127.0.0.1:4040
# Conn 0
Avg Conn Time 0.00ms

Then I instructed the students to go to that URL…

Image for post
Image for post

…enter their GitHub username, and click the button…

Image for post
Image for post

…and they get an email instantly!

Image for post
Image for post

…and within minutes, most students are inside the organization.

Code, Applied to Life

Stories about how coding can be applied to solve everyday…

Thai Pangsakulyanont

Written by

(@dtinth) A software engineer and frontend enthusiast. A Christian. A JavaScript musician. A Ruby and Vim lover.

Code, Applied to Life

Stories about how coding can be applied to solve everyday life problems. (Formerly Ruby Everyday).

Thai Pangsakulyanont

Written by

(@dtinth) A software engineer and frontend enthusiast. A Christian. A JavaScript musician. A Ruby and Vim lover.

Code, Applied to Life

Stories about how coding can be applied to solve everyday life problems. (Formerly Ruby Everyday).

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store