Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script upgrades and updated CONTRIBUTING.md and README.md #576

Merged
merged 24 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
84ad016
Updated README and CONTRIBUTING
Thomas-Boi Apr 24, 2021
df35733
Added check for devicon object when peeking
Thomas-Boi Apr 24, 2021
330fcd4
Added PR template
Thomas-Boi Apr 24, 2021
035cbf1
Added a script to create release messages
Thomas-Boi Apr 26, 2021
2e9c01f
Updated CONTRIBUTING about new script
Thomas-Boi Apr 26, 2021
f8d931d
Update .github/PULL_REQUEST_TEMPLATE/new_icon.md
Thomas-Boi Apr 26, 2021
086fa4a
Update .github/scripts/build_assets/arg_getters.py
Thomas-Boi Apr 26, 2021
056fc89
Update .github/workflows/get_release_message.yml
Thomas-Boi Apr 26, 2021
738e69b
Update gulpfile.js
Thomas-Boi Apr 26, 2021
6c029ea
Update .github/PULL_REQUEST_TEMPLATE/new_feature.md
Thomas-Boi Apr 26, 2021
a07cb17
Update .github/PULL_REQUEST_TEMPLATE/new_feature.md
Thomas-Boi Apr 26, 2021
a563506
Added a way for peek bot to comment error
Thomas-Boi Apr 26, 2021
1015ae1
Merge branch 'thomas/feature/variousUpgrades' of https://github.com/d…
Thomas-Boi Apr 26, 2021
a7f967f
Merge branch 'develop' into thomas/feature/variousUpgrades
Panquesito7 Apr 27, 2021
e622923
Update CONTRIBUTING.md
Thomas-Boi Apr 27, 2021
1905ac9
Update .github/scripts/get_release_message.py
Thomas-Boi Apr 27, 2021
a398068
Update .github/scripts/get_release_message.py
Thomas-Boi Apr 27, 2021
2a3ee3a
Update .github/PULL_REQUEST_TEMPLATE/new_feature.md
Thomas-Boi Apr 27, 2021
fb3fc67
Clean up and updated CONTRIBUTING
Thomas-Boi Apr 28, 2021
b85ba90
Updated CONTRIBUTING
Thomas-Boi Apr 28, 2021
9b6847a
Add set up steps for release message workflow
Thomas-Boi Apr 28, 2021
52fa4c4
Refactored peek workflow
Thomas-Boi Apr 28, 2021
ea662d3
Added requests library
Thomas-Boi Apr 28, 2021
001b136
Reformat devicon object error messages
Thomas-Boi Apr 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/new_feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## This PR adds...

*List your features here and their reasons for creation.*

## Notes

*List anything note-worthy here (potential issues, this needs merge to `master` before working etc....)*
Thomas-Boi marked this conversation as resolved.
Show resolved Hide resolved

*Don't forget to link any issues that this PR will solved.*
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/new_icon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**Double check these details before you open a PR**

- [] PR does not match another non-stale PR currently opened
- [] PR name matches the format *new icon: <i>Icon name</i> (<i>versions separated by comma</i>)* as seen [here](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#overview)
- [] Your icons are put in a folder as seen [here](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#organizational-guidelines)
- [] SVG matches the standards laid out [here](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#svgStandards)
- [] A new object is added in the `devicon.json` file as seen [here](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#-updating-the-deviconjson-)

Refer to the [`CONTRIBUTING.md`](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#contributing-to-devicon) for more details.
37 changes: 0 additions & 37 deletions .github/drafts/check_devicon_object.py

This file was deleted.

13 changes: 12 additions & 1 deletion .github/scripts/build_assets/arg_getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,15 @@ def get_check_svgs_monthly_args():
parser.add_argument("icons_folder_path",
help="The path to the icons folder",
action=PathResolverAction)
return parser.parse_args()
return parser.parse_args()


def get_release_message_args():
"""
Get the commandline arguments for the check_svgs_monthly.py.
Thomas-Boi marked this conversation as resolved.
Show resolved Hide resolved
"""
parser = ArgumentParser(description="Create a text containing the icons and features added since last release.")
parser.add_argument("token",
help="The GitHub token to access the GitHub REST API.",
type=str)
return parser.parse_args()
75 changes: 75 additions & 0 deletions .github/scripts/get_release_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import requests
from build_assets import arg_getters
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}")
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))


if __name__ == "__main__":
main()
110 changes: 84 additions & 26 deletions .github/scripts/icomoon_peek.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import sys
from selenium.common.exceptions import TimeoutException
import xml.etree.ElementTree as et

# pycharm complains that build_assets is an unresolved ref
# don't worry about it, the script still runs
Expand All @@ -12,59 +11,118 @@


def main():
args = arg_getters.get_selenium_runner_args(True)
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)
runner = None
try:
args = arg_getters.get_selenium_runner_args(True)
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)

