GitHub Network Graph
This script mimics the "Network Graph" display on GitHub.com in that it fetches the number of forks of a given repo and displays the distance (commits ahead or behind) it is from the upstream repository (the repository it is forked from).
The script is intended to be simple and as modular as possible without using outside dependencies. It is of course mostly a thought experiment as doing this kind of thing in bash is a bit insane.
There a few main components:
- Two functions called
get_fork_branchtake in a single argument (the index of a forked repo from the list generated by a later command) and returns the user and default branch of that fork, respectively
- The main function, called
fork_statustakes no arguments and iterates through the returned list of forks, getting the number of commits ahead or behind it is from master. It uses
get_fork_branchto set variables appropriately for each run of the loop
The script also includes some basic dependency checking, including
jq to process
JSON payloads returned by the GitHub API. It would be absolutely rediculous to rewrite a
JSON parser in Bash.
The current version does not conform to design guidelines and is a bit "messy". If this were not an excercise it would need clean up, but this demonstrates the intended purpose.
To use the script simple call it with the user/repo as the first and second parameters.
For exmaple, if you wanted to run it on
fork_map User:mesosphere Repo:mesos
- Compare non default branches
- Visual output
- Validate input
- Print usage upon invalidated input
- World peace