Skip to content

Commit 28a1cff

Browse files
author
sevastian.zhukov
committed
Add changelog to comments
1 parent bea0230 commit 28a1cff

File tree

2 files changed

+67
-24
lines changed

2 files changed

+67
-24
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Assemble changelog
2+
on:
3+
pull_request:
4+
types: [ opened, synchronize ]
5+
jobs:
6+
process:
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
runs-on: ubuntu-20.04
11+
env:
12+
PR_NUMBER: ${{ github.event.pull_request.number }}
13+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
ref: ${{github.head_ref}}
18+
19+
- name: setup python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.7.7'
23+
24+
- name: install python packages
25+
run: |
26+
python3 -m pip install requests GitPython
27+
28+
- name: execute py script
29+
run: |
30+
python3 scripts/changelog/assemble_changelog.py
Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import argparse
21
import os
32

3+
import requests
4+
5+
pr_number = os.environ['PR_NUMBER']
6+
token = os.environ['GITHUB_TOKEN']
7+
48

59
def get_changes(path):
610
changes = ''
@@ -24,27 +28,36 @@ def get_changes(path):
2428
return changes.strip()
2529

2630

27-
parser = argparse.ArgumentParser(description='Assemble changelog')
28-
parser.add_argument('--auto', action='store_true', help='To assemble android auto changelog')
29-
args = parser.parse_args()
30-
31-
if args.auto:
32-
auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/')
33-
auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/')
34-
35-
auto_changelog = '#### Features\n' + auto_features + '\n\n' + \
36-
'#### Bug fixes and improvements\n' + auto_bugfixes
37-
38-
print(auto_changelog)
31+
bugfixes = get_changes('changelog/unreleased/bugfixes/')
32+
features = get_changes('changelog/unreleased/features/')
33+
issues = get_changes('changelog/unreleased/issues/')
34+
other = get_changes('changelog/unreleased/other/')
35+
36+
changelog = '# Changelog' \
37+
'#### Features\n' + features + '\n\n' + \
38+
'#### Bug fixes and improvements\n' + bugfixes + '\n\n' + \
39+
'#### Known issues :warning:\n' + issues + '\n\n' + \
40+
'#### Other changes\n' + other
41+
42+
# auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/')
43+
# auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/')
44+
#
45+
# auto_changelog = '#### Features\n' + auto_features + '\n\n' + \
46+
# '#### Bug fixes and improvements\n' + auto_bugfixes
47+
#
48+
# print(auto_changelog)
49+
50+
comments_url = 'https://api.github.com/repos/mapbox/mapbox-navigation-android/pulls/' + pr_number + '/comments'
51+
headers = {"Authorization": "Bearer " + token}
52+
comments = requests.get(comments_url, headers=headers).json()
53+
54+
comment_with_changelog_id = None
55+
for comment in comments:
56+
if comment['body'].startswith('# Changelog'):
57+
comment_with_changelog_id = comment['id']
58+
59+
if comment_with_changelog_id:
60+
comment_url = comments_url + '/' + comment_with_changelog_id
61+
requests.patch(comment_url, json={'body': changelog}, headers=headers)
3962
else:
40-
bugfixes = get_changes('changelog/unreleased/bugfixes/')
41-
features = get_changes('changelog/unreleased/features/')
42-
issues = get_changes('changelog/unreleased/issues/')
43-
other = get_changes('changelog/unreleased/other/')
44-
45-
changelog = '#### Features\n' + features + '\n\n' + \
46-
'#### Bug fixes and improvements\n' + bugfixes + '\n\n' + \
47-
'#### Known issues :warning:\n' + issues + '\n\n' + \
48-
'#### Other changes\n' + other
49-
50-
print(changelog)
63+
requests.post(comments_url, json={'body': changelog}, headers=headers)

0 commit comments

Comments
 (0)