forked from devicons/devicon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request devicons#412 from devicons/TB_peekUpgrade
Make the peek script (bot:peek) take screenshot of individual files
- Loading branch information
Showing
9 changed files
with
193 additions
and
58 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
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,10 @@ | ||
import json | ||
import os | ||
|
||
|
||
if __name__ == "__main__": | ||
img_urls_list = json.loads(os.environ["IMG_URLS"]) | ||
template = "![Detailed Screenshot]({})" | ||
markdown = [template.format(img_url) for img_url in img_urls_list] | ||
print("\n\n".join(markdown)) | ||
|
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,33 +1,66 @@ | ||
from typing import List | ||
import re | ||
import sys | ||
from selenium.common.exceptions import TimeoutException | ||
|
||
# pycharm complains that build_assets is an unresolved ref | ||
# don't worry about it, the script still runs | ||
from build_assets.SeleniumRunner import SeleniumRunner | ||
from build_assets import filehandler, util | ||
from build_assets import filehandler, arg_getters | ||
|
||
|
||
def main(): | ||
args = util.get_commandline_args() | ||
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: | ||
print("No files need to be uploaded. Ending script...") | ||
return | ||
sys.exit("No files need to be uploaded. Ending script...") | ||
|
||
if len(filtered_icons) == 0: | ||
message = "No icons found matching the icon name in the PR's title.\n" \ | ||
"Ensure that 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) | ||
|
||
# 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') | ||
|
||
runner = None | ||
try: | ||
runner = SeleniumRunner(args.download_path, args.geckodriver_path, args.headless) | ||
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path) | ||
runner.upload_svgs(svgs) | ||
svgs = filehandler.get_svgs_paths(filtered_icons, args.icons_folder_path) | ||
screenshot_folder = filehandler.create_screenshot_folder("./") | ||
runner.upload_svgs(svgs, screenshot_folder) | ||
print("Task completed.") | ||
except TimeoutException as e: | ||
print("Selenium Time Out Error: ", e.stacktrace, sep='\n') | ||
except Exception as e: | ||
print(e) | ||
print(e.stacktrace) | ||
finally: | ||
runner.close() | ||
|
||
|
||
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 list containing the dictionary with the "name" | ||
entry's value matching the name in the pr_title. | ||
If none can be found, return an empty list. | ||
""" | ||
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] | ||
except IndexError: # there are no match in the findall() | ||
return [] | ||
|
||
|
||
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.