Skip to content

Commit

Permalink
chore: add change to allow for shared resources
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelorenzo committed Oct 22, 2024
1 parent ec8612f commit 8116a02
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 90 deletions.
4 changes: 0 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ name: 'Sync Action Status'
description: 'Sync a GitHub Action status from a repository_dispatch event'
author: "Philip De Lorenzo"
inputs:
#is_org: # Whether the repository is an organization
# description: 'Whether the repository is an organization'
# required: true
# default: "false"
gh_token: # The GitHub token to use for access to the API
description: 'Your GitHub token'
required: true
Expand Down
55 changes: 2 additions & 53 deletions src/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from icecream import ic # We will use icecream to print out the job information
from datetime import datetime, timezone
from shared import get_workflow_data, get_workflow_id

BASE = os.path.dirname(os.path.abspath(__file__)) # Get the base directory of the script
WORKDIR = os.environ.get("WORKDIR") # Get the workflows directory
Expand All @@ -33,6 +34,7 @@ def get_repos(api: Github) -> list:

return repos


def get_repository_dispatch(args: argparse.ArgumentParser.parse_args) -> str:
"""This function will return the repository dispatch URL for the repository passed in as an argument.
Expand All @@ -45,59 +47,6 @@ def get_repository_dispatch(args: argparse.ArgumentParser.parse_args) -> str:
return f"https://github.com/{args.target_repo}"


def get_workflow_data(repo: str) -> list[dict]:
"""This function will return the deployment workflows for the SRE Deployments Repo -- @manscaped-dev/manscaped-sre-deployments.
Args:
repo (str): The repository to get the workflow data from.
Returns:
lists: The deployment workflows for the SRE Deployments Repo -- @manscaped-dev/manscaped-sre-deploy
For example:
[
{
"name": "workflow-name",
"id": "workflow-id",
"path": "workflow-path"
},
...
]
"""
# Let's get a JSON objects of the name, id of the workflows
_cmd = [
"gh",
"workflow",
"list",
"--repo",
repo,
'--json=name,id,path,state',
]

return json.loads(subprocess.check_output(_cmd).decode("utf-8").strip())


def get_workflow_id(_name: str, repo: str) -> int:
"""This function will return the id of the workflow passed in as an argument.
Returns:
int: The id of the workflow passed in as an argument.
"""
workflow_data = get_workflow_data(repo=repo) # Let's get a list of the workflows in the repos

id = [i["id"] for i in workflow_data if i["name"] == _name][0] # This will return the id of the workflow, if the name passed in matches one of these

if not id:
print(f"Workflow with name {_name} not found.")
sys.exit(5)

if not isinstance(id, int):
print(f"Workflow ID must be an integer. Got {id} instead.")
sys.exit(5)

return id


def get_event_type_list_for_workflows(repo: str) -> dict[str, list[str]]:
"""This function will return the event triggers for the workflows.
Expand Down
34 changes: 1 addition & 33 deletions src/gh_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from github import Auth

from icecream import ic # We will use icecream to print out the job information
from shared import get_workflow_data
#from datetime import datetime, timezone, UTC

BASE = os.path.dirname(os.path.abspath(__file__)) # Get the base directory of the script
Expand Down Expand Up @@ -43,36 +44,3 @@ def get_repos(api: Github) -> list:
repos.append(repo)

return repos


def get_workflow_data(repo: str) -> list[dict]:
"""This function will return the deployment workflows for the SRE Deployments Repo -- @manscaped-dev/manscaped-sre-deployments.
Args:
repo (str): The repository to get the workflow data from.
Returns:
lists: The deployment workflows for the SRE Deployments Repo -- @manscaped-dev/manscaped-sre-deploy
For example:
[
{
"name": "workflow-name",
"id": "workflow-id",
"path": "workflow-path"
},
...
]
"""
# Let's get a JSON objects of the name, id of the workflows
_cmd = [
"gh",
"workflow",
"list",
"--repo",
repo,
'--json=name,id,path,state',
]

return json.loads(subprocess.check_output(_cmd).decode("utf-8").strip())

0 comments on commit 8116a02

Please sign in to comment.