-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build bot now build new SVGs in folder that were already built (#666)
* Refactor the pull request fetching code * Refactor build script to use past PRs * Added function to update icomoon json * new icon: matlab (line) (#640) * Add matlab-line * Fixed issues reported by check svg bot * optimisation for svg (#643) Co-authored-by: Clemens Bastian <[email protected]> Co-authored-by: David Leal <[email protected]> * Add better logging to icomoon_build Co-authored-by: Clemens Bastian <[email protected]> Co-authored-by: David Leal <[email protected]>
- Loading branch information
1 parent
8d617d7
commit d60b334
Showing
8 changed files
with
253 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import requests | ||
import sys | ||
import re | ||
|
||
def get_merged_pull_reqs(token, page): | ||
""" | ||
Get the merged pull requests based on page. There are | ||
100 results page. See https://docs.github.com/en/rest/reference/pulls | ||
for more details on the parameters. | ||
:param token, a GitHub API token. | ||
:param page, the page number. | ||
""" | ||
queryPath = "https://api.github.com/repos/devicons/devicon/pulls" | ||
headers = { | ||
"Authorization": f"token {token}" | ||
} | ||
params = { | ||
"accept": "application/vnd.github.v3+json", | ||
"state": "closed", | ||
"per_page": 100, | ||
"page": page | ||
} | ||
|
||
print(f"Querying the GitHub API for requests page #{page}") | ||
response = requests.get(queryPath, headers=headers, params=params) | ||
if not response: | ||
print(f"Can't query the GitHub API. Status code is {response.status_code}. Message is {response.text}") | ||
sys.exit(1) | ||
|
||
closed_pull_reqs = response.json() | ||
return [merged_pull_req | ||
for merged_pull_req in closed_pull_reqs | ||
if merged_pull_req["merged_at"] is not None] | ||
|
||
|
||
def is_feature_icon(pull_req_data): | ||
""" | ||
Check whether the pullData is a feature:icon PR. | ||
:param pull_req_data - the data on a specific pull request from GitHub. | ||
:return true if the pullData has a label named "feature:icon" | ||
""" | ||
for label in pull_req_data["labels"]: | ||
if label["name"] == "feature:icon": | ||
return True | ||
return False | ||
|
||
|
||
def find_all_authors(pull_req_data, token): | ||
""" | ||
Find all the authors of a PR based on its commits. | ||
:param pull_req_data - the data on a specific pull request from GitHub. | ||
:param token - a GitHub API token. | ||
""" | ||
headers = { | ||
"Authorization": f"token {token}" | ||
} | ||
response = requests.get(pull_req_data["commits_url"], headers=headers) | ||
if not response: | ||
print(f"Can't query the GitHub API. Status code is {response.status_code}") | ||
print("Response is: ", response.text) | ||
return | ||
|
||
commits = response.json() | ||
authors = set() # want unique authors only | ||
for commit in commits: | ||
authors.add(commit["commit"]["author"]["name"]) | ||
return ", ".join(["@" + author for author in list(authors)]) | ||
|
||
|
||
def get_merged_pull_reqs_since_last_release(token): | ||
""" | ||
Get all the merged pull requests since the last release. | ||
""" | ||
stopPattern = r"^(r|R)elease v" | ||
pull_reqs = [] | ||
found_last_release = False | ||
page = 1 | ||
|
||
print("Getting PRs since last release.") | ||
while not found_last_release: | ||
data = get_merged_pull_reqs(token, page) | ||
# assume we don't encounter it during the loop | ||
last_release_index = 101 | ||
|
||
for i in range(len(data)): | ||
if re.search(stopPattern, data[i]["title"]): | ||
found_last_release = True | ||
last_release_index = i | ||
break | ||
pull_reqs.extend(data[:last_release_index]) | ||
page += 1 | ||
|
||
# should contain all the PRs since last release | ||
return pull_reqs |
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,75 +1,39 @@ | ||
import requests | ||
from build_assets import arg_getters | ||
from build_assets import arg_getters, api_handler, util | ||
import re | ||
|
||
def main(): | ||
print("Please wait a few seconds...") | ||
args = arg_getters.get_release_message_args() | ||
queryPath = "https://api.github.com/repos/devicons/devicon/pulls?accept=application/vnd.github.v3+json&state=closed&per_page=100" | ||
stopPattern = r"^(r|R)elease v" | ||
headers = { | ||
"Authorization": f"token {args.token}" | ||
} | ||
|
||
response = requests.get(queryPath, headers=headers) | ||
if not response: | ||
print(f"Can't query the GitHub API. Status code is {response.status_code}. Message is {response.text}") | ||
return | ||
|
||
data = response.json() | ||
newIcons = [] | ||
features = [] | ||
|
||
for pullData in data: | ||
if re.search(stopPattern, pullData["title"]): | ||
break | ||
|
||
authors = findAllAuthors(pullData, headers) | ||
markdown = f"- [{pullData['title']}]({pullData['html_url']}) by {authors}." | ||
|
||
if isFeatureIcon(pullData): | ||
newIcons.append(markdown) | ||
else: | ||
features.append(markdown) | ||
|
||
thankYou = "A huge thanks to all our maintainers and contributors for making this release possible!" | ||
iconTitle = "**{} New Icons**\n".format(len(newIcons)) | ||
featureTitle = "**{} New Features**\n".format(len(features)) | ||
finalString = "{0}\n\n {1}{2}\n\n {3}{4}".format(thankYou, | ||
iconTitle, "\n".join(newIcons), featureTitle, "\n".join(features)) | ||
|
||
print("--------------Here is the build message--------------\n", finalString) | ||
|
||
|
||
""" | ||
Check whether the pullData is a feature:icon PR. | ||
:param pullData | ||
:return true if the pullData has a label named "feature:icon" | ||
""" | ||
def isFeatureIcon(pullData): | ||
for label in pullData["labels"]: | ||
if label["name"] == "feature:icon": | ||
return True | ||
return False | ||
|
||
|
||
""" | ||
Find all the authors of a PR based on its commits. | ||
:param pullData - the data of a pull request. | ||
""" | ||
def findAllAuthors(pullData, authHeader): | ||
response = requests.get(pullData["commits_url"], headers=authHeader) | ||
if not response: | ||
print(f"Can't query the GitHub API. Status code is {response.status_code}") | ||
print("Response is: ", response.text) | ||
return | ||
|
||
commits = response.json() | ||
authors = set() # want unique authors only | ||
for commit in commits: | ||
authors.add("@" + commit["author"]["login"]) | ||
return ", ".join(list(authors)) | ||
|
||
try: | ||
print("Please wait a few seconds...") | ||
args = arg_getters.get_release_message_args() | ||
|
||
# fetch first page by default | ||
data = api_handler.get_merged_pull_reqs_since_last_release(args.token) | ||
newIcons = [] | ||
features = [] | ||
|
||
print("Parsing through the pull requests") | ||
for pullData in data: | ||
authors = api_handler.find_all_authors(pullData, args.token) | ||
markdown = f"- [{pullData['title']}]({pullData['html_url']}) by {authors}." | ||
|
||
if api_handler.is_feature_icon(pullData): | ||
newIcons.append(markdown) | ||
else: | ||
features.append(markdown) | ||
|
||
print("Constructing message") | ||
thankYou = "A huge thanks to all our maintainers and contributors for making this release possible!" | ||
iconTitle = f"**{len(newIcons)} New Icons**" | ||
featureTitle = f"**{len(features)} New Features**" | ||
finalString = "{0}\n\n {1}\n{2}\n\n {3}\n{4}".format(thankYou, | ||
iconTitle, "\n".join(newIcons), featureTitle, "\n".join(features)) | ||
|
||
print("--------------Here is the build message--------------\n", finalString) | ||
print("Script finished") | ||
except Exception as e: | ||
util.exit_with_err(e) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Oops, something went wrong.