|
1 | 1 | import os |
2 | 2 |
|
3 | | -import git |
| 3 | +import requests |
| 4 | + |
| 5 | +pr_number = os.environ['PR_NUMBER'] |
| 6 | +token = os.environ['GITHUB_TOKEN'] |
4 | 7 |
|
5 | 8 |
|
6 | 9 | def get_changes(path): |
@@ -35,26 +38,29 @@ def get_changes(path): |
35 | 38 | '#### Known issues :warning:\n' + issues + '\n\n' + \ |
36 | 39 | '#### Other changes\n' + other |
37 | 40 |
|
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 | | - |
47 | 41 | auto_bugfixes = get_changes('libnavui-androidauto/changelog/unreleased/bugfixes/') |
48 | 42 | auto_features = get_changes('libnavui-androidauto/changelog/unreleased/features/') |
49 | 43 |
|
50 | 44 | 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>' |
52 | 55 |
|
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'] |
54 | 60 |
|
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