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:
<?php require "vendor/autoload.php"; $logger = new \Monolog\Logger("log"); $logger->pushHandler(new \Monolog\Handler\ErrorLogHandler()); $logger->addInfo("Something happened");
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.
[color] branch = false diff = false interactive = false status = false
First you will need to edit the URL to put in your own
project values. Then intialise the request and add a couple of headers and the
CURLOPT_RETURNTRANSFER option to stop curl from echoing the output instead of returning it. Once we get the response, we
json_decode() it and then the data is available in an array - which is echoed out in a very hi-tech manner!
I can imagine using variations of this script in other automated processes, perhaps to notify the team of which issues were closed yesterday, or automating a changelog when a new tag is pushed to the deployment server. However you use it, I thought I'd share in case it's useful. If you have any additional tips or advice, leave me a comment and share in return :)