Auto Generating Release Notes Using REST Java API

Recently I was exploring a possibility to automate release note process. It’s quite a boring and annoying task to do for either, developers and QA’s (or even tech leads). I came up with two different approaches and I think that both of them might be used beneficially. However, this is no way a full application which completely replaces RELEASE notes, just my thought process and a few quick hacks in order to test stuff out.

Used technologies:

  • Apache Maven 3.3.3
  • Jira-rest-java-client-api 2.0.0-m25

Firstly, I was thinking about an actual generator. The idea was very simple, use REST Api to get a connection with the JIRA board, select the project, fix version and get a list of tickets. Because we are relying on fix version, the list will only contain those tickets which are relevant. Go through the list and get ticket number and description (need to use a good regex). Finally, format and export everything into .txt file.

This option has a few weaknesses, basically you always want your release notes to be official and brief, while most of the time Jira description looks rather differently, usually, it’s messy and long. However, you only need to change the way how your regex works, put your release note comment between # tags and only export what is between them. This way we can have good from both of the worlds; brief, long and messy descriptions and official release notes inside the hash tags. Auto generator easily picks up the regex and makes your life easier.

private static URI jiraServerUri = URI.create("https://jira.com");
public GetIssues(String string) throws Exception {

    final AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
    final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "username", "password");

    try {
        final int buildNumber = restClient.getMetadataClient().getServerInfo().claim().getBuildNumber();
        PrintWriter writer = new PrintWriter("pathtoyourreleasefile\RELEASENOTE.txt", "UTF-8");
        String pattern = "YOUR REGEX";
        Pattern r = Pattern.compile(pattern);

        // let's now print all issues matching a JQL string (here: all assigned issues)
        if (buildNumber >= ServerVersionConstants.BN_JIRA_4_3) {
            final SearchResult searchResult = restClient.getSearchClient().searchJql("project=MFXMOTIF AND fixVersion="+string+"").claim();
            int i = 0;

            writer.println("Version: "+string);
            writer.println("===========================\n");

            for (BasicIssue issue : searchResult.getIssues()) {

                String line = issue.toString();
                Matcher m = r.matcher(line);
                while(m.find()) {
                    writer.println(issue.getKey() + " : "+m.group());
                    System.out.println((issue.getKey() ));
                    i++;
                }
            }
            System.out.println(i);
            writer.close();
        }

    }
    finally {
        restClient.close();
     }
}

Release Note CI Checker

The other, more viable, option is to make a Release note checker, which gets the list from Release note file and compares it to the list which is on Jira. The output shows what are you including/excluding from the list.

I found that very beneficial and my team and manager liked the idea a lot!
Every time there was a commit it would trigger the Jenkins build which would trigger my script. This script would grab all of the current issues from Jira done column, get the key(Jira ID). Then it would download the current release note file of the current CI commit build and go through the file searching for those Jira keys that it found on the board. Finally, it would generate an HTML 5 report and upload it to the CI build. This way anyone could easily see what issues are missing or are included in the current build. So you would be always up to date. No more missed release notes!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s