Skip to content

feat: ghe support #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

[![Action Template](https://img.shields.io/badge/Action%20Template-Python%20Container%20Action-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/andrewthetechie/gha-repo-manager)
[![Actions Status](https://github.com/andrewthetechie/gha-repo-manager/workflows/Lint/badge.svg)](https://github.com/andrewthetechie/gha-repo-manager/actions)
[![Actions Status](https://github.com/andrewthetechie/gha-repo-manager/workflows/Integration%20Test/badge.svg)](https://github.com/andrewthetechie/gha-repo-manager/actions)

<!-- action-docs-description -->
## Description

Expand Down Expand Up @@ -64,13 +60,10 @@ jobs:

| parameter | description | required | default |
| - | - | - | - |
| action | 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
| `false` | check |
| action | 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 | `false` | check |
| settings_file | What yaml file to use as your settings. This is local to runner running this action. | `false` | .github/settings.yml |
| repo | What repo to perform this action on. Default is self, as in the repo this action is running in | `false` | self |
| github_server_url | Set a custom github server url for github api operations. Useful if you're running on GHE. Will try to autodiscover from env.GITHUB_SERVER_URL if left at default | `false` | none |
| token | What github token to use with this action. | `true` | |


Expand Down
9 changes: 4 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ description: "Manage your Github repo(s) settings and secrets using Github Actio
author: "Andrew Herrington"
inputs:
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
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"
github_server_url:
description: Set a custom github server url for github api operations. Useful if you're running on GHE. Will try to autodiscover from env.GITHUB_SERVER_URL if left at default
default: "none"
token:
description: What github token to use with this action.
required: true
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ show_error_codes = true
show_error_context = true

[tool.pytest.ini_options]
python_paths = "./"
norecursedirs = ".github ci .git .idea"
addopts = "--cov=repo_manager --cov-report xml:.coverage.xml --cov-report=term-missing"
4 changes: 2 additions & 2 deletions repo_manager/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@


@lru_cache
def get_github_client(token: str) -> Github:
def get_github_client(token: str, api_url: str) -> Github:
""" """
return Github(token)
return Github(token, base_url=api_url)
15 changes: 14 additions & 1 deletion repo_manager/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,21 @@ def validate_inputs(parsed_inputs: dict[str, Any]) -> dict[str, Any]:
+ "GITHUB_REPOSITORY env var is not set. Please set INPUT_REPO or GITHUB_REPOSITORY in the env"
)

if parsed_inputs["github_server_url"].lower() == "none":
parsed_inputs["github_server_url"] = os.environ.get("GITHUB_SERVER_URL", None)
if parsed_inputs["github_server_url"] is None:
actions_toolkit.set_failed(
"Error getting inputs. github_server_url is 'none' and "
+ "GITHUB_SERVER_URL env var is not set. Please set "
+ "INPUT_GITHUB_SERVER_URL or GITHUB_SERVER_URL in the env"
)
if parsed_inputs["github_server_url"] == "https://github.com":
api_url = "https://api.github.com"
else:
api_url = parsed_inputs["github_server_url"] + "/api/v3"

try:
repo = get_github_client(parsed_inputs["token"]).get_repo(parsed_inputs["repo"])
repo = get_github_client(parsed_inputs["token"], api_url=api_url).get_repo(parsed_inputs["repo"])
except Exception as exc: # this should be tighter
actions_toolkit.set_failed(f"Error while retriving {parsed_inputs['repo']} from Github. {exc}")

Expand Down
6 changes: 5 additions & 1 deletion repo_manager/utils/_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
###START_INPUT_AUTOMATION###
INPUTS = {
"action": {
"description": "What action to take with this action. One of validate, check, or apply.\nValidate will validate your settings file, but not touch your repo.\nCheck will check your repo with your settings file and output a report of any drift.\nApply will apply the settings in your settings file to your repo\n",
"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": {
Expand All @@ -14,6 +14,10 @@
"description": "What repo to perform this action on. Default is self, as in the repo this action is running in",
"default": "self",
},
"github_server_url": {
"description": "Set a custom github server url for github api operations. Useful if you're running on GHE. Will try to autodiscover from env.GITHUB_SERVER_URL if left at default",
"default": "none",
},
"token": {"description": "What github token to use with this action.", "required": True},
}
###END_INPUT_AUTOMATION###