diff --git a/.github/workflows/assemble_changelog.yml b/.github/workflows/assemble_changelog.yml
index 352de2221b9..8d94b800c54 100644
--- a/.github/workflows/assemble_changelog.yml
+++ b/.github/workflows/assemble_changelog.yml
@@ -1,9 +1,7 @@
name: Assemble changelog
on:
- push:
- branches:
- - main
- - release-v**
+ pull_request:
+ types: [ opened, synchronize ]
jobs:
process:
permissions:
@@ -11,6 +9,7 @@ jobs:
contents: write
runs-on: ubuntu-20.04
env:
+ PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
diff --git a/changelog/README.md b/changelog/README.md
index 1b621760894..969f30a8eb9 100644
--- a/changelog/README.md
+++ b/changelog/README.md
@@ -26,12 +26,10 @@ If you have implemented several features or bugfixes you should describe all of
You can choose any name for your changelog files because the GitHub action will rename files in
`changelog/unreleased/features` and `changelog/unreleased/bugfixes` directories to `${PR_NUMBER}.md` when you open a PR.
-Every push to the main or release branch Assemble changelog GitHub action will be executed:
-
-* collect all files from `changelog/unreleased`
-* assemble the changelog like:
+For every PR the script will generate and update a comment with a changelog for the current branch in the following format:
```
+# Changelog
#### Features
- Feature 1 [#1234](https://github.com/mapbox/mapbox-navigation-android/pull/1234)
- 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
Some other changes
```
-* write the changelog to the `changelog/unreleased/CHANGELOG.md` file
+The comment will be updated with every change.
+Also, a comment with a changelog will be generated and updated for the android auto project too.
Every release the release train app will:
-* get changelog from `changelog/unreleased/CHANGELOG.md` file
+* assemble the changelog
* add information about dependencies and compile changelog like:
```
## Mapbox Navigation SDK 1.1.1 - 13 December, 2022
diff --git a/scripts/changelog/assemble_changelog.py b/scripts/changelog/assemble_changelog.py
index 587c1014050..d99c8ca904f 100644
--- a/scripts/changelog/assemble_changelog.py
+++ b/scripts/changelog/assemble_changelog.py
@@ -1,6 +1,9 @@
import os
-import git
+import requests
+
+pr_number = os.environ['PR_NUMBER']
+token = os.environ['GITHUB_TOKEN']
def get_changes(path):
@@ -35,26 +38,29 @@ def get_changes(path):
'#### Known issues :warning:\n' + issues + '\n\n' + \
'#### Other changes\n' + other
-old_changelog = open('changelog/unreleased/CHANGELOG.md', 'r').read()
-
-if changelog != old_changelog:
- open('changelog/unreleased/CHANGELOG.md', 'w').write(changelog)
- repository = git.Repo('.')
- repository.git.add('changelog/unreleased')
- repository.index.commit('Assemble changelog file [skip ci]')
- repository.remotes.origin.push().raise_if_error()
-
auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/')
auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/')
auto_changelog = '#### Features\n' + auto_features + '\n\n' + \
- '#### Bug fixes and improvements\n' + auto_bugfixes
+ '#### Bug fixes and improvements\n' + auto_bugfixes
+
+pr_comments_url = 'https://api.github.com/repos/mapbox/mapbox-navigation-android/issues/' + pr_number + '/comments'
+headers = {"Authorization": "Bearer " + token}
+comments = requests.get(pr_comments_url, headers=headers).json()
+
+full_changelog = '\nChangelog
\n\n' + \
+ changelog + ' \n' + \
+ '\nAndroid Auto Changelog
\n\n' + \
+ auto_changelog + ' '
-auto_old_changelog = open('libnavui-androidauto/changelog/unreleased/CHANGELOG.md', 'r').read()
+comment_with_changelog_id = None
+for comment in comments:
+ if comment['body'].startswith('\nChangelog
\n'):
+ comment_with_changelog_id = comment['id']
-if auto_changelog != auto_old_changelog:
- open('libnavui-androidauto/changelog/unreleased/CHANGELOG.md', 'w').write(auto_changelog)
- repository = git.Repo('.')
- repository.git.add('libnavui-androidauto/changelog/unreleased')
- repository.index.commit('Assemble auto changelog file [skip ci]')
- repository.remotes.origin.push().raise_if_error()
+if comment_with_changelog_id:
+ comments_url = 'https://api.github.com/repos/mapbox/mapbox-navigation-android/issues/comments/'
+ comment_url = comments_url + str(comment_with_changelog_id)
+ requests.patch(comment_url, json={'body': full_changelog}, headers=headers)
+else:
+ requests.post(pr_comments_url, json={'body': full_changelog}, headers=headers)