File: generate_release_notes.py

package info (click to toggle)
srt 1.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,804 kB
  • sloc: cpp: 52,175; ansic: 5,746; tcl: 1,183; sh: 318; python: 99; makefile: 38
file content (120 lines) | stat: -rw-r--r-- 3,076 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import enum

import click
import numpy as np
import pandas as pd


@enum.unique
class Area(enum.Enum):
    core = 'core'
    tests = 'tests'
    build = 'build'
    apps = 'apps'
    docs = 'docs'


def define_area(msg):
    areas = [e.value for e in Area]

    for area in areas:
        if msg.startswith(f'[{area}] '):
            return area

    return np.nan


def delete_prefix(msg):
    prefixes = [f'[{e.value}] ' for e in Area]

    for prefix in prefixes:
        if msg.startswith(prefix):
            return msg[len(prefix):]

    return msg[:]


def write_into_changelog(df, f):
    f.write('\n')
    for _, row in df.iterrows():
        f.write(f"\n{row['commit']} {row['message']}")
    f.write('\n')


@click.command()
@click.argument(
    'git_log',
    type=click.Path(exists=True)
)
def main(git_log):
    """
    Script designed to generate release notes template with main sections,
    contributors list, and detailed changelog out of .csv SRT git log file.
    """
    df = pd.read_csv(git_log, sep = '|', names = ['commit', 'message', 'author', 'email'])
    df['area'] = df['message'].apply(define_area)
    df['message'] = df['message'].apply(delete_prefix)

    # Split commits by areas
    core = df[df['area']==Area.core.value]
    tests = df[df['area']==Area.tests.value]
    build = df[df['area']==Area.build.value]
    apps = df[df['area']==Area.apps.value]
    docs = df[df['area']==Area.docs.value]
    other = df[df['area'].isna()]

    # Define individual contributors
    contributors = df.groupby(['author', 'email'])
    contributors = list(contributors.groups.keys())

    with open('release-notes.md', 'w') as f:
        f.write('# Release Notes\n')

        f.write('\n## API / ABI / Integration Changes\n')
        f.write('\n**API/ABI version: 1.x.**\n')

        f.write('\n## New Features and Improvements\n')
        f.write('\n## Important Bug Fixes\n')
        f.write('\n## Build\n')
        f.write('\n## Documentation\n')

        f.write('\n## Contributors\n')
        for name, email in contributors:
            f.write(f'\n{name} <{email}>')
        f.write('\n')

        f.write('\n## Changelog\n')
        f.write('\n<details><summary>Click to expand/collapse</summary>')
        f.write('\n<p>')
        f.write('\n')

        if not core.empty:
            f.write('\n### Core Functionality')
            write_into_changelog(core, f)

        if not tests.empty:
            f.write('\n### Unit Tests')
            write_into_changelog(tests, f)

        if not build.empty:
            f.write('\n### Build Scripts (CMake, etc.)')
            write_into_changelog(build, f)

        if not apps.empty:
            f.write('\n### Sample Applications')
            write_into_changelog(apps, f)

        if not docs.empty:
            f.write('\n### Documentation')
            write_into_changelog(docs, f)

        if not other.empty:
            f.write('\n### Other')
            write_into_changelog(other, f)

        f.write('\n</p>')
        f.write('\n</details>')


if __name__ == '__main__':
    main()