1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-12 01:24:42 +02:00

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 <8781699+amacado@users.noreply.github.com>
Co-authored-by: David Leal <halfpacho@gmail.com>

* Add better logging to icomoon_build

Co-authored-by: Clemens Bastian <8781699+amacado@users.noreply.github.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
Thomas Bui
2021-06-13 06:17:13 -07:00
committed by GitHub
parent 8d617d7787
commit d60b334fa3
8 changed files with 248 additions and 116 deletions

View File

@@ -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

View File

@@ -33,6 +33,10 @@ def get_selenium_runner_args(peek_mode=False):
help="The download destination of the Icomoon files",
action=PathResolverAction)
parser.add_argument("token",
help="The GitHub token to access the GitHub REST API.",
type=str)
if peek_mode:
parser.add_argument("--pr_title",
help="The title of the PR that we are peeking at")

View File

@@ -1,4 +1,6 @@
import os
import re
from typing import List
import platform
import sys
import traceback
@@ -41,4 +43,22 @@ def set_env_var(key: str, value: str, delimiter: str='~'):
else:
os.system(f'echo "{key}={value}" >> $GITHUB_ENV')
else:
raise Exception("This function doesn't support this platform: " + platform.system())
raise Exception("This function doesn't support this platform: " + platform.system())
def find_object_added_in_this_pr(icons: List[dict], pr_title: str):
"""
Find the icon name from the PR title.
:param icons, a list of the font objects found in the devicon.json.
:pr_title, the title of the PR that this workflow was called on.
:return a dictionary with the "name"
entry's value matching the name in the pr_title.
:raise If no object can be found, raise an Exception.
"""
try:
pattern = re.compile(r"(?<=^new icon: )\w+ (?=\(.+\))", re.I)
icon_name = pattern.findall(pr_title)[0].lower().strip() # should only have one match
icon = [icon for icon in icons if icon["name"] == icon_name][0]
return icon
except IndexError: # there are no match in the findall()
raise Exception("Couldn't find an icon matching the name in the PR title.")