Skip to content

Commit dc30f35

Browse files
author
Sevastyan Zhukov
committed
Assemble changelog only in PRs comments (#6783)
(cherry picked from commit 671b157)
1 parent f6b0874 commit dc30f35

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

.github/workflows/assemble_changelog.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
name: Assemble changelog
22
on:
3-
push:
4-
branches:
5-
- main
6-
- release-v**
3+
pull_request:
4+
types: [ opened, synchronize ]
75
jobs:
86
process:
97
permissions:
108
pull-requests: write
119
contents: write
1210
runs-on: ubuntu-20.04
1311
env:
12+
PR_NUMBER: ${{ github.event.pull_request.number }}
1413
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1514
steps:
1615
- uses: actions/checkout@v3

changelog/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ If you have implemented several features or bugfixes you should describe all of
2626
You can choose any name for your changelog files because the GitHub action will rename files in
2727
`changelog/unreleased/features` and `changelog/unreleased/bugfixes` directories to `${PR_NUMBER}.md` when you open a PR.
2828

29-
Every push to the main or release branch Assemble changelog GitHub action will be executed:
30-
31-
* collect all files from `changelog/unreleased`
32-
* assemble the changelog like:
29+
For every PR the script will generate and update a comment with a changelog for the current branch in the following format:
3330

3431
```
32+
# Changelog
3533
#### Features
3634
- Feature 1 [#1234](https://github.com/mapbox/mapbox-navigation-android/pull/1234)
3735
- Feature 2 [#2345](https://github.com/mapbox/mapbox-navigation-android/pull/2345)
@@ -47,11 +45,12 @@ Every push to the main or release branch Assemble changelog GitHub action will b
4745
Some other changes
4846
```
4947

50-
* write the changelog to the `changelog/unreleased/CHANGELOG.md` file
48+
The comment will be updated with every change.
49+
Also, a comment with a changelog will be generated and updated for the android auto project too.
5150

5251
Every release the release train app will:
5352

54-
* get changelog from `changelog/unreleased/CHANGELOG.md` file
53+
* assemble the changelog
5554
* add information about dependencies and compile changelog like:
5655
```
5756
## Mapbox Navigation SDK 1.1.1 - 13 December, 2022

scripts/changelog/assemble_changelog.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import os
22

3-
import git
3+
import requests
4+
5+
pr_number = os.environ['PR_NUMBER']
6+
token = os.environ['GITHUB_TOKEN']
47

58

69
def get_changes(path):
@@ -35,26 +38,29 @@ def get_changes(path):
3538
'#### Known issues :warning:\n' + issues + '\n\n' + \
3639
'#### Other changes\n' + other
3740

38-
old_changelog = open('changelog/unreleased/CHANGELOG.md', 'r').read()
39-
40-
if changelog != old_changelog:
41-
open('changelog/unreleased/CHANGELOG.md', 'w').write(changelog)
42-
repository = git.Repo('.')
43-
repository.git.add('changelog/unreleased')
44-
repository.index.commit('Assemble changelog file [skip ci]')
45-
repository.remotes.origin.push().raise_if_error()
46-
4741
auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/')
4842
auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/')
4943

5044
auto_changelog = '#### Features\n' + auto_features + '\n\n' + \
51-
'#### Bug fixes and improvements\n' + auto_bugfixes
45+
'#### Bug fixes and improvements\n' + auto_bugfixes
46+
47+
pr_comments_url = 'https://api.github.com/repos/mapbox/mapbox-navigation-android/issues/' + pr_number + '/comments'
48+
headers = {"Authorization": "Bearer " + token}
49+
comments = requests.get(pr_comments_url, headers=headers).json()
50+
51+
full_changelog = '<details>\n<summary>Changelog</summary>\n\n' + \
52+
changelog + '</details>\n' + \
53+
'<details>\n<summary>Android Auto Changelog</summary>\n\n' + \
54+
auto_changelog + '</details>'
5255

53-
auto_old_changelog = open('libnavui-androidauto/changelog/unreleased/CHANGELOG.md', 'r').read()
56+
comment_with_changelog_id = None
57+
for comment in comments:
58+
if comment['body'].startswith('<details>\n<summary>Changelog</summary>\n'):
59+
comment_with_changelog_id = comment['id']
5460

55-
if auto_changelog != auto_old_changelog:
56-
open('libnavui-androidauto/changelog/unreleased/CHANGELOG.md', 'w').write(auto_changelog)
57-
repository = git.Repo('.')
58-
repository.git.add('libnavui-androidauto/changelog/unreleased')
59-
repository.index.commit('Assemble auto changelog file [skip ci]')
60-
repository.remotes.origin.push().raise_if_error()
61+
if comment_with_changelog_id:
62+
comments_url = 'https://api.github.com/repos/mapbox/mapbox-navigation-android/issues/comments/'
63+
comment_url = comments_url + str(comment_with_changelog_id)
64+
requests.patch(comment_url, json={'body': full_changelog}, headers=headers)
65+
else:
66+
requests.post(pr_comments_url, json={'body': full_changelog}, headers=headers)

0 commit comments

Comments
 (0)