From cff1ab2c9e5c3d2623d1704fb965fac1675d819c Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Mon, 13 Dec 2021 15:11:16 +0900 Subject: [PATCH] update naming and docs --- README.md | 20 +++++++++++--------- action.yml | 11 +++++++---- dist/index.js | 13 +++++++------ src/create-or-update-branch.ts | 7 ++++--- src/create-pull-request.ts | 4 ++-- src/main.ts | 4 ++-- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 852dd89..599ca1f 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ All inputs are **optional**. If not set, sensible defaults will be used. | --- | --- | --- | | `token` | `GITHUB_TOKEN` (`contents: write`, `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` | | `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. Defaults to adding all new and modified files. See [Controlling committed files](#controlling-committed-files). | `-A` | | `commit-message` | The message to use when committing changes. | `[create-pull-request] automated change` | | `committer` | The committer name and email address in the format `Display Name `. Defaults to the GitHub Actions bot user. | `GitHub ` | | `author` | The author name and email address in the format `Display Name `. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>` | @@ -63,7 +64,6 @@ All inputs are **optional**. If not set, sensible defaults will be used. | `team-reviewers` | A comma or newline-separated list of GitHub teams to request a review from. Note that a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) may be required. See [this issue](https://github.com/peter-evans/create-pull-request/issues/155). If using a GitHub App, refer to [Authenticating with GitHub App generated tokens](docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens) for the proper permissions. | | | `milestone` | The number of the milestone to associate this pull request with. | | | `draft` | Create a [draft pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). | `false` | | -| `add-pattern-array` | A comma or newline-separated list of file path patterns, by example `**.txt, **some_dir**.png`. | `-A (what means --all)` | For self-hosted runners behind a corporate proxy set the `https_proxy` environment variable. ```yml @@ -125,16 +125,18 @@ To use this strategy, set input `branch-suffix` with one of the following option ### Controlling committed files -You may control files to added on pull request with argument `add-pattern-array`. -It specify `git add` pattern of files. By example: +The action defaults to adding all new and modified files. +You can override this behaviour and control which files are committed with the `add-paths` input. +Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. +All file changes that do not match one of the paths will be discarded. + ```yml - ... - uses: peter-evans/create-pull-request@main #TODO put next version here + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 with: - add-pattern-array: | - **.txt - **some/dirs**.png - token: ${{ secrets.GITHUB_TOKEN }} + add-paths: | + *.java + docs/\*.txt ``` ### Controlling commits diff --git a/action.yml b/action.yml index ac92da0..512e658 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,13 @@ inputs: description: > Relative path under $GITHUB_WORKSPACE to the repository. Defaults to $GITHUB_WORKSPACE. + add-paths: + description: > + A comma or newline-separated list of file paths to commit. + Paths should follow git's pathspec syntax. + Defaults to adding all new and modified files. + default: | + -A commit-message: description: 'The message to use when committing changes.' default: '[create-pull-request] automated change' @@ -64,10 +71,6 @@ inputs: draft: description: 'Create a draft pull request' default: false - add-pattern-array: - description: 'git add [pattern]' - default: | - -A outputs: pull-request-number: description: 'The pull request number' diff --git a/dist/index.js b/dist/index.js index df98b37..f911c9c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -98,7 +98,7 @@ function splitLines(multilineString) { .map(s => s.trim()) .filter(x => x !== ''); } -function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName, signoff, filePatterns) { +function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName, signoff, addPaths) { return __awaiter(this, void 0, void 0, function* () { // Get the working base. // When a ref, it may or may not be the actual base. @@ -124,14 +124,15 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName // Commit any uncommitted changes if (yield git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.'); - for (const filePattern of filePatterns) { - yield git.exec(['add', filePattern], true); + for (const path of addPaths) { + yield git.exec(['add', path], true); } const params = ['-m', commitMessage]; if (signoff) { params.push('--signoff'); } yield git.commit(params); + // Remove uncommitted tracked and untracked changes git.exec(['reset', '--hard']); git.exec(['clean', '-f']); } @@ -381,7 +382,7 @@ function createPullRequest(inputs) { core.endGroup(); // Create or update the pull request branch core.startGroup('Create or update the pull request branch'); - const result = yield (0, create_or_update_branch_1.createOrUpdateBranch)(git, inputs.commitMessage, inputs.base, inputs.branch, branchRemoteName, inputs.signoff, inputs.addPatternArray); + const result = yield (0, create_or_update_branch_1.createOrUpdateBranch)(git, inputs.commitMessage, inputs.base, inputs.branch, branchRemoteName, inputs.signoff, inputs.addPaths); core.endGroup(); if (['created', 'updated'].includes(result.action)) { // The branch was created or updated @@ -1078,6 +1079,7 @@ function run() { const inputs = { token: core.getInput('token'), path: core.getInput('path'), + addPaths: utils.getInputAsArray('add-paths'), commitMessage: core.getInput('commit-message'), committer: core.getInput('committer'), author: core.getInput('author'), @@ -1094,8 +1096,7 @@ function run() { reviewers: utils.getInputAsArray('reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'), milestone: Number(core.getInput('milestone')), - draft: core.getInput('draft') === 'true', - addPatternArray: utils.getInputAsArray('add-pattern-array') + draft: core.getInput('draft') === 'true' }; core.debug(`Inputs: ${(0, util_1.inspect)(inputs)}`); yield (0, create_pull_request_1.createPullRequest)(inputs); diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index 9031a13..46265bc 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -92,7 +92,7 @@ export async function createOrUpdateBranch( branch: string, branchRemoteName: string, signoff: boolean, - filePatterns: string[] + addPaths: string[] ): Promise { // Get the working base. // When a ref, it may or may not be the actual base. @@ -121,14 +121,15 @@ export async function createOrUpdateBranch( // Commit any uncommitted changes if (await git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.') - for (const filePattern of filePatterns) { - await git.exec(['add', filePattern], true) + for (const path of addPaths) { + await git.exec(['add', path], true) } const params = ['-m', commitMessage] if (signoff) { params.push('--signoff') } await git.commit(params) + // Remove uncommitted tracked and untracked changes git.exec(['reset', '--hard']) git.exec(['clean', '-f']) } diff --git a/src/create-pull-request.ts b/src/create-pull-request.ts index 73c874c..81caa88 100644 --- a/src/create-pull-request.ts +++ b/src/create-pull-request.ts @@ -12,6 +12,7 @@ import * as utils from './utils' export interface Inputs { token: string path: string + addPaths: string[] commitMessage: string committer: string author: string @@ -29,7 +30,6 @@ export interface Inputs { teamReviewers: string[] milestone: number draft: boolean - addPatternArray: string[] } export async function createPullRequest(inputs: Inputs): Promise { @@ -175,7 +175,7 @@ export async function createPullRequest(inputs: Inputs): Promise { inputs.branch, branchRemoteName, inputs.signoff, - inputs.addPatternArray + inputs.addPaths ) core.endGroup() diff --git a/src/main.ts b/src/main.ts index baa9a32..45a1ae8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,6 +8,7 @@ async function run(): Promise { const inputs: Inputs = { token: core.getInput('token'), path: core.getInput('path'), + addPaths: utils.getInputAsArray('add-paths'), commitMessage: core.getInput('commit-message'), committer: core.getInput('committer'), author: core.getInput('author'), @@ -24,8 +25,7 @@ async function run(): Promise { reviewers: utils.getInputAsArray('reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'), milestone: Number(core.getInput('milestone')), - draft: core.getInput('draft') === 'true', - addPatternArray: utils.getInputAsArray('add-pattern-array') + draft: core.getInput('draft') === 'true' } core.debug(`Inputs: ${inspect(inputs)}`)