]> git.lizzy.rs Git - rust.git/commitdiff
Submit a comment to the PR in additional to pushing a commit.
authorkennytm <kennytm@gmail.com>
Wed, 21 Feb 2018 14:58:06 +0000 (22:58 +0800)
committerkennytm <kennytm@gmail.com>
Thu, 22 Feb 2018 19:30:10 +0000 (03:30 +0800)
Fix rust-lang-nursery/rust-toolstate#2.

.travis.yml
src/tools/publish_toolstate.py

index 280da056995068fd58d6a8e1082f94f3d88be2f9..0d8641e45ed157b90b56fb3dd940ad611b89da99 100644 (file)
@@ -188,7 +188,7 @@ matrix:
       script:
         MESSAGE_FILE=$(mktemp -t msg.XXXXXX);
         . src/ci/docker/x86_64-gnu-tools/repo.sh;
-        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"
+        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";
 
 env:
   global:
index e2dbdb301e286d885598ddec2cddf3d737f2d1d8..40abe81c449efa4d8209e9f8bc465c9ebdf5128d 100755 (executable)
@@ -18,6 +18,10 @@ import copy
 import datetime
 import collections
 import textwrap
+try:
+    import urllib2
+except ImportError:
+    import urllib.request as urllib2
 
 # List of people to ping when the status of a tool changed.
 MAINTAINERS = {
@@ -100,6 +104,7 @@ if __name__ == '__main__':
     cur_datetime = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
     cur_commit_msg = sys.argv[2]
     save_message_to_path = sys.argv[3]
+    github_token = sys.argv[4]
 
     relevant_pr_match = re.search('#([0-9]+)', cur_commit_msg)
     if relevant_pr_match:
@@ -107,6 +112,7 @@ if __name__ == '__main__':
         relevant_pr_number = 'rust-lang/rust#' + number
         relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
     else:
+        number = '-1'
         relevant_pr_number = '<unknown PR>'
         relevant_pr_url = '<unknown>'
 
@@ -116,9 +122,23 @@ if __name__ == '__main__':
         relevant_pr_url,
         cur_datetime
     )
-    if message:
-        print(message)
-        with open(save_message_to_path, 'w') as f:
-            f.write(message)
-    else:
+    if not message:
         print('<Nothing changed>')
+        sys.exit(0)
+
+    print(message)
+    with open(save_message_to_path, 'w') as f:
+        f.write(message)
+
+    # Write the toolstate comment on the PR as well.
+    gh_url = 'https://api.github.com/repos/rust-lang/rust/issues/{}/comments' \
+        .format(number)
+    response = urllib2.urlopen(urllib2.Request(
+        gh_url,
+        json.dumps({'body': message}),
+        {
+            'Authorization': 'token ' + github_token,
+            'Content-Type': 'application/json',
+        }
+    ))
+    response.read()