@@ -57,17 +57,22 @@ def extend_parser(
57
57
parser_actions = subparsers .add_parser (
58
58
"actions" , help = "!!BETA!!\n Add or Update Actions in the pre-approved list."
59
59
)
60
- parser_actions .add_argument (
61
- "-o" , "--output" , action = "store" , default = "actions.json"
62
- )
63
60
subparsers_actions = parser_actions .add_subparsers (
64
61
required = True , dest = "actions_command"
65
62
)
66
- subparsers_actions .add_parser ("update" , help = "update action versions" )
63
+ parser_actions_update = subparsers_actions .add_parser (
64
+ "update" , help = "update action versions"
65
+ )
66
+ parser_actions_update .add_argument (
67
+ "-o" , "--output" , action = "store" , default = "actions.json" , help = "output file"
68
+ )
67
69
parser_actions_add = subparsers_actions .add_parser (
68
70
"add" , help = "add action to approved list"
69
71
)
70
72
parser_actions_add .add_argument ("name" , help = "action name [git owner/repo]" )
73
+ parser_actions_add .add_argument (
74
+ "-o" , "--output" , action = "store" , default = "actions.json" , help = "output file"
75
+ )
71
76
72
77
return subparsers
73
78
@@ -127,29 +132,38 @@ def get_latest_version(self, action: Action) -> Action | None:
127
132
f"https://api.github.com/repos/{ action .name } /releases/latest" ,
128
133
action .name ,
129
134
)
130
- if not response :
131
- return None
135
+ if response is not None and response . status != 404 :
136
+ tag_name = json . loads ( response . data )[ "tag_name" ]
132
137
133
- tag_name = json .loads (response .data )["tag_name" ]
138
+ # Get the URL to the commit for the tag
139
+ response = self .get_github_api_response (
140
+ f"https://api.github.com/repos/{ action .name } /git/ref/tags/{ tag_name } " ,
141
+ action .name ,
142
+ )
134
143
135
- # Get the URL to the commit for the tag
136
- response = self .get_github_api_response (
137
- f"https://api.github.com/repos/{ action .name } /git/ref/tags/{ tag_name } " ,
138
- action .name ,
139
- )
140
- if not response :
141
- return None
144
+ if response is None or response .status != 200 :
145
+ return None
146
+
147
+ if json .loads (response .data )["object" ]["type" ] != "commit" :
148
+ url = json .loads (response .data )["object" ]["url" ]
149
+ # Follow the URL and get the commit sha for tags
150
+ response = self .get_github_api_response (url , action .name )
151
+ if not response :
152
+ return None
142
153
143
- if json .loads (response .data )["object" ]["type" ] == "commit" :
144
154
sha = json .loads (response .data )["object" ]["sha" ]
145
155
else :
146
- url = json .loads (response .data )["object" ]["url" ]
147
- # Follow the URL and get the commit sha for tags
148
- response = self .get_github_api_response (url , action .name )
149
- if not response :
156
+ # Get tag from latest tag
157
+ response = self .get_github_api_response (
158
+ f"https://api.github.com/repos/{ action .name } /tags" ,
159
+ action .name ,
160
+ )
161
+
162
+ if response is None or response .status != 200 :
150
163
return None
151
164
152
- sha = json .loads (response .data )["object" ]["sha" ]
165
+ sha = json .loads (response .data )[0 ]["commit" ]["sha" ]
166
+ tag_name = json .loads (response .data )[0 ]["name" ]
153
167
except KeyError as err :
154
168
raise GitHubApiSchemaError (
155
169
f"Error with the GitHub API Response Schema for either /releases or"
@@ -182,10 +196,20 @@ def add(self, new_action_name: str, filename: str) -> int:
182
196
updated_actions = self .settings .approved_actions
183
197
proposed_action = Action (name = new_action_name )
184
198
199
+ # Remove the action directory if the action is in a multi-actions repo
200
+ if len (new_action_name .split ("/" )) > 2 :
201
+ modified_action = "/" .join (new_action_name .split ("/" )[:- 1 ])
202
+ print (
203
+ f" - { new_action_name } \033 [{ Colors .yellow } modified\033 [0m to { modified_action } "
204
+ )
205
+ proposed_action = Action (name = modified_action )
206
+
185
207
if self .exists (proposed_action ):
186
208
latest = self .get_latest_version (proposed_action )
187
209
if latest :
188
210
updated_actions [latest .name ] = latest
211
+ else :
212
+ print (f" - { new_action_name } \033 [{ Colors .red } not found\033 [0m" )
189
213
190
214
self .save_actions (updated_actions , filename )
191
215
return 0
0 commit comments