Skip to content

Commit

Permalink
feat: optional input for git ops token
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-evans committed Sep 25, 2023
1 parent 126241d commit 32179d9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | `[create-pull-request] automated change` |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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'),
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/create-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as utils from './utils'

export interface Inputs {
token: string
gitToken: string
path: string
addPaths: string[]
commitMessage: string
Expand Down Expand Up @@ -106,7 +107,7 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
// 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()
}

Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async function run(): Promise<void> {
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'),
Expand All @@ -30,6 +31,10 @@ async function run(): Promise<void> {
}
core.debug(`Inputs: ${inspect(inputs)}`)

if (!inputs.gitToken) {
inputs.gitToken = inputs.token
}

await createPullRequest(inputs)
} catch (error) {
core.setFailed(utils.getErrorMessage(error))
Expand Down

0 comments on commit 32179d9

Please sign in to comment.