Skip to content

Commit

Permalink
[BRE-443] - Fix bwwl Linting pre Deployment - work on the bwwl action…
Browse files Browse the repository at this point in the history
… sub command (#36)

* activate approved actions

* [BRE-443] - Fix bwwl Linting pre Deployment - work on the bwwl action sub command

Co-authored-by: Andy Pixley <[email protected]>

* use regex to escape matrix in name

---------

Co-authored-by: Andy Pixley <[email protected]>
  • Loading branch information
Eeebru and pixman20 authored Dec 17, 2024
1 parent 3c98908 commit f0997dc
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 146 deletions.
64 changes: 44 additions & 20 deletions src/bitwarden_workflow_linter/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,22 @@ def extend_parser(
parser_actions = subparsers.add_parser(
"actions", help="!!BETA!!\nAdd or Update Actions in the pre-approved list."
)
parser_actions.add_argument(
"-o", "--output", action="store", default="actions.json"
)
subparsers_actions = parser_actions.add_subparsers(
required=True, dest="actions_command"
)
subparsers_actions.add_parser("update", help="update action versions")
parser_actions_update = subparsers_actions.add_parser(
"update", help="update action versions"
)
parser_actions_update.add_argument(
"-o", "--output", action="store", default="actions.json", help="output file"
)
parser_actions_add = subparsers_actions.add_parser(
"add", help="add action to approved list"
)
parser_actions_add.add_argument("name", help="action name [git owner/repo]")
parser_actions_add.add_argument(
"-o", "--output", action="store", default="actions.json", help="output file"
)

return subparsers

Expand Down Expand Up @@ -127,29 +132,38 @@ def get_latest_version(self, action: Action) -> Action | None:
f"https://api.github.com/repos/{action.name}/releases/latest",
action.name,
)
if not response:
return None
if response is not None and response.status != 404:
tag_name = json.loads(response.data)["tag_name"]

tag_name = json.loads(response.data)["tag_name"]
# Get the URL to the commit for the tag
response = self.get_github_api_response(
f"https://api.github.com/repos/{action.name}/git/ref/tags/{tag_name}",
action.name,
)

# Get the URL to the commit for the tag
response = self.get_github_api_response(
f"https://api.github.com/repos/{action.name}/git/ref/tags/{tag_name}",
action.name,
)
if not response:
return None
if response is None or response.status != 200:
return None

if json.loads(response.data)["object"]["type"] != "commit":
url = json.loads(response.data)["object"]["url"]
# Follow the URL and get the commit sha for tags
response = self.get_github_api_response(url, action.name)
if not response:
return None

if json.loads(response.data)["object"]["type"] == "commit":
sha = json.loads(response.data)["object"]["sha"]
else:
url = json.loads(response.data)["object"]["url"]
# Follow the URL and get the commit sha for tags
response = self.get_github_api_response(url, action.name)
if not response:
# Get tag from latest tag
response = self.get_github_api_response(
f"https://api.github.com/repos/{action.name}/tags",
action.name,
)

if response is None or response.status != 200:
return None

sha = json.loads(response.data)["object"]["sha"]
sha = json.loads(response.data)[0]["commit"]["sha"]
tag_name = json.loads(response.data)[0]["name"]
except KeyError as err:
raise GitHubApiSchemaError(
f"Error with the GitHub API Response Schema for either /releases or"
Expand Down Expand Up @@ -182,10 +196,20 @@ def add(self, new_action_name: str, filename: str) -> int:
updated_actions = self.settings.approved_actions
proposed_action = Action(name=new_action_name)

# Remove the action directory if the action is in a multi-actions repo
if len(new_action_name.split("/")) > 2:
modified_action = "/".join(new_action_name.split("/")[:-1])
print(
f" - {new_action_name} \033[{Colors.yellow}modified\033[0m to {modified_action}"
)
proposed_action = Action(name=modified_action)

if self.exists(proposed_action):
latest = self.get_latest_version(proposed_action)
if latest:
updated_actions[latest.name] = latest
else:
print(f" - {new_action_name} \033[{Colors.red}not found\033[0m")

self.save_actions(updated_actions, filename)
return 0
Expand Down
Loading

0 comments on commit f0997dc

Please sign in to comment.