Skip to content

Commit

Permalink
Provides direct link to the PR when toolstate is changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Feb 22, 2018
1 parent b1f8e6f commit 1acd378
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/tools/publish_toolstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import copy
import datetime
import collections
import textwrap

# List of people to ping when the status of a tool changed.
MAINTAINERS = {
Expand All @@ -38,7 +39,12 @@ def read_current_status(current_commit, path):
return {}


def update_latest(current_commit, relevant_pr_number, current_datetime):
def update_latest(
current_commit,
relevant_pr_number,
relevant_pr_url,
current_datetime
):
'''Updates `_data/latest.json` to match build result of the given commit.
'''
with open('_data/latest.json', 'rb+') as f:
Expand All @@ -50,8 +56,13 @@ def update_latest(current_commit, relevant_pr_number, current_datetime):
}

slug = 'rust-lang/rust'
message = '📣 Toolstate changed by {}!\n\nTested on commit {}@{}.\n\n' \
.format(relevant_pr_number, slug, current_commit)
message = textwrap.dedent('''\
📣 Toolstate changed by {}!
Tested on commit {}@{}.
Direct link to PR: <{}>
''').format(relevant_pr_number, slug, current_commit, relevant_pr_url)
anything_changed = False
for status in latest:
tool = status['tool']
Expand Down Expand Up @@ -90,13 +101,21 @@ def update_latest(current_commit, relevant_pr_number, current_datetime):
cur_commit_msg = sys.argv[2]
save_message_to_path = sys.argv[3]

relevant_pr_match = re.search('#[0-9]+', cur_commit_msg)
relevant_pr_match = re.search('#([0-9]+)', cur_commit_msg)
if relevant_pr_match:
relevant_pr_number = 'rust-lang/rust' + relevant_pr_match.group(0)
number = relevant_pr_match.group(1)
relevant_pr_number = 'rust-lang/rust#' + number
relevant_pr_url = 'https://github.com/rust-lang/rust/pull/' + number
else:
relevant_pr_number = '<unknown PR>'

message = update_latest(cur_commit, relevant_pr_number, cur_datetime)
relevant_pr_url = '<unknown>'

message = update_latest(
cur_commit,
relevant_pr_number,
relevant_pr_url,
cur_datetime
)
if message:
print(message)
with open(save_message_to_path, 'w') as f:
Expand Down

0 comments on commit 1acd378

Please sign in to comment.