GithHub app and bot account


#2

Hey Jacek, I’m doing some research on using GitHub in a learning environment myself, not for a school but for voluntary workshops, but I think there is lots of common ground.

Just to be sure: have you seen https://classroom.github.com/? I’m new to it all myself, I’d love to hear why GitHub Classroom didn’t work out for you if you had a chance to consider it yet?

Regarding GitHub Apps, I’ve built a few using Node.js. I made an introductory tutorial at https://github.com/gr2m/github-app-example. A great framework to build GitHub apps with Node.js is Probot.

With Probot, you have a Node server running somewhere which is authenticated against GitHub using a PGP key. Given that you have set the right scope permission for your GitHub app, it can create new repositories, create new teams, etc. All APIs that you see here are available: http://octokit.github.io/node-github/

Right now I want to automate this process (points 1 and 2). To do so I wanted to use GitHub App (to manage students in organisation, assign them to groups) and Bot account (to push content to student repositories).

If I understand it correctly, you want to create one repository in the students repository per class, and then fork this repository once per team? Ideally you want to make the workflow work without needing

  1. a custom user interface
  2. a custom data store

For example what you could do is to have teachers create an issue in the core exercise repository with a title like “Create exercise for class 2017-b”. In the issue body, you could make lists for the different teams, like so

- Team A
  - @student1
  - @student2
  - @student3
- Team B
  - @student4
  - @student5
  - @student6

Where @student1 is the github login of the first issue, etc

A GitHub app can be notified about issues in the core repositories using webhooks. Then the Node app can check if the issue title begins with “Create excercise for”. If it does, it parses the issue description, creates repository for class in the “students” organisation, forks the new repository once per team, adds students to the respective team forks.

The GitHub app could respond to the issue if something went wrong, e.g. if one of the listed student logins does not exist, or if one student from the “@class-2017-b” team has not been listed. That way you have a place the GitHub app can respond to you without creating a custom web application for it, it can run entirely in the background, doing nothing but automising your workflows.

I think that way you can even automate steps 1.-3.? Or am I missing something?


#4

You can authenticate as the app instead: https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-a-github-app Probot does that automatically for you. In the event handlers, a context argument is passed as argument. On that argument you can get context.github, which is a GitHub API instance pre-authenticated as the current App.

If you have a use case where you need to authenticate as installation instead, you can run const github = robot.asInstallation(id) which gives you the GitHub API instance pre-authenticated as the installation