GitHub-Powered Changelog Scripts

Posted by Unknown on Tuesday, January 28, 2014

My current project does periodic releases, we build a few things, then we work on getting a bunch of user feedback and changing/fixing things before we actually release. This means we need to be organised with tags and branches. We're using GitHub for collaboration, including our issue trackers, commits which contribute to an issue have the issue number in the commit message, and when a branch merges in to the main line, we use the "fixes #42" notation to simultaneously close off the issue that it relates to.


This has been working pretty well, and today I got the question "what's new since I last saw this project?" - so I created a changelog. It's rather rough-and-ready but I had fun so I thought I'd share.


Git the Log


First I grabbed all the log messages that had the word "fixes" in them, just by running a command-line one-liner:




git log last-release...HEAD --oneline | grep fixes > log.txt

We use tags when we release so instead of last-release, I used a tag name, but you could equally use a revision number. I grabbed the output and threw it into a text file, then parsed it in more detail so that I could get the issue information from GitHub using their API. For this I used PHP, because it's great for talking to APIs.


Here's the script that I used to parse out the actual issue numbers I wanted:




$filename = "log.txt";
$entries = file($filename);

foreach($entries as $entry) {
$matches = array();
preg_match("/fixes #([0-9]+)/", $entry, $matches);

if(isset($matches[1])) {
$id = $matches[1];

This just takes the file and reads it into an array, then does a little regex on each array to grab issue numbers from the commit messages (it's probably easy to do this in the previous step, but my PHP is still better than my commandline-fu).


Get Details From Github


Once I have that issue ID, I can just grab the issue details from Github - in this case I simply went for the issue title and its URL, to provide a simple changelog to the team.


Before you begin, you will need an access token, get a GitHub "personal access token" from https://github.com/settings/applications. In my script, this is stored in $access_token. I'm using the PHP cURL extension in this example but you could easily use another library such as Guzzle which has a nicer interface.




$url = 'https://api.github.com/repos/organisation/project/issues/' . $id;
$ch = curl_init($url);
$headers = array(
"Authorization: token " . $access_token,
"User-Agent: php-curl");

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$issue_json = curl_exec

Truncated by Planet PHP, read more at the original (another 2056 bytes)




more

{ 0 comments... » GitHub-Powered Changelog Scripts read them below or add one }

Post a Comment

Popular Posts