File: update_changelog.py

package info (click to toggle)
gensim 4.3.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,436 kB
  • sloc: python: 26,865; sh: 109; cpp: 37; ansic: 26; makefile: 14
file content (75 lines) | stat: -rw-r--r-- 2,171 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Updates the changelog with PRs merged since the last version."""
import datetime
import json
import os.path
import sys

import requests


URL = 'https://api.github.com/repos/RaRe-Technologies/gensim'


def summarize_prs(since_version):
    """Go through all closed PRs, summarize those merged after the previous release.

    Yields one-line summaries of each relevant PR as a string.
    """
    releases = requests.get(URL + '/releases').json()
    most_recent_release = releases[0]['tag_name']
    assert most_recent_release  == since_version, 'unexpected most_recent_release: %r' % most_recent_release

    published_at = releases[0]['published_at']

    pulls = requests.get(URL + '/pulls', params={'state': 'closed'}).json()
    for pr in pulls:
        merged_at = pr['merged_at']
        if merged_at is None or merged_at < published_at:
            continue

        summary = "* {msg} (__[{author}]({author_url})__, [#{pr}]({purl}))".format(
            msg=pr['title'],
            author=pr['user']['login'],
            author_url=pr['user']['html_url'],
            pr=pr['number'],
            purl=pr['html_url'],
        )
        print(summary)
        yield summary


def main():
    root = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
    previous_version, new_version = sys.argv[1:3]

    path = os.path.join(root, 'CHANGELOG.md')
    with open(path) as fin:
        contents = fin.read().split('\n')

    header, contents = contents[:2], contents[2:]
    header.append('## %s, %s\n' % (new_version, datetime.date.today().isoformat()))
    header.append("""
### :star2: New Features

### :red_circle: Bug fixes

### :books: Tutorial and doc improvements

### :+1: Improvements

### :warning: Deprecations (will be removed in the next major release)

**COPY-PASTE DEPRECATIONS FROM THE PREVIOUS RELEASE HERE**

Please organize the PR summaries from below into the above sections
You may remove empty sections.  Be sure to include all deprecations.
""")

    header += list(summarize_prs(previous_version))

    with open(path, 'w') as fout:
        fout.write('\n'.join(header + contents))


if __name__ == '__main__':
    main()