@@ -0,0 +1,2419 @@
+%22%22%22Create a changelog file from all the merged pull requests%0A%0ALooking into the latest milestone, all the pull requests for neuropoly/spinalcordtoolbox%0Aare grouped by label and saved in %60changlog.md%60 in markdown format.%0A%0A%22%22%22%0A%0Aimport logging%0Aimport requests%0Aimport sys%0A%0AapiURL = 'https://api.github.com/repos/neuropoly/spinalcordtoolbox/'%0A%0A%0Adef latestMilestone():%0A    %22%22%22Get from Github the details of the latest milestone%0A    %22%22%22%0A    milestoneURL = apiURL + 'milestones'%0A    response = requests.get(milestoneURL)%0A    data = response.json()%0A    logging.info('Open milestones found %25d', len(data))%0A    logging.info('Latest milestone %25s %25d', data%5B0%5D%5B'title'%5D, data%5B0%5D%5B'number'%5D)%0A    return data%5B0%5D%0A%0A%0Adef detailedChangeLog():%0A    %22%22%22Return the Github URL comparing the last two tags.%0A    %22%22%22%0A    tagsURL = apiURL + 'tags'%0A    response = requests.get(tagsURL)%0A    latest, previous = response.json()%5B:2%5D%0A    return (%22https://github.com/neuropoly/spinalcordtoolbox/compare/%25s...%25s%22 %25 (previous%5B'name'%5D, latest%5B'name'%5D))%0A%0A%0Adef search(milestone, label=''):%0A    %22%22%22Return a list of merged pull requests linked to the milestone and label%0A    %22%22%22%0A    searchAPI = 'https://api.github.com/search/issues'%0A    query = 'milestone:%22%25s%22 is:pr repo:neuropoly/spinalcordtoolbox state:closed is:merged' %25 (milestone)%0A    if label:%0A        query += ' label:%25s' %25 (label)%0A    payload = %7B'q': query%7D%0A    response = requests.get(searchAPI, payload)%0A    data = response.json()%0A    logging.info('Pull requests %22%25s%22 labeled %25s received %25d', milestone, label, len(data))%0A    return data%0A%0A%0Aif __name__ == '__main__':%0A    logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='SCT changelog -- %25(message)s')%0A    lines = %5B%5D%0A    milestone = latestMilestone()%0A    lines.append('# Milestone %22%25s%22' %25 milestone%5B'title'%5D)%0A    for label in %5B'bug', 'enhancement', 'feature', 'doc', 'testing', ''%5D:%0A        lines.append('## %25s' %25 (label.upper() or 'OTHER'))%0A        lines.append('%5BView detailed changelog%5D(%25s)' %25 detailedChangeLog())%0A        pulls = search(milestone%5B'title'%5D, label)%0A        for pull in pulls.get('items'):%0A            msg = %22 - (%25s) %25s %5BView pull request%5D(%25s)%22 %25 (pull%5B'id'%5D, pull%5B'title'%5D, pull%5B'html_url'%5D)%0A            lines.append(msg)%0A%0A    filename = 'changelog.%25d.md' %25 milestone%5B'number'%5D%0A    with open(filename, 'w') as changelog:%0A        changelog.write('%5Cn'.join(lines))%0A    logging.info('Changelog saved in %25s', filename)%0A

Generate a changelog from GitHub