Skip to content

Commit 92af36d

Browse files
author
sevastian.zhukov
committed
create and update changelog in pr comment
1 parent bea0230 commit 92af36d

2 files changed

Lines changed: 69 additions & 20 deletions

File tree

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: 39 additions & 20 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,42 @@ 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()
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\n' + \
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 = '# Android Auto Changelog\n' + \
46+
'#### Features\n' + auto_features + '\n\n' + \
47+
'#### Bug fixes and improvements\n' + auto_bugfixes
48+
49+
pr_comments_url = 'https://api.github.com/repos/mapbox/mapbox-navigation-android/issues/' + pr_number + '/comments'
50+
headers = {"Authorization": "Bearer " + token}
51+
comments = requests.get(pr_comments_url, headers=headers).json()
3052

31-
if args.auto:
32-
auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/')
33-
auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/')
3453

35-
auto_changelog = '#### Features\n' + auto_features + '\n\n' + \
36-
'#### Bug fixes and improvements\n' + auto_bugfixes
54+
def update_comment(title, content):
55+
comment_with_changelog_id = None
56+
for comment in comments:
57+
if comment['body'].startswith(title):
58+
comment_with_changelog_id = comment['id']
3759

38-
print(auto_changelog)
39-
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/')
60+
if comment_with_changelog_id:
61+
comments_url = 'https://api.github.com/repos/mapbox/mapbox-navigation-android/issues/comments/'
62+
comment_url = comments_url + str(comment_with_changelog_id)
63+
requests.patch(comment_url, json={'body': content}, headers=headers)
64+
else:
65+
requests.post(pr_comments_url, json={'body': content}, headers=headers)
4466

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
4967

50-
print(changelog)
68+
update_comment('# Changelog', changelog)
69+
update_comment('# Android Auto Changelog', auto_changelog)

0 commit comments

Comments
 (0)