18
18
import datetime
19
19
import collections
20
20
import textwrap
21
+ try :
22
+ import urllib2
23
+ except ImportError :
24
+ import urllib .request as urllib2
21
25
22
26
# List of people to ping when the status of a tool changed.
23
27
MAINTAINERS = {
@@ -100,13 +104,15 @@ def update_latest(
100
104
cur_datetime = datetime .datetime .utcnow ().strftime ('%Y-%m-%dT%H:%M:%SZ' )
101
105
cur_commit_msg = sys .argv [2 ]
102
106
save_message_to_path = sys .argv [3 ]
107
+ github_token = sys .argv [4 ]
103
108
104
109
relevant_pr_match = re .search ('#([0-9]+)' , cur_commit_msg )
105
110
if relevant_pr_match :
106
111
number = relevant_pr_match .group (1 )
107
112
relevant_pr_number = 'rust-lang/rust#' + number
108
113
relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
109
114
else :
115
+ number = '-1'
110
116
relevant_pr_number = '<unknown PR>'
111
117
relevant_pr_url = '<unknown>'
112
118
@@ -116,9 +122,23 @@ def update_latest(
116
122
relevant_pr_url ,
117
123
cur_datetime
118
124
)
119
- if message :
120
- print (message )
121
- with open (save_message_to_path , 'w' ) as f :
122
- f .write (message )
123
- else :
125
+ if not message :
124
126
print ('<Nothing changed>' )
127
+ sys .exit (0 )
128
+
129
+ print (message )
130
+ with open (save_message_to_path , 'w' ) as f :
131
+ f .write (message )
132
+
133
+ # Write the toolstate comment on the PR as well.
134
+ gh_url = 'https://api.github.com/repos/rust-lang/rust/issues/{}/comments' \
135
+ .format (number )
136
+ response = urllib2 .urlopen (urllib2 .Request (
137
+ gh_url ,
138
+ json .dumps ({'body' : message }),
139
+ {
140
+ 'Authorization' : 'token ' + github_token ,
141
+ 'Content-Type' : 'application/json' ,
142
+ }
143
+ ))
144
+ response .read ()
0 commit comments