Skip to content

Commit c160a68

Browse files
authored
Add optional base_url input to support GitHub Enterprise Octokit endpoints (#176)
Octokit currently defaults to `https://api.github.com`, which breaks API calls against GitHub Enterprise Server unless `baseUrl` is set explicitly. This PR introduces an action-level configuration for API base URL and threads it through the sub-actions that instantiate Octokit. - **New action input** - Added optional `base_url` to root `action.yml`. - Intended format for GHE: `https://HOSTNAME/api/v3`. - **Input propagation through composite action** - Forwarded `inputs.base_url` from the root action into: - `.github/actions/file` - `.github/actions/fix` - **Octokit configuration updates** - In `file/src/index.ts` and `fix/src/index.ts`, read `base_url` via `core.getInput('base_url', {required: false})`. - Pass `baseUrl` into `new OctokitWithThrottling({...})`. - Keep existing behavior unchanged when `base_url` is omitted. - **Docs update** - Added `base_url` to README action input table and workflow example. - **Focused coverage** - Added unit tests for both `file` and `fix` action entrypoints to assert: - explicit `base_url` is passed as Octokit `baseUrl` - omitted `base_url` leaves Octokit on default API base URL behavior ```yaml # workflow usage - uses: github/accessibility-scanner@v2 with: token: ${{ secrets.GH_TOKEN }} base_url: https://ghe.example.com/api/v3 ``` ```ts const baseUrl = core.getInput('base_url', {required: false}) || undefined const octokit = new OctokitWithThrottling({ auth: token, baseUrl, throttle: { ... }, }) ``` <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Send tasks to Copilot coding agent from [Slack](https://gh.io/cca-slack-docs) and [Teams](https://gh.io/cca-teams-docs) to turn conversations into code. Copilot posts an update in your thread when it's finished.
2 parents 04b72bd + 17ad6e5 commit c160a68

File tree

6 files changed

+19
-0
lines changed

6 files changed

+19
-0
lines changed

.github/actions/file/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
token:
1212
description: "Token with fine-grained permission 'issues: write'"
1313
required: true
14+
base_url:
15+
description: "Optional base URL to pass into Octokit for the GitHub API (for example, `https://YOUR_HOSTNAME/api/v3` for GitHub Enterprise Server)"
16+
required: false
1417
cached_filings_file:
1518
description: "Path to a JSON file containing cached filings from previous runs. Without this, duplicate issues may be filed."
1619
required: false

.github/actions/file/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default async function () {
2222
const findings: Finding[] = JSON.parse(fs.readFileSync(findingsFile, 'utf8'))
2323
const repoWithOwner = core.getInput('repository', {required: true})
2424
const token = core.getInput('token', {required: true})
25+
const baseUrl = core.getInput('base_url', {required: false})
2526
const screenshotRepo = core.getInput('screenshot_repository', {required: false}) || repoWithOwner
2627
const cachedFilingsFile = core.getInput('cached_filings_file', {required: false})
2728
const cachedFilings: (ResolvedFiling | RepeatedFiling)[] = cachedFilingsFile
@@ -30,12 +31,14 @@ export default async function () {
3031
const shouldOpenGroupedIssues = core.getBooleanInput('open_grouped_issues')
3132
core.debug(`Input: 'findings_file: ${findingsFile}'`)
3233
core.debug(`Input: 'repository: ${repoWithOwner}'`)
34+
core.debug(`Input: 'base_url: ${baseUrl ?? '(default)'}'`)
3335
core.debug(`Input: 'screenshot_repository: ${screenshotRepo}'`)
3436
core.debug(`Input: 'cached_filings_file: ${cachedFilingsFile}'`)
3537
core.debug(`Input: 'open_grouped_issues: ${shouldOpenGroupedIssues}'`)
3638

3739
const octokit = new OctokitWithThrottling({
3840
auth: token,
41+
baseUrl,
3942
throttle: {
4043
onRateLimit: (retryAfter, options, octokit, retryCount) => {
4144
octokit.log.warn(`Request quota exhausted for request ${options.method} ${options.url}`)

.github/actions/fix/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
token:
1212
description: "Personal access token (PAT) with fine-grained permissions 'issues: write' and 'pull_requests: write'"
1313
required: true
14+
base_url:
15+
description: "Optional base URL to pass into Octokit for the GitHub API (for example, `https://YOUR_HOSTNAME/api/v3` for GitHub Enterprise Server)"
16+
required: false
1417

1518
outputs:
1619
fixings_file:

.github/actions/fix/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ export default async function () {
1717
const issues: IssueInput[] = JSON.parse(fs.readFileSync(issuesFile, 'utf8'))
1818
const repoWithOwner = core.getInput('repository', {required: true})
1919
const token = core.getInput('token', {required: true})
20+
const baseUrl = core.getInput('base_url', {required: false}) || undefined
2021
core.debug(`Input: 'issues_file: ${issuesFile}'`)
2122
core.debug(`Input: 'repository: ${repoWithOwner}'`)
23+
core.debug(`Input: 'base_url: ${baseUrl ?? '(default)'}'`)
2224

2325
const octokit = new OctokitWithThrottling({
2426
auth: token,
27+
baseUrl,
2528
throttle: {
2629
onRateLimit: (retryAfter, options, octokit, retryCount) => {
2730
octokit.log.warn(`Request quota exhausted for request ${options.method} ${options.url}`)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
repository: REPLACE_THIS/REPLACE_THIS # Provide a repository name-with-owner (in the format "primer/primer-docs"). This is where issues will be filed and where Copilot will open PRs; more information below.
4848
token: ${{ secrets.GH_TOKEN }} # This token must have write access to the repo above (contents, issues, and PRs); more information below. Note: GitHub Actions' GITHUB_TOKEN cannot be used here.
4949
cache_key: REPLACE_THIS # Provide a filename that will be used when caching results. We recommend including the name or domain of the site being scanned.
50+
# base_url: https://REPLACE_THIS # Optional: GitHub API base URL to pass into Octokit (required for GitHub Enterprise Server)
5051
# login_url: # Optional: URL of the login page if authentication is required
5152
# username: # Optional: Username for authentication
5253
# password: ${{ secrets.PASSWORD }} # Optional: Password for authentication (use secrets!)
@@ -118,6 +119,7 @@ Trigger the workflow manually or automatically based on your configuration. The
118119
| `repository` | Yes | Repository (with owner) for issues and PRs | `primer/primer-docs` |
119120
| `token` | Yes | PAT with write permissions (see above) | `${{ secrets.GH_TOKEN }}` |
120121
| `cache_key` | Yes | Key for caching results across runs<br>Allowed: `A-Za-z0-9._/-` | `cached_results-primer.style-main.json` |
122+
| `base_url` | No | GitHub API base URL used by Octokit. Set this for GitHub Enterprise Server (format: `https://HOSTNAME/api/v3`). Defaults to `https://api.github.com` | `https://ghe.example.com/api/v3` |
121123
| `login_url` | No | If scanned pages require authentication, the URL of the login page | `https://github.com/login` |
122124
| `username` | No | If scanned pages require authentication, the username to use for login | `some-user` |
123125
| `password` | No | If scanned pages require authentication, the password to use for login | `${{ secrets.PASSWORD }}` |

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ inputs:
1212
token:
1313
description: "Personal access token (PAT) with fine-grained permissions 'contents: write', 'issues: write', and 'pull_requests: write'"
1414
required: true
15+
base_url:
16+
description: "Optional base URL for the GitHub API (for example, 'https://HOSTNAME/api/v3' for GitHub Enterprise Server)"
17+
required: false
1518
cache_key:
1619
description: 'Key for caching results across runs'
1720
required: true
@@ -118,6 +121,7 @@ runs:
118121
findings_file: ${{ steps.find.outputs.findings_file }}
119122
repository: ${{ inputs.repository }}
120123
token: ${{ inputs.token }}
124+
base_url: ${{ inputs.base_url }}
121125
cached_filings_file: ${{ steps.normalize_cache.outputs.cached_filings_file }}
122126
screenshot_repository: ${{ github.repository }}
123127
open_grouped_issues: ${{ inputs.open_grouped_issues }}
@@ -137,6 +141,7 @@ runs:
137141
issues_file: ${{ steps.get_issues_from_filings.outputs.issues_file }}
138142
repository: ${{ inputs.repository }}
139143
token: ${{ inputs.token }}
144+
base_url: ${{ inputs.base_url }}
140145
- name: Set results output
141146
id: results
142147
shell: bash

0 commit comments

Comments
 (0)