-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Make the peek script (bot:peek) take screenshot of individual files #412
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eb6884d
Added zoomed in snapshot for peek scripts
Thomas-Boi 8a5ff05
Various bug fixes and reference update
Thomas-Boi c388503
Refactored take screenshot and remove color functions
Thomas-Boi a9eb51a
Various bug fixes and added ability to comment multiple files
Thomas-Boi a84cd46
Added comments and script now fail if can't find icon name
Thomas-Boi e51fb1c
Fixed error with logging
Thomas-Boi 799878e
Update handling outputs in build_icons.yml
Thomas-Boi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 = "" | ||
markdown = [template.format(img_url) for img_url in img_urls_list] | ||
print("\n\n".join(markdown)) | ||
|
This file contains hidden or 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 hidden or 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 | ||
amacado marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.