This is a POC to demonstrate how to build a GitHub App, running on Ruby on Rails, for understanding relationships between GitHub repos' usage and their assigned business units.
This application is built with Ruby on Rails. The intention is to containerize the application, but for now, please see the below points for operating the app locally.
-
Ruby: You will need Ruby installed on your machine. The required Ruby version is specified in the
.ruby-versionfile. If you don't have Ruby installed, you can follow the instructions on the official website. -
Bundler: Bundler is a Ruby gem that manages project-specific dependencies. Install it by running
gem install bundler. -
Rails: This application requires the Rails gem. Install it by running
gem install rails. -
Database: This application uses a Postgres database, and Postgres must be running in the background to use this app. The database configuration is specified in the
config/database.ymlfile.
-
Clone the repository: Run
git clone <REPO_URL>to clone the repository to your local machine. -
Install dependencies: Navigate to the project directory and run
bundle installto install the project dependencies. -
Database setup: Run the below to create the database and run the necessarymigrations:
rails db:create rails db:migrate
-
Install the front-end assets: You must have
[node](https://nodejs.org/en)and[yarn](https://yarnpkg.com/)installed on your machine to install the front-end assets.- The front-end styling is managed via the
css-bundlinggem, which should have been installed via thebundle installcommand in step 2 above. See here for more information on this gem's required use ofnodeandyarn. - Assuming you have
nodeandyarninstalled, runrails css:install:bootstrapfrom the app's working directory. - This command configures the app's asset pipeline to use the Bootstrap CSS styling system. It also adds relevant files to the
.gitignorefile.
- The front-end styling is managed via the
-
Start the server: Run
rails serverto start the Rails server.
Now you can visit http://localhost:3000 to view the application in your web browser.
To run the test suite, execute rails test in the project directory.
At its core, this app is a simple webhook that listens for Repository events and then uses the GitHub API to determine which business unit owns the repo that was pushed to.
- App listens for webhook events defined on the GitHub App.
- When a
RepositoryorPushevent is received, the app uses the GitHub API to fetch any custom property values associate with the repo. - The app then uses the custom property values to determine which business unit owns the repo. Business units are defined by any custom property with a
bu_prefix. - Users can upload a CSV report that's already generated by GitHub.com. The report is then parsed and the costs are associated with the business unit that owns the repo.
- If multiple business units are attached to the repo, defined by a custom repo property with the
bu_prefix, then any future repo costs will be split as-equally-as-possible between the business units.