Skip to content

Commit

Permalink
Merge pull request #10 from jnwng/feat/add-base-url
Browse files Browse the repository at this point in the history
This PR adds baseUrl to the action allowing onPerm GitHub instances to take advantage of the action. 

I've replicated #6 @bBackdark PR to avoid having issues with tokens missing in the workflows.
  • Loading branch information
gagoar authored Dec 29, 2022
2 parents 81ed716 + ff1d06e commit a8b194f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ By providing some key information to this action, it will return you your GitHub

## Input

| Key | Type | Required | Description |
| ----------------------- | :------: | :------: | ----------------------------------------------------------------------- |
| `appId` | `int` | Yes | Your GitHub App's id |
| `installationId` | `int` | Yes | The installation id of the the GitHub App in this repo / org |
| `privateKey` | `string` | Yes | The private key associated to the GitHub App (typically an RSA private key)|
| Key | Type | Required | Description |
| ---------------- | :------: | :------: | --------------------------------------------------------------------------------------------------------------------------- |
| `appId` | `int` | Yes | Your GitHub App's id |
| `installationId` | `int` | Yes | The installation id of the the GitHub App in this repo / org |
| `privateKey` | `string` | Yes | The private key associated to the GitHub App (typically an RSA private key) |
| `baseUrl` | `string` | No | Custom base url of Github if for example self hosted in enterprise context. For example: `https://github.domain.com/api/v3` |

**Be sure to store your `privateKey` [as a secret](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) in GitHub Actions!**

## Output

This action returns the relevant installation token for use in subsequent steps, like [actions/github-script](https://github.com/actions/github-script)

| Property | Type | Description |
| ----------------- | --------- | ----------------------------------------------------------------------------------- |
| `token` | `string` | A GitHub App [installation access token](https://docs.github.com/en/rest/reference/apps#create-an-installation-access-token-for-an-app)|
| Property | Type | Description |
| -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `token` | `string` | A GitHub App [installation access token](https://docs.github.com/en/rest/reference/apps#create-an-installation-access-token-for-an-app) |

## Examples

Expand Down
4 changes: 3 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
const mockedInput = {
appId: APP_ID,
installationId: 123,
privateKey: PRIVATE_KEY
privateKey: PRIVATE_KEY,
baseUrl: ''
}

const getAccessTokensURL = (installationID: number): string =>
Expand All @@ -73,6 +74,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==

try {
await run()
expect(setFailed).not.toHaveBeenCalled()
expect(setOutput).toHaveBeenCalled()
expect(github.isDone()).toBe(true)
} catch (e) {
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
privateKey:
description: The private key used to sign the JWT
required: true
baseUrl:
description: Optional base url for github requests
required: false
outputs:
token:
description: The generated RS256-signed JWT
Expand Down
3 changes: 2 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24719,7 +24719,8 @@ async function run() {
const appId = parseInt((0, import_core.getInput)("appId"), 10);
const installationId = parseInt((0, import_core.getInput)("installationId"), 10);
const privateKey = (0, import_core.getInput)("privateKey");
const { token } = await (0, import_github_app_installation_token.getToken)({ appId, installationId, privateKey });
const baseUrl = (0, import_core.getInput)("baseUrl", { required: false });
const { token } = await (0, import_github_app_installation_token.getToken)({ appId, installationId, privateKey, baseUrl });
(0, import_core.setOutput)("token", token);
} catch (error) {
(0, import_core.setFailed)(error.message);
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export async function run(): Promise<void> {
const appId = parseInt(getInput('appId'), 10)
const installationId = parseInt(getInput('installationId'), 10)
const privateKey = getInput('privateKey')
const baseUrl = getInput('baseUrl', {required: false}) || undefined

const {token} = await getToken({appId, installationId, privateKey})
const {token} = await getToken({appId, installationId, privateKey, baseUrl})

setOutput('token', token)
} catch (error) {
Expand Down

0 comments on commit a8b194f

Please sign in to comment.