-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update validation scripts for running changelog
- Loading branch information
Łukasz Paczos
committed
Dec 21, 2021
1 parent
cfa4807
commit b03b6ad
Showing
3 changed files
with
42 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,46 @@ | ||
#!/usr/bin/python | ||
|
||
import sys | ||
import requests | ||
import re | ||
import requests | ||
import sys | ||
|
||
print("Validating that changelog entry is provided in the PR description...") | ||
print("Validating that changelog entry is provided in the CHANGELOG.md...") | ||
|
||
pr_number = sys.argv[1] | ||
github_token = sys.argv[2] | ||
url = "https://api.github.com/repos/mapbox/mapbox-navigation-android/pulls/" + pr_number | ||
headers = { "accept": "application/vnd.github.v3+json", "authorization": "token " + github_token } | ||
with requests.get(url, headers = headers) as r: | ||
response_json = r.json() | ||
pr_description = response_json["body"] | ||
pr_labels = response_json["labels"] | ||
api_url = "https://api.github.com/repos/mapbox/mapbox-navigation-android/pulls/" + str(pr_number) | ||
pr_link_regex = "\[#\d+]\(https:\/\/github\.com\/mapbox\/mapbox-navigation-android\/pull\/\d+\)" | ||
headers = {"accept": "application/vnd.github.v3+json", "authorization": "token " + github_token} | ||
changelog_diff_substring = "diff --git a/CHANGELOG.md b/CHANGELOG.md" | ||
any_diff_substring = "diff --git" | ||
|
||
skip_changelog = False | ||
if pr_labels is not None: | ||
for label in pr_labels: | ||
if label["name"] == "skip changelog": | ||
skip_changelog = True | ||
break | ||
with requests.get(api_url, headers=headers) as pr_response: | ||
response_json = pr_response.json() | ||
pr_labels = response_json["labels"] | ||
|
||
matches = re.search(r'<changelog>(.+)</changelog>', pr_description, flags=re.S) is not None | ||
skip_changelog = False | ||
if pr_labels is not None: | ||
for label in pr_labels: | ||
if label["name"] == "skip changelog": | ||
skip_changelog = True | ||
break | ||
|
||
if skip_changelog and matches: | ||
raise Exception("Both `skip changelog` label and `<changelog></changelog>` closure present.") | ||
elif skip_changelog: | ||
print("`skip changelog` label present, exiting.") | ||
elif matches: | ||
print("Changelog entry validation successful.") | ||
else: | ||
raise Exception("Add a non-empty changelog entry in a `<changelog></changelog>` closure in the PR description or add a `skip changelog` label if not applicable.") | ||
if not skip_changelog: | ||
pr_diff_url = response_json["diff_url"] | ||
with requests.get(pr_diff_url, headers) as diff_response: | ||
diff = diff_response.text | ||
changelog_entry_index = diff.find(changelog_diff_substring) | ||
if changelog_entry_index == -1: | ||
raise Exception("Add a non-empty changelog entry in a CHANGELOG.md or add a `skip changelog` label if not applicable.") | ||
else: | ||
changelog_entry_last_index = changelog_entry_index + len(changelog_diff_substring) | ||
last_reachable_index = diff.find(any_diff_substring, changelog_entry_last_index) | ||
if last_reachable_index == -1: | ||
last_reachable_index = len(diff) | ||
diff_searchable = diff[changelog_entry_last_index:last_reachable_index] | ||
pr_link_matches = re.search(pr_link_regex, diff_searchable) | ||
if not pr_link_matches: | ||
raise Exception("The changelog entry should contain a link to the original PR that matches `" + pr_link_regex + "`") | ||
print("Changelog entry validation successful.") | ||
else: | ||
print("`skip changelog` label present, exiting.") |