@@ -22,11 +22,11 @@ def main():
2222 logfile = open ("log.txt" , "w" )
2323 try :
2424 args = arg_getters .get_selenium_runner_args ()
25- new_icons = get_icons_for_building (args .icomoon_json_path , args . devicon_json_path , args .token , logfile )
25+ new_icons = get_icons_for_building (args .devicon_json_path , args .changed_files )
2626 if len (new_icons ) == 0 :
2727 sys .exit ("No files need to be uploaded. Ending script..." )
2828
29- print (f"There are { len (new_icons )} icons to be build. Here are they:" , * new_icons , sep = "\n " , file = logfile )
29+ print (f"There are { len (new_icons )} icons to be build. Here are they:" , * new_icons , sep = "\n " , file = logfile )
3030
3131 print ("Begin optimizing files..." , file = logfile )
3232 optimize_svgs (new_icons , args .icons_folder_path , logfile = logfile )
@@ -39,7 +39,7 @@ def main():
3939 new_icons , args .icons_folder_path , icon_versions_only = True )
4040 zip_name = "devicon-v1.0.zip"
4141 zip_path = Path (args .download_path , zip_name )
42- screenshot_folder = filehandler .create_screenshot_folder ("./" )
42+ screenshot_folder = filehandler .create_screenshot_folder ("./" )
4343
4444 runner = BuildSeleniumRunner (args .download_path ,
4545 args .geckodriver_path , args .headless , log_output = logfile )
@@ -65,43 +65,24 @@ def main():
6565 finally :
6666 print ("Exiting" , file = logfile )
6767 if runner is not None :
68- runner .close ()
68+ runner .close ()
6969 logfile .close ()
7070
7171
72- def get_icons_for_building (icomoon_json_path : str , devicon_json_path : str , token : str , logfile : FileIO ) :
72+ def get_icons_for_building (devicon_json_path : str , changed_files : List [ str ]) -> List [ dict ] :
7373 """
7474 Get the icons for building.
75- :param icomoon_json_path - the path to the `icomoon.json`.
7675 :param devicon_json_path - the path to the `devicon.json`.
77- :param token - the token to access the GitHub API .
78- :param logfile.
79- :return a list of dict containing info on the icons. These are
76+ :param changed_files - the list of changed files since the last release/tag .
77+
78+ :return a list of dict containing info on the icons. These are
8079 from the `devicon.json`.
8180 """
8281 devicon_json = filehandler .get_json_file_content (devicon_json_path )
83- pull_reqs = api_handler .get_merged_pull_reqs_since_last_release (token , logfile )
84- new_icons = []
85-
86- for pull_req in pull_reqs :
87- if api_handler .is_feature_icon (pull_req ):
88- filtered_icon = util .find_object_added_in_pr (devicon_json , pull_req ["title" ])
89- if filtered_icon not in new_icons :
90- new_icons .append (filtered_icon )
91-
92- # get any icons that might not have been found by the API
93- # sometimes happen due to the PR being opened before the latest build release
94- new_icons_from_devicon_json = filehandler .find_new_icons_in_devicon_json (
95- devicon_json_path , icomoon_json_path )
82+ return util .find_changed_icons (devicon_json , changed_files )
9683
97- for icon in new_icons_from_devicon_json :
98- if icon not in new_icons :
99- new_icons .append (icon )
10084
101- return new_icons
102-
103-
104- def optimize_svgs (new_icons : List [str ], icons_folder_path : str , logfile : FileIO ):
85+ def optimize_svgs (new_icons : List [dict ], icons_folder_path : str , logfile : FileIO ):
10586 """
10687 Optimize the newly added svgs. This is done in batches
10788 since the command line has a limit on characters allowed.
@@ -118,7 +99,7 @@ def optimize_svgs(new_icons: List[str], icons_folder_path: str, logfile: FileIO)
11899 subprocess .run (["npm" , "run" , "optimize-svg" , "--" , f"--svgFiles={ json .dumps (batch )} " ], shell = True )
119100
120101
121- def update_icomoon_json (new_icons : List [str ], icomoon_json_path : str , logfile : FileIO ):
102+ def update_icomoon_json (new_icons : List [dict ], icomoon_json_path : str , logfile : FileIO ):
122103 """
123104 Update the `icomoon.json` if it contains any icons
124105 that needed to be updated. This will remove the icons
@@ -129,23 +110,23 @@ def update_icomoon_json(new_icons: List[str], icomoon_json_path: str, logfile: F
129110 cur_len = len (icomoon_json ["icons" ])
130111 messages = []
131112
132- wrapper_function = lambda icomoon_icon : find_icomoon_icon_not_in_new_icons (
113+ wrapper_function = lambda icomoon_icon : find_icomoon_icon_not_in_new_icons (
133114 icomoon_icon , new_icons , messages )
134115 icons_to_keep = filter (wrapper_function , icomoon_json ["icons" ])
135116 icomoon_json ["icons" ] = list (icons_to_keep )
136117
137118 new_len = len (icomoon_json ["icons" ])
138119 print (f"Update completed. Removed { cur_len - new_len } icons:" , * messages , sep = '\n ' , file = logfile )
139120 filehandler .write_to_file (icomoon_json_path , json .dumps (icomoon_json ))
140-
121+
141122
142123def find_icomoon_icon_not_in_new_icons (icomoon_icon : Dict , new_icons : List , messages : List ):
143124 """
144125 Find all the icomoon icons that are not listed in the new icons.
145126 This also add logging for which icons were removed.
146127 :param icomoon_icon - a dict object from the icomoon.json's `icons` attribute.
147128 :param new_icons - a list of new icons. Each element is an object from the `devicon.json`.
148- :param messages - an empty list where the function can attach logging on which
129+ :param messages - an empty list where the function can attach logging on which
149130 icon were removed.
150131 """
151132 for new_icon in new_icons :
@@ -182,7 +163,7 @@ def get_release_message(token, logfile: FileIO):
182163 thankYou = "A huge thanks to all our maintainers and contributors for making this release possible!"
183164 iconTitle = f"**{ len (newIcons )} New Icons**"
184165 featureTitle = f"**{ len (features )} New Features**"
185- finalString = "{0}\n \n {1}\n {2}\n \n {3}\n {4}" .format (thankYou ,
166+ finalString = "{0}\n \n {1}\n {2}\n \n {3}\n {4}" .format (thankYou ,
186167 iconTitle , "\n " .join (newIcons ),
187168 featureTitle , "\n " .join (features ))
188169
0 commit comments