# get only the icon object that has the name matching the pr title
filtered_icons = find_object_added_in_this_pr(new_icons, args.pr_title)
if len(new_icons) == 0:
raise Exception("No files need to be uploaded. Ending script...")

if len(new_icons) == 0:
sys.exit("No files need to be uploaded. Ending script...")
# get only the icon object that has the name matching the pr title
err_messages = []
filtered_icon = find_object_added_in_this_pr(new_icons, args.pr_title, err_messages)

if len(filtered_icons) == 0:
message = "No icons found matching the icon name in the PR's title.\n" \
"Ensure that a new icon entry is added in the devicon.json and the PR title matches the convention here: \n" \
"https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#overview\n" \
"Ending script...\n"
sys.exit(message)
if filtered_icon is None:
# should have 1 error message if filtered_icon is None
raise Exception(err_messages[0])

# print list of new icons
print("List of new icons:", *new_icons, sep = "\n")
print("Icons being uploaded:", *filtered_icons, sep = "\n", end='\n\n')
print("Icon being checked:", filtered_icon, sep = "\n", end='\n\n')

runner = None
try:
runner = SeleniumRunner(args.download_path, args.geckodriver_path, args.headless)
svgs = filehandler.get_svgs_paths(filtered_icons, args.icons_folder_path, True)
svgs = filehandler.get_svgs_paths([filtered_icon], args.icons_folder_path, True)
screenshot_folder = filehandler.create_screenshot_folder("./")
runner.upload_svgs(svgs, screenshot_folder)
print("Task completed.")
except TimeoutException as e:
util.exit_with_err("Selenium Time Out Error: \n" + str(e))

# no errors, do this so upload-artifact won't fail
filehandler.write_to_file("./err_messages.txt", "0")
except Exception as e:
filehandler.write_to_file("./err_messages.txt", str(e))
util.exit_with_err(e)
finally:
runner.close()


def find_object_added_in_this_pr(icons: List[dict], pr_title: str):
def find_object_added_in_this_pr(icons: List[dict], pr_title: str, err_messages: List[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 list containing the dictionary with the "name"
:param err_messages, the error messages that will be displayed
:return a dictionary with the "name"
entry's value matching the name in the pr_title.
If none can be found, return an empty list.
If none can be found, return None.
"""
try:
pattern = re.compile(r"(?<=^new icon: )\w+ (?=\(.+\))", re.I)
icon_name = pattern.findall(pr_title)[0].lower().strip() # should only have one match
return [icon for icon in icons if icon["name"] == icon_name]
icon = [icon for icon in icons if icon["name"] == icon_name][0]
check_devicon_object(icon, icon_name)
return icon
except IndexError: # there are no match in the findall()
return []
err_messages.append("Couldn't find an icon matching the name in the PR title.")
return None
except ValueError as e:
err_messages.append(str(e))
return None


def check_devicon_object(icon: dict, icon_name: str):
"""
Check that the devicon object added is up to standard.
:return a string containing the error messages if any.
"""
err_msgs = []
try:
if type(icon["name"]) != icon_name:
err_msgs.append("'name' value is not: " + icon_name)
except KeyError:
err_msgs.append("Missing key: 'name'.")

try:
for tag in icon["tags"]:
if type(tag) != str:
raise TypeError()
except TypeError:
err_msgs.append("'tags' must be an array of strings, not: " + str(icon["tags"]))
except KeyError:
err_msgs.append("Missing key: 'tags'.")

try:
if type(icon["versions"]) != dict:
err_msgs.append("'versions' must be an object.")
except KeyError:
err_msgs.append("Missing key: 'versions'.")

try:
if type(icon["versions"]["svg"]) != list or len(icon["versions"]["svg"]) == 0:
err_msgs.append("Must contain at least 1 svg version in a list.")
except KeyError:
err_msgs.append("Missing key: 'svg' in 'versions'.")

try:
if type(icon["versions"]["font"]) != list or len(icon["versions"]["svg"]) == 0:
err_msgs.append("Must contain at least 1 font version in a list.")
except KeyError:
err_msgs.append("Missing key: 'font' in 'versions'.")

try:
if type(icon["color"]) != str or "#" not in icon["color"]:
err_msgs.append("'color' must be a string in the format '#abcdef'")
except KeyError:
err_msgs.append("Missing key: 'color'.")

try:
if type(icon["aliases"]) != list:
err_msgs.append("'aliases' must be an array.")
except KeyError:
err_msgs.append("Missing key: 'aliases'.")

if len(err_msgs) > 0:
message = "Error found in 'devicon.json' for '{}' entry: \n{}\n".format(icon_name, "\n".join(err_msgs))
raise ValueError(message)
return ""

if __name__ == "__main__":
main()
11 changes: 11 additions & 0 deletions .github/workflows/get_release_message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Get Release Message
on: workflow_dispatch
jobs:
build:
name: Get Fonts From Icomoon
runs-on: ubuntu-18.04
steps:
- name: Run the get_release_message.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python ./.github/scripts/get_release_message.py $GITHUB_TOKEN
7 changes: 7 additions & 0 deletions .github/workflows/peek_icons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ jobs:
./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json
./devicon.json ./icons ./ --headless --pr_title "%PR_TITLE%"

- name: Upload the err messages (created by icomoon_peek.py)
uses: actions/upload-artifact@v2
if: success()
with:
name: err_messages
path: ./err_messages.txt

- name: Upload screenshots for comments
uses: actions/upload-artifact@v2
if: success()
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/post_peek_screenshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ jobs:
with:
path: ./pr_num/pr_num.txt

- name: Read the err message file
if: success()
id: err_message_reader
uses: juliangruber/read-file-action@v1.0.0
with:
path: ./err_messages/err_messages.txt


- name: Upload screenshot of the newly made icons gotten from the artifacts
id: icons_overview_img_step
if: env.PEEK_STATUS == 'success' && success()
Expand Down Expand Up @@ -87,20 +95,24 @@ jobs:
MESSAGE: |
Hi there,

I'm Devicons' Peek Bot and it seems we've ran into a problem (sorry!).
I'm Devicons' Peek Bot and it seems we've ran into a problem.

```
{0}
```

Please double check and fix the possible issues below:
Make sure that:

- Your svgs are named and added correctly to the /icons folder as seen [here](https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#orgGuidelines).
- Your icon information has been added to the `devicon.json` as seen [here](https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#updateDevicon)
- Your PR title follows the format seen [here](https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#overview)

I will retry once everything is fixed. If I still fail (sorry!) or there are other erros, the maintainers will investigate.
I will retry once everything is fixed. If I still fail or there are other error, the maintainers will investigate.

Best of luck,
Peek Bot :relaxed:
with:
type: create
issue_number: ${{ steps.pr_num_reader.outputs.content }}
token: ${{ secrets.GITHUB_TOKEN }}
body: ${{ env.MESSAGE }}
body: ${{ format(env.MESSAGE, steps.err_message_reader.outputs.content) }}