From 76979c4272448278067c43328a8adf91b0a94f02 Mon Sep 17 00:00:00 2001 From: avdim Date: Wed, 8 Dec 2021 14:28:53 +0300 Subject: [PATCH 1/5] add add-pattern-array argument --- .gitignore | 1 + action.yml | 4 ++++ dist/index.js | 11 +++++++---- src/create-or-update-branch.ts | 7 +++++-- src/create-pull-request.ts | 4 +++- src/main.ts | 3 ++- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index d35224019..93a4a641b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ lib/ node_modules/ .DS_Store +.idea diff --git a/action.yml b/action.yml index 96fb5d1d7..ac92da0e6 100644 --- a/action.yml +++ b/action.yml @@ -64,6 +64,10 @@ 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 be6695e9d..b4895ee27 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) { +function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName, signoff, filePatterns) { 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,7 +124,9 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName // Commit any uncommitted changes if (yield git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.'); - yield git.exec(['add', '-A']); + for (const filePattern of filePatterns) { + yield git.exec(['add', filePattern]); + } const params = ['-m', commitMessage]; if (signoff) { params.push('--signoff'); @@ -377,7 +379,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); + const result = yield (0, create_or_update_branch_1.createOrUpdateBranch)(git, inputs.commitMessage, inputs.base, inputs.branch, branchRemoteName, inputs.signoff, inputs.addPatternArray); core.endGroup(); if (['created', 'updated'].includes(result.action)) { // The branch was created or updated @@ -1090,7 +1092,8 @@ function run() { reviewers: utils.getInputAsArray('reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'), milestone: Number(core.getInput('milestone')), - draft: core.getInput('draft') === 'true' + draft: core.getInput('draft') === 'true', + addPatternArray: utils.getInputAsArray('add-pattern-array') }; 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 f33051d1a..1934287fa 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -91,7 +91,8 @@ export async function createOrUpdateBranch( base: string, branch: string, branchRemoteName: string, - signoff: boolean + signoff: boolean, + filePatterns: string[] ): Promise { // Get the working base. // When a ref, it may or may not be the actual base. @@ -120,7 +121,9 @@ export async function createOrUpdateBranch( // Commit any uncommitted changes if (await git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.') - await git.exec(['add', '-A']) + for (const filePattern of filePatterns) { + await git.exec(['add', filePattern]) + } const params = ['-m', commitMessage] if (signoff) { params.push('--signoff') diff --git a/src/create-pull-request.ts b/src/create-pull-request.ts index 8b2c11e62..73c874c15 100644 --- a/src/create-pull-request.ts +++ b/src/create-pull-request.ts @@ -29,6 +29,7 @@ export interface Inputs { teamReviewers: string[] milestone: number draft: boolean + addPatternArray: string[] } export async function createPullRequest(inputs: Inputs): Promise { @@ -173,7 +174,8 @@ export async function createPullRequest(inputs: Inputs): Promise { inputs.base, inputs.branch, branchRemoteName, - inputs.signoff + inputs.signoff, + inputs.addPatternArray ) core.endGroup() diff --git a/src/main.ts b/src/main.ts index bb7b7e23c..baa9a329d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -24,7 +24,8 @@ async function run(): Promise { reviewers: utils.getInputAsArray('reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'), milestone: Number(core.getInput('milestone')), - draft: core.getInput('draft') === 'true' + draft: core.getInput('draft') === 'true', + addPatternArray: utils.getInputAsArray('add-pattern-array') } core.debug(`Inputs: ${inspect(inputs)}`) From 205aea6a3eb91682ec1c501f53de61f03dbea382 Mon Sep 17 00:00:00 2001 From: avdim Date: Wed, 8 Dec 2021 14:43:34 +0300 Subject: [PATCH 2/5] ignore return code --- dist/index.js | 2 +- src/create-or-update-branch.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index b4895ee27..7d704f067 100644 --- a/dist/index.js +++ b/dist/index.js @@ -125,7 +125,7 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName if (yield git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.'); for (const filePattern of filePatterns) { - yield git.exec(['add', filePattern]); + yield git.exec(['add', filePattern], true); } const params = ['-m', commitMessage]; if (signoff) { diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index 1934287fa..7c2a3ac07 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -122,7 +122,7 @@ export async function createOrUpdateBranch( if (await git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.') for (const filePattern of filePatterns) { - await git.exec(['add', filePattern]) + await git.exec(['add', filePattern], true) } const params = ['-m', commitMessage] if (signoff) { From aadca79904b06bb906e191d55b60e6e1da03796c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B2=D0=B4=D0=B5=D0=B5=D0=B2=20=D0=94=D0=B8=D0=BC?= =?UTF-8?q?=D0=B0?= Date: Wed, 8 Dec 2021 15:17:53 +0300 Subject: [PATCH 3/5] doc to add-pattern-array --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da7493844..a5d978765 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,8 @@ All inputs are **optional**. If not set, sensible defaults will be used. | `reviewers` | A comma or newline-separated list of reviewers (GitHub usernames) to request a review from. | | | `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` | +| `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 From 2d4e9657d4ab38a33cd819eb71ce661917aadec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B2=D0=B4=D0=B5=D0=B5=D0=B2=20=D0=94=D0=B8=D0=BC?= =?UTF-8?q?=D0=B0?= Date: Wed, 8 Dec 2021 15:33:59 +0300 Subject: [PATCH 4/5] update README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index a5d978765..852dd893d 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,20 @@ To use this strategy, set input `branch-suffix` with one of the following option - `short-commit-hash` - Commits will be made to a branch suffixed with the short SHA1 commit hash. e.g. `create-pull-request/patch-fcdfb59`, `create-pull-request/patch-394710b` +### 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: +```yml + ... + uses: peter-evans/create-pull-request@main #TODO put next version here + with: + add-pattern-array: | + **.txt + **some/dirs**.png + token: ${{ secrets.GITHUB_TOKEN }} +``` + ### Controlling commits As well as relying on the action to handle uncommitted changes, you can additionally make your own commits before the action runs. From 0e80eb58d9fd1bc27a69eb0fc49d5f44167b6216 Mon Sep 17 00:00:00 2001 From: avdim Date: Wed, 8 Dec 2021 18:31:26 +0300 Subject: [PATCH 5/5] cleanup after success commit --- dist/index.js | 2 ++ src/create-or-update-branch.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dist/index.js b/dist/index.js index 7d704f067..df98b37f8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -132,6 +132,8 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName params.push('--signoff'); } yield git.commit(params); + git.exec(['reset', '--hard']); + git.exec(['clean', '-f']); } // Perform fetch and reset the working base // Commits made during the workflow will be removed diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index 7c2a3ac07..9031a13eb 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -129,6 +129,8 @@ export async function createOrUpdateBranch( params.push('--signoff') } await git.commit(params) + git.exec(['reset', '--hard']) + git.exec(['clean', '-f']) } // Perform fetch and reset the working base