Skip to content

Commit 60e128a

Browse files
feat: ghe support (#23)
* docs: cleanup badges * feat: support for github enterprise This adds github_server_url to the inputs and adds logic to try to autodsicover it via the Environment * docs: automated doc update * fix: api_url keyword * docs: fix action descriptions to remove newlines * docs: automated doc update
1 parent 8fc702a commit 60e128a

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

README.md

+2-9
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
44
<!-- ALL-CONTRIBUTORS-BADGE:END -->
55

6-
[![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)
7-
[![Actions Status](https://github.com/andrewthetechie/gha-repo-manager/workflows/Lint/badge.svg)](https://github.com/andrewthetechie/gha-repo-manager/actions)
8-
[![Actions Status](https://github.com/andrewthetechie/gha-repo-manager/workflows/Integration%20Test/badge.svg)](https://github.com/andrewthetechie/gha-repo-manager/actions)
9-
106
<!-- action-docs-description -->
117
## Description
128

@@ -64,13 +60,10 @@ jobs:
6460

6561
| parameter | description | required | default |
6662
| - | - | - | - |
67-
| action | What action to take with this action. One of validate, check, or apply.
68-
Validate will validate your settings file, but not touch your repo.
69-
Check will check your repo with your settings file and output a report of any drift.
70-
Apply will apply the settings in your settings file to your repo
71-
| `false` | check |
63+
| 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 |
7264
| settings_file | What yaml file to use as your settings. This is local to runner running this action. | `false` | .github/settings.yml |
7365
| repo | What repo to perform this action on. Default is self, as in the repo this action is running in | `false` | self |
66+
| 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 |
7467
| token | What github token to use with this action. | `true` | |
7568

7669

action.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ description: "Manage your Github repo(s) settings and secrets using Github Actio
33
author: "Andrew Herrington"
44
inputs:
55
action:
6-
description: |
7-
What action to take with this action. One of validate, check, or apply.
8-
Validate will validate your settings file, but not touch your repo.
9-
Check will check your repo with your settings file and output a report of any drift.
10-
Apply will apply the settings in your settings file to your repo
6+
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
117
default: "check"
128
settings_file:
139
description: What yaml file to use as your settings. This is local to runner running this action.
1410
default: ".github/settings.yml"
1511
repo:
1612
description: What repo to perform this action on. Default is self, as in the repo this action is running in
1713
default: "self"
14+
github_server_url:
15+
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
16+
default: "none"
1817
token:
1918
description: What github token to use with this action.
2019
required: true

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,5 @@ show_error_codes = true
5858
show_error_context = true
5959

6060
[tool.pytest.ini_options]
61-
python_paths = "./"
6261
norecursedirs = ".github ci .git .idea"
6362
addopts = "--cov=repo_manager --cov-report xml:.coverage.xml --cov-report=term-missing"

repo_manager/github/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55

66
@lru_cache
7-
def get_github_client(token: str) -> Github:
7+
def get_github_client(token: str, api_url: str) -> Github:
88
""" """
9-
return Github(token)
9+
return Github(token, base_url=api_url)

repo_manager/utils/__init__.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,21 @@ def validate_inputs(parsed_inputs: dict[str, Any]) -> dict[str, Any]:
7171
+ "GITHUB_REPOSITORY env var is not set. Please set INPUT_REPO or GITHUB_REPOSITORY in the env"
7272
)
7373

74+
if parsed_inputs["github_server_url"].lower() == "none":
75+
parsed_inputs["github_server_url"] = os.environ.get("GITHUB_SERVER_URL", None)
76+
if parsed_inputs["github_server_url"] is None:
77+
actions_toolkit.set_failed(
78+
"Error getting inputs. github_server_url is 'none' and "
79+
+ "GITHUB_SERVER_URL env var is not set. Please set "
80+
+ "INPUT_GITHUB_SERVER_URL or GITHUB_SERVER_URL in the env"
81+
)
82+
if parsed_inputs["github_server_url"] == "https://github.com":
83+
api_url = "https://api.github.com"
84+
else:
85+
api_url = parsed_inputs["github_server_url"] + "/api/v3"
86+
7487
try:
75-
repo = get_github_client(parsed_inputs["token"]).get_repo(parsed_inputs["repo"])
88+
repo = get_github_client(parsed_inputs["token"], api_url=api_url).get_repo(parsed_inputs["repo"])
7689
except Exception as exc: # this should be tighter
7790
actions_toolkit.set_failed(f"Error while retriving {parsed_inputs['repo']} from Github. {exc}")
7891

repo_manager/utils/_inputs.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
###START_INPUT_AUTOMATION###
44
INPUTS = {
55
"action": {
6-
"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",
6+
"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",
77
"default": "check",
88
},
99
"settings_file": {
@@ -14,6 +14,10 @@
1414
"description": "What repo to perform this action on. Default is self, as in the repo this action is running in",
1515
"default": "self",
1616
},
17+
"github_server_url": {
18+
"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",
19+
"default": "none",
20+
},
1721
"token": {"description": "What github token to use with this action.", "required": True},
1822
}
1923
###END_INPUT_AUTOMATION###

0 commit comments

Comments
 (0)