DEV Community

Blake Morgan
Blake Morgan

Posted on

GitHub as Code

The Problem

I work on a team when new GitHub repositories need to be created daily. In a perfect world, our repos have the following characteristics:

  • Two branches: master and dev
  • Part of our GitHub organization
  • A repo topic of our team name
  • Another repo topic specifying a frontend or backend project.
  • Our GitHub team set as an admin repo
  • Pushes to master require review
  • Administrators are required to abide by branch rules

Unfortunately, GitHub has no convenient way to specify all of those options at one time. It's also just (relatively) takes a lot of time and when you're in the zone developing, you don't want to spend that time setting up a GitHub repository. So what ends up happening is that a repository is created without the characteristics we want and in turn, technical debt is created because eventually, we have to go back and add those settings in. It's just a pain

The Solution

As I was thinking about how to solve this issue, the thought that came to me was "infrastructure as code." I know that there are tools like CloudFormation, Handel, and Terraform, so I thought "why couldn't there be something like this for GitHub?" That is where the idea for GitHub as Code came from.

GitHub as Code (GHaC) works just like you'd expect any infrastructure as code. You create a YAML file defining the GitHub repo, the use the GHaC command line tool to build the repository. Here is an example of a GHaC YAML file:

name: Test Repo
private: true
topics:
  - ghac
auto_security_fixes: true

This would be a simple GHaC YAML file. You can install GHaC with npm i -g ghac and run ghac filename.yml. It would then follow the instructions in the YAML file. In this case, it would create a private repo with the "ghac" topic and automatic security fixes enabled. You can see all of the options GHaC supports in the GHaC README. Ultimately, the goal is to support every feature supported by the GitHub v3 REST API. This tool also uses the preview GitHub API's in order to provide more customizability.

Conclusion

With this tool, you can more easily create GitHub repositories with all the settings your team needs. It will save you time and increase the uniformity of your team's GitHub repo settings.

Try GHaC out! You can download it from NPM.

Top comments (2)

Collapse
 
ojacques profile image
Olivier Jacques

Cool project. I wrote a Python script which does something similar. I may move to yours and contribute. I will need to add support for GitHub enterprise and also look at issue / pr custom labels. Thanks for sharing!

Collapse
 
blakemorgan profile image
Blake Morgan

Thank you! Contributions would be greatly appreciated. It should already support GitHub enterprise, as that's what my team uses.