def get_icons_for_building(icomoon_json_path: str, devicon_json_path: str, token: str, logfile: FileIO): """ Get the icons for building. :param icomoon_json_path - the path to the `icomoon.json`. :param devicon_json_path - the path to the `devicon.json`. :param token - the token to access the GitHub API. :param logfile. :return a list of dict containing info on the icons. These are from the `devicon.json`. """ devicon_json = filehandler.get_json_file_content(devicon_json_path) pull_reqs = api_handler.get_merged_pull_reqs_since_last_release(token, logfile) new_icons = [] for pull_req in pull_reqs: if api_handler.is_feature_icon(pull_req): filtered_icon = util.find_object_added_in_pr(devicon_json, pull_req["title"]) if filtered_icon not in new_icons: new_icons.append(filtered_icon) # get any icons that might not have been found by the API # sometimes happen due to the PR being opened before the latest build release new_icons_from_devicon_json = filehandler.find_new_icons_in_devicon_json( devicon_json_path, icomoon_json_path) for icon in new_icons_from_devicon_json: if icon not in new_icons: new_icons.append(icon) return new_icons
def main(): runner = None try: args = arg_getters.get_selenium_runner_args(peek_mode=True) all_icons = filehandler.get_json_file_content(args.devicon_json_path) # get only the icon object that has the name matching the pr title filtered_icon = util.find_object_added_in_pr(all_icons, args.pr_title) check_devicon_object(filtered_icon) print("Icon being checked:", filtered_icon, sep="\n", end='\n\n') runner = PeekSeleniumRunner(args.download_path, args.geckodriver_path, args.headless) svgs = filehandler.get_svgs_paths([filtered_icon], args.icons_folder_path, True) screenshot_folder = filehandler.create_screenshot_folder("./") svgs_with_strokes = runner.peek(svgs, screenshot_folder, filtered_icon) print("Task completed.") message = "" if svgs_with_strokes != []: svgs_str = "\n\n".join(svgs_with_strokes) message = "\n### WARNING -- Strokes detected in the following SVGs:\n" + svgs_str + "\n" filehandler.write_to_file("./err_messages.txt", message) except Exception as e: filehandler.write_to_file("./err_messages.txt", str(e)) util.exit_with_err(e) finally: if runner is not None: runner.close()
def main(): runner = None try: args = arg_getters.get_selenium_runner_args(True) new_icons = filehandler.get_json_file_content(args.devicon_json_path) # get only the icon object that has the name matching the pr title filtered_icon = util.find_object_added_in_this_pr( new_icons, args.pr_title) check_devicon_object(filtered_icon) print("Icon being checked:", filtered_icon, sep="\n", end='\n\n') runner = SeleniumRunner(args.download_path, args.geckodriver_path, args.headless) 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.") # 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 main(): """ Check the quality of the svgs of the whole icons folder. """ args = arg_getters.get_check_svgs_monthly_args() try: devicon_json = filehandler.get_json_file_content( args.devicon_json_path) svgs = filehandler.get_svgs_paths(devicon_json, args.icons_folder_path) util.check_svgs(svgs) print("All SVGs found were good. Task completed.") except Exception as e: util.exit_with_err(e)
def main(): """ Check the quality of the svgs IF this is an icon PR. Else, does nothing. If any svg error is found, create a json file called 'svg_err_messages.json' in the root folder that will contains the error messages. """ args = arg_getters.get_check_icon_pr_args() try: all_icons = filehandler.get_json_file_content(args.devicon_json_path) # get only the icon object that has the name matching the pr title filtered_icon = util.find_object_added_in_pr(all_icons, args.pr_title) print("Checking devicon.json object: " + str(filtered_icon)) devicon_err_msg = check_devicon_object(filtered_icon) # check the file names filename_err_msg = "" svgs = None try: svgs = filehandler.get_svgs_paths([filtered_icon], args.icons_folder_path, as_str=False) print("SVGs to check: ", *svgs, sep='\n') except ValueError as e: filename_err_msg = "Error found regarding filenames:\n- " + e.args[ 0] # check the svgs if svgs is None or len(svgs) == 0: print("No SVGs to check, ending script.") svg_err_msg = "Error checking SVGs: no SVGs to check. Might be caused by above issues." else: svg_err_msg = check_svgs(svgs) err_msg = [] if devicon_err_msg != "": err_msg.append(devicon_err_msg) if filename_err_msg != "": err_msg.append(filename_err_msg) if svg_err_msg != "": err_msg.append(svg_err_msg) filehandler.write_to_file("./err_messages.txt", "\n\n".join(err_msg)) print("Task completed.") except Exception as e: filehandler.write_to_file("./err_messages.txt", str(e)) util.exit_with_err(e)
def get_icons_for_building(devicon_json_path: str, token: str): """ Get the icons for building. :param devicon_json_path - the path to the `devicon.json`. :param token - the token to access the GitHub API. """ all_icons = filehandler.get_json_file_content(devicon_json_path) pull_reqs = api_handler.get_merged_pull_reqs_since_last_release(token) new_icons = [] for pull_req in pull_reqs: if api_handler.is_feature_icon(pull_req): filtered_icon = util.find_object_added_in_this_pr( all_icons, pull_req["title"]) if filtered_icon not in new_icons: new_icons.append(filtered_icon) return new_icons
def update_icomoon_json(new_icons: List[str], icomoon_json_path: str, logfile: FileIO): """ Update the `icomoon.json` if it contains any icons that needed to be updated. This will remove the icons from the `icomoon.json` so the build script will reupload it later. """ icomoon_json = filehandler.get_json_file_content(icomoon_json_path) cur_len = len(icomoon_json["icons"]) messages = [] wrapper_function = lambda icomoon_icon : find_icomoon_icon_not_in_new_icons( icomoon_icon, new_icons, messages) icons_to_keep = filter(wrapper_function, icomoon_json["icons"]) icomoon_json["icons"] = list(icons_to_keep) new_len = len(icomoon_json["icons"]) print(f"Update completed. Removed {cur_len - new_len} icons:", *messages, sep='\n', file=logfile) filehandler.write_to_file(icomoon_json_path, json.dumps(icomoon_json))