Skip to content

Commit e181050

Browse files
committed
Submit a comment to the PR in additional to pushing a commit.
Fix rust-lang-nursery/rust-toolstate#2.
1 parent 1acd378 commit e181050

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ matrix:
188188
script:
189189
MESSAGE_FILE=$(mktemp -t msg.XXXXXX);
190190
. src/ci/docker/x86_64-gnu-tools/repo.sh;
191-
commit_toolstate_change "$MESSAGE_FILE" "$TRAVIS_BUILD_DIR/src/tools/publish_toolstate.py" "$(git rev-parse HEAD)" "$(git log --format=%s -n1 HEAD)" "$MESSAGE_FILE"
191+
commit_toolstate_change "$MESSAGE_FILE" "$TRAVIS_BUILD_DIR/src/tools/publish_toolstate.py" "$(git rev-parse HEAD)" "$(git log --format=%s -n1 HEAD)" "$MESSAGE_FILE" "$TOOLSTATE_REPO_ACCESS_TOKEN";
192192

193193
env:
194194
global:

src/tools/publish_toolstate.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
import datetime
1919
import collections
2020
import textwrap
21+
try:
22+
import urllib2
23+
except ImportError:
24+
import urllib.request as urllib2
2125

2226
# List of people to ping when the status of a tool changed.
2327
MAINTAINERS = {
@@ -100,13 +104,15 @@ def update_latest(
100104
cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
101105
cur_commit_msg = sys.argv[2]
102106
save_message_to_path = sys.argv[3]
107+
github_token = sys.argv[4]
103108

104109
relevant_pr_match = re.search('#([0-9]+)', cur_commit_msg)
105110
if relevant_pr_match:
106111
number = relevant_pr_match.group(1)
107112
relevant_pr_number = 'rust-lang/rust#' + number
108113
relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
109114
else:
115+
number = '-1'
110116
relevant_pr_number = '<unknown PR>'
111117
relevant_pr_url = '<unknown>'
112118

@@ -116,9 +122,23 @@ def update_latest(
116122
relevant_pr_url,
117123
cur_datetime
118124
)
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:
124126
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

Comments
 (0)