1- import argparse
21import os
32
3+ import requests
4+
5+ pr_number = os .environ ['PR_NUMBER' ]
6+ token = os .environ ['GITHUB_TOKEN' ]
7+
48
59def 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