Automated GitHub Organization Invites

with Ruby, Sinatra, Slim, Octokit and ngrok

Thai Pangsakulyanont
Code, Applied to Life
2 min readJan 15, 2015

--

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.
  • I’d have to tell them to check their email.
  • I’d have to wait for them to check their email and accept the invitation.

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;
  • Octokit is a GitHub API client library;
  • GitHub has an API for adding members to team by username;
  • Although not required, Slim makes writing HTML much easier, without those curly braces and closing tags; and finally,
  • ngrok lets you publish your local web server online.

…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:

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

Then I instructed the students to go to that URL…

…enter their GitHub username, and click the button…

…and they get an email instantly!

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

--

--

Thai Pangsakulyanont
Code, Applied to Life

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