generated from jacobtomlinson/python-container-action
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64bff62
commit 4b8c4b2
Showing
12 changed files
with
309 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
pydantic | ||
pydantic==1.9.1 | ||
actions-toolkit==0.1.13 | ||
pygithub==1.55 | ||
pyyaml==3.9.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
name: "Python Container Action Template" | ||
description: "Get started with Python Container actions" | ||
author: "Jacob Tomlinson" | ||
name: "Repo Manager" | ||
description: "Manage your Github repo(s) settings and secrets using Github Actions and a yaml file" | ||
author: "Andrew Herrington" | ||
inputs: | ||
myInput: | ||
description: "Input to use" | ||
default: "world" | ||
action: | ||
description: "What action to take with this action. One of validate, check, or apply. Validate will validate your settings file, but not touch your repo. Check will check your repo with your settings file and output a report of any drift. Apply will apply the settings in your settings file to your repo" | ||
default: "check" | ||
settings_file: | ||
description: What yaml file to use as your settings. This is local to runner running this action. | ||
default: ".github/settings.yml" | ||
repo: | ||
description: What repo to perform this action on. Default is self, as in the repo this action is running in | ||
default: "self" | ||
token: | ||
description: What github token to use with this action. | ||
required: true | ||
outputs: | ||
myOutput: | ||
description: "Output from the action" | ||
result: | ||
description: "Result of the action" | ||
runs: | ||
using: "docker" | ||
image: "Dockerfile" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import List | ||
from typing import Optional | ||
from typing import Union | ||
|
||
import yaml | ||
from pydantic import BaseModel # pylint: disable=E0611 | ||
from pydantic import Field | ||
|
||
from .branch_protection import BranchProtection | ||
from .label import Label | ||
from .secret import Secret | ||
from .settings import Settings | ||
|
||
|
||
class RepoManagerConfig(BaseModel): | ||
settings: Optional[Settings] | ||
branch_protections: Optional[List[BranchProtection]] | ||
secrets: Optional[List[Secret]] | ||
|
||
|
||
def load_config(filename: str) -> RepoManagerConfig: | ||
"""Loads a yaml file into a RepoManagerconfig""" | ||
with open(filename) as fh: | ||
this_dict = yaml.safe_load(fh) | ||
|
||
return RepoManagerConfig(**this_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from typing import List | ||
from typing import Optional | ||
from typing import Union | ||
|
||
from pydantic import BaseModel # pylint: disable=E0611 | ||
from pydantic import conint | ||
from pydantic import Field | ||
from pydantic import HttpUrl # pylint: disable=E0611 | ||
|
||
OptBool = Optional[bool] | ||
OptStr = Optional[str] | ||
|
||
|
||
class RestrictionOptions(BaseModel): | ||
apps: Optional[List[str]] = Field(None, description="List of App names that cannot push to this branch") | ||
users: Optional[List[str]] = Field( | ||
None, description="List of users who cannot push to this branch, only available to orgs" | ||
) | ||
teams: Optional[List[str]] = Field( | ||
None, description="List of teams who cannot push to this branch, only available to orgs" | ||
) | ||
|
||
|
||
class StatusChecksOptions(BaseModel): | ||
strict: OptBool = Field(None, description="Require branches to be up to date before merging.") | ||
checks: Optional[List[str]] = Field( | ||
None, description="The list of status checks to require in order to merge into this branch" | ||
) | ||
|
||
|
||
class DismissalOptions(BaseModel): | ||
users: Optional[List[str]] = Field( | ||
None, description="List of users who can dismiss pull request reviews, only available to orgs" | ||
) | ||
teams: Optional[List[str]] = Field( | ||
None, description="List of teams who can dismiss pull request reviews, only available to orgs" | ||
) | ||
|
||
|
||
class PROptions(BaseModel): | ||
required_approving_review_count: Optional[conint(ge=1, le=6)] = Field( | ||
None, description="The number of approvals required. (1-6)" | ||
) | ||
dismiss_stale_reviews: OptBool = Field( | ||
None, description="Dismiss approved reviews automatically when a new commit is pushed." | ||
) | ||
require_code_owner_reviews: OptBool = Field(None, description="Blocks merge until code owners have reviewed.") | ||
dismissal_restrictions: Optional[DismissalOptions] = Field( | ||
None, description="Options related to PR dismissal. Only available to Orgs." | ||
) | ||
|
||
|
||
class ProtectionOptions(BaseModel): | ||
required_pull_request_reviews: Optional[PROptions] = Field(None, description="Options related to PR reviews") | ||
required_status_checks: Optional[StatusChecksOptions] = Field( | ||
None, description="Options related to required status checks" | ||
) | ||
enforce_admins: OptBool = Field( | ||
None, | ||
description="Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable.", | ||
) | ||
required_linear_history: OptBool = Field( | ||
None, description="Prevent merge commits from being pushed to matching branches" | ||
) | ||
restrictions: Optional[RestrictionOptions] = Field( | ||
None, description="Options related to restricting who can push to this branch" | ||
) | ||
|
||
|
||
class BranchProtection(BaseModel): | ||
name: OptStr = Field(None, description="Name of the branch") | ||
protection: Optional[ProtectionOptions] = Field(None, description="Protection options for the branch") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import List | ||
from typing import Optional | ||
from typing import Union | ||
|
||
from pydantic import BaseModel # pylint: disable=E0611 | ||
from pydantic import Field | ||
from pydantic import HttpUrl # pylint: disable=E0611 | ||
|
||
OptBool = Optional[bool] | ||
OptStr = Optional[str] | ||
|
||
|
||
class Label(BaseModel): | ||
name: OptStr = Field(None, description="Label's name.") | ||
color: OptStr = Field(None, description="Color code of this label") | ||
description: OptStr = Field(None, description="Description of the label") | ||
new_name: OptBool = Field(None, description="If set, rename a label from name to new_name.") | ||
exists: OptBool = Field(True, description="Set to false to delete a label") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import List | ||
from typing import Optional | ||
from typing import Union | ||
|
||
from pydantic import BaseModel # pylint: disable=E0611 | ||
from pydantic import Field | ||
from pydantic import HttpUrl # pylint: disable=E0611 | ||
from pydantic import validator | ||
|
||
OptBool = Optional[bool] | ||
OptStr = Optional[str] | ||
|
||
|
||
class Secret(BaseModel): | ||
key: OptStr = Field(None, description="Secret's name.") | ||
env: OptStr = Field(None, description="Environment variable to pull the secret from") | ||
value: OptStr = Field(None, description="Value to set this secret to") | ||
required: OptBool = Field( | ||
True, | ||
description="Setting a value as not required allows you to not pass in an env var without causing an error", | ||
) | ||
exists: OptBool = Field(True, description="Set to false to delete a secret") | ||
|
||
@validator("value", always=True) | ||
def validate_value(cls, v, values) -> OptStr: | ||
if v is None: | ||
return None | ||
|
||
if values["env"] is not None: | ||
raise ValueError("Cannot set an env and a value in the same secret, remove one.") | ||
|
||
return v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from typing import Optional | ||
from typing import Set | ||
from typing import Union | ||
|
||
from pydantic import BaseModel # pylint: disable=E0611 | ||
from pydantic import Field | ||
from pydantic import HttpUrl # pylint: disable=E0611 | ||
|
||
OptBool = Optional[bool] | ||
OptStr = Optional[str] | ||
|
||
|
||
class Settings(BaseModel): | ||
description: OptStr = Field(None, description="A short description of the repository that will show up on GitHub.") | ||
homepage: Optional[Union[str, HttpUrl]] = Field( | ||
None, description="A URL with more information about the repository." | ||
) | ||
topics: Optional[Union[str, Set[str]]] = Field( | ||
None, description="A list of strings to apply as topics on the repo" | ||
) | ||
private: OptBool = Field( | ||
None, description="Either `true` to make the repository private, or `false` to make it public." | ||
) | ||
has_issues: OptBool = Field( | ||
None, description="Either `true` to enable issues for this repository, `false` to disable them." | ||
) | ||
has_projects: OptBool = Field( | ||
None, | ||
description="Either `true` to enable projects for this repository, or `false` to disable them. If projects are disabled for the organization, passing `true` will cause an API error.", | ||
) | ||
has_wiki: OptBool = Field( | ||
None, description="Either `true` to enable the wiki for this repository, `false` to disable it." | ||
) | ||
has_downloads: OptBool = Field( | ||
None, description="Either `true` to enable downloads for this repository, `false` to disable them." | ||
) | ||
default_branch: OptStr = Field(None, description="Set the default branch for this repository. ") | ||
allow_squash_merge: OptBool = Field( | ||
None, description="Either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging." | ||
) | ||
allow_merge_commit: OptBool = Field( | ||
None, | ||
description="Either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.", | ||
) | ||
allow_rebase_merge: OptBool = Field( | ||
None, | ||
description=" # Either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.", | ||
) | ||
delete_branch_on_merge: OptBool = Field( | ||
None, description="Either `true` to enable automatic deletion of branches on merge, or `false` to disable" | ||
) | ||
enable_automate_security_fixes: OptBool = Field( | ||
None, | ||
description="Either `true` to enable automated security fixes, or `false` to disable automated security fixes.", | ||
) | ||
enable_vulnerability_alerts: OptBool = Field( | ||
None, description="Either `true` to enable vulnerability alerts, or `false` to disable vulnerability alerts." | ||
) |