Skip to content

Commit bf16ef0

Browse files
authored
Merge pull request #19 from goshlanguage/configurable-github-api-1
Additional changes for Github enterprise support
2 parents 04a4d41 + 026937b commit bf16ef0

4 files changed

Lines changed: 7 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Prometheus metrics exporter for github actions self-hosted runners.
1212
| REFRESH_INTERVAL | No | Internval time in seconds betwen api requests (Default: 20)
1313
| LOG_LEVEL | No | Log level: DEBUG, INFO, WARNING or ERROR (Default: INFO)
1414
| API_URL | No | URL to your github API (Default: https://api.github.com)
15+
| GITHUB_APP_ID | No | The Github app id to login as
16+
| GITHUB_PRIVATE_KEY | No* | The Github app private key generated from the app settings, required if GITHUB_APP_ID is set
1517

1618

1719
## How to deploy

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
cryptography==42.0.5
12
prometheus_client==0.15.0
23
requests==2.28.2
3-
PyJWT==2.6.0
4+
PyJWT==2.8.0
45
python-dateutil==2.8.1

runner_exporter/github_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(
3838
self.github_app_id = github_app_id
3939
self.private_key = private_key
4040
self.github_owner = github_owner
41+
self.api_url = api_url
4142
self.logger = logger
4243

4344
def app_jwt_header(self):
@@ -152,7 +153,7 @@ def list_runners(self) -> list:
152153
headers = self.get_headers()
153154

154155
per_page = 100
155-
url = f"https://api.github.com/orgs/{self.github_owner}/actions/runners?per_page={per_page}"
156+
url = f"{self.api_url}/orgs/{self.github_owner}/actions/runners?per_page={per_page}"
156157

157158
while True:
158159
try:

runner_exporter/runner_exporter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,14 @@ def main():
156156
GITHUB_APP_ID = os.getenv("GITHUB_APP_ID")
157157
GITHUB_PRIVATE_KEY = os.getenv("GITHUB_PRIVATE_KEY")
158158
OWNER = os.getenv("OWNER")
159-
API_URL = os.getenv("API_URL")
159+
API_URL = os.getenv("API_URL", "https://api.github.com")
160160

161161
# Start prometheus metrics
162162
logger.info("Starting metrics server")
163163
start_http_server(8000)
164164

165165
runner_exports = runnerExports()
166166

167-
if API_URL == None or API_URL == "":
168-
API_URL = "https://api.github.com"
169-
170167
github = githubApi(
171168
OWNER,
172169
logger,

0 commit comments

Comments
 (0)