From fb5edaa38faa09e12ca368b4679055b2989e9d1c Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:52:47 +0100 Subject: [PATCH] feat: optional input for git ops token --- README.md | 1 + action.yml | 4 ++++ dist/index.js | 6 +++++- src/create-pull-request.ts | 3 ++- src/main.ts | 5 +++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ed5976d4a..b1c0e0afe3 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ All inputs are **optional**. If not set, sensible defaults will be used. | Name | Description | Default | | --- | --- | --- | | `token` | `GITHUB_TOKEN` (permissions `contents: write` and `pull-requests: write`) or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | `GITHUB_TOKEN` | +| `git-token` | The [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) that the action will use for git operations. | Defaults to the value of `token` | | `path` | Relative path under `GITHUB_WORKSPACE` to the repository. | `GITHUB_WORKSPACE` | | `add-paths` | A comma or newline-separated list of file paths to commit. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. If no paths are specified, all new and modified files are added. See [Add specific paths](#add-specific-paths). | | | `commit-message` | The message to use when committing changes. See [commit-message](#commit-message). | `[create-pull-request] automated change` | diff --git a/action.yml b/action.yml index 5bd317e388..9993f0f5b6 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,10 @@ inputs: token: description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)' default: ${{ github.token }} + git-token: + description: > + The Personal Access Token (PAT) that the action will use for git operations. + Defaults to the value of `token`. path: description: > Relative path under $GITHUB_WORKSPACE to the repository. diff --git a/dist/index.js b/dist/index.js index 66d4115da2..ef002552b3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -376,7 +376,7 @@ function createPullRequest(inputs) { // Configure auth if (baseRemote.protocol == 'HTTPS') { core.startGroup('Configuring credential for HTTPS authentication'); - yield gitAuthHelper.configureToken(inputs.token); + yield gitAuthHelper.configureToken(inputs.gitToken); core.endGroup(); } core.startGroup('Checking the base repository state'); @@ -1206,6 +1206,7 @@ function run() { try { const inputs = { token: core.getInput('token'), + gitToken: core.getInput('git-token'), path: core.getInput('path'), addPaths: utils.getInputAsArray('add-paths'), commitMessage: core.getInput('commit-message'), @@ -1228,6 +1229,9 @@ function run() { draft: core.getBooleanInput('draft') }; core.debug(`Inputs: ${(0, util_1.inspect)(inputs)}`); + if (!inputs.gitToken) { + inputs.gitToken = inputs.token; + } yield (0, create_pull_request_1.createPullRequest)(inputs); } catch (error) { diff --git a/src/create-pull-request.ts b/src/create-pull-request.ts index 526c5a43b8..692c5574b4 100644 --- a/src/create-pull-request.ts +++ b/src/create-pull-request.ts @@ -11,6 +11,7 @@ import * as utils from './utils' export interface Inputs { token: string + gitToken: string path: string addPaths: string[] commitMessage: string @@ -106,7 +107,7 @@ export async function createPullRequest(inputs: Inputs): Promise { // Configure auth if (baseRemote.protocol == 'HTTPS') { core.startGroup('Configuring credential for HTTPS authentication') - await gitAuthHelper.configureToken(inputs.token) + await gitAuthHelper.configureToken(inputs.gitToken) core.endGroup() } diff --git a/src/main.ts b/src/main.ts index 711d0c3852..3b47e038b2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,6 +7,7 @@ async function run(): Promise { try { const inputs: Inputs = { token: core.getInput('token'), + gitToken: core.getInput('git-token'), path: core.getInput('path'), addPaths: utils.getInputAsArray('add-paths'), commitMessage: core.getInput('commit-message'), @@ -30,6 +31,10 @@ async function run(): Promise { } core.debug(`Inputs: ${inspect(inputs)}`) + if (!inputs.gitToken) { + inputs.gitToken = inputs.token + } + await createPullRequest(inputs) } catch (error) { core.setFailed(utils.getErrorMessage(error))