From ddd52205b6f87683930f7399dfff8f4c340d4704 Mon Sep 17 00:00:00 2001 From: pvogt09 <50047961+pvogt09@users.noreply.github.com> Date: Thu, 30 Jul 2020 15:51:23 +0200 Subject: [PATCH 1/8] adds signoff option to sign off commits Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com> --- README.md | 1 + action.yml | 3 +++ src/create-or-update-branch.ts | 9 +++++++-- src/create-pull-request.ts | 4 +++- src/main.ts | 3 ++- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9a5b5a4..2106f3d 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ 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://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) may be required. See [this issue](https://github.com/peter-evans/create-pull-request/issues/155). | | | `milestone` | The number of the milestone to associate this pull request with. | | | `draft` | Create a [draft pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). | `false` | +| `signoff` | Add Signed-off-by to commit message | `false` | ### Action outputs diff --git a/action.yml b/action.yml index 36f51a2..6a65523 100644 --- a/action.yml +++ b/action.yml @@ -56,6 +56,9 @@ inputs: draft: description: 'Create a draft pull request' default: false + signoff: + description: 'Add "Signed-off-by" to commit message' + default: false outputs: pull-request-number: description: 'The pull request number' diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index 9803e69..d927828 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -77,7 +77,8 @@ export async function createOrUpdateBranch( commitMessage: string, base: string, branch: string, - branchRemoteName: string + branchRemoteName: string, + signoff: boolean ): Promise { // Get the working base. This may or may not be the actual base. const workingBase = await git.symbolicRef('HEAD', ['--short']) @@ -99,7 +100,11 @@ export async function createOrUpdateBranch( if (await git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.') await git.exec(['add', '-A']) - await git.commit(['-m', commitMessage]) + if (signoff == true) { + await git.commit(['--signoff', '-m', commitMessage]) + } else { + await git.commit(['-m', commitMessage]) + } } // Perform fetch and reset the working base diff --git a/src/create-pull-request.ts b/src/create-pull-request.ts index 8da5f90..29a0e4a 100644 --- a/src/create-pull-request.ts +++ b/src/create-pull-request.ts @@ -23,6 +23,7 @@ export interface Inputs { teamReviewers: string[] milestone: number draft: boolean + signoff: boolean } export async function createPullRequest(inputs: Inputs): Promise { @@ -166,7 +167,8 @@ export async function createPullRequest(inputs: Inputs): Promise { inputs.commitMessage, inputs.base, inputs.branch, - branchRemoteName + branchRemoteName, + inputs.signoff ) core.endGroup() diff --git a/src/main.ts b/src/main.ts index 3fe5322..1766428 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,7 +22,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', + signoff: core.getInput('signoff') === 'true' } core.debug(`Inputs: ${inspect(inputs)}`) From dd364f28353f57241b19c42c676d2005744287f0 Mon Sep 17 00:00:00 2001 From: pvogt09 <50047961+pvogt09@users.noreply.github.com> Date: Thu, 30 Jul 2020 16:06:07 +0200 Subject: [PATCH 2/8] adds argument to test cases Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com> --- __test__/create-or-update-branch.int.test.ts | 126 ++++++++++++------- 1 file changed, 84 insertions(+), 42 deletions(-) diff --git a/__test__/create-or-update-branch.int.test.ts b/__test__/create-or-update-branch.int.test.ts index 335d20c..d8db654 100644 --- a/__test__/create-or-update-branch.int.test.ts +++ b/__test__/create-or-update-branch.int.test.ts @@ -200,7 +200,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('none') expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy() @@ -215,7 +216,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent) @@ -241,7 +243,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -260,7 +263,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent) @@ -286,7 +290,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -307,7 +312,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -334,7 +340,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('none') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -353,7 +360,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -388,7 +396,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -417,7 +426,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -443,7 +453,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeFalsy() @@ -462,7 +473,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -500,7 +512,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeFalsy() @@ -520,7 +533,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked) @@ -549,7 +563,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -573,7 +588,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -606,7 +622,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -632,7 +649,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -673,7 +691,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -698,7 +717,8 @@ describe('create-or-update-branch tests', () => { commitMessage, '', BRANCH, - FORK_REMOTE_NAME + FORK_REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -725,7 +745,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, '', BRANCH, - FORK_REMOTE_NAME + FORK_REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -748,7 +769,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('none') expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy() @@ -766,7 +788,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent) @@ -795,7 +818,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -817,7 +841,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent) @@ -846,7 +871,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -870,7 +896,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -900,7 +927,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('none') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -922,7 +950,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -960,7 +989,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -992,7 +1022,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -1021,7 +1052,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeFalsy() @@ -1045,7 +1077,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -1086,7 +1119,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeFalsy() @@ -1109,7 +1143,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked) @@ -1141,7 +1176,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -1168,7 +1204,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -1204,7 +1241,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -1233,7 +1271,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -1277,7 +1316,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - REMOTE_NAME + REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() @@ -1305,7 +1345,8 @@ describe('create-or-update-branch tests', () => { commitMessage, BASE, BRANCH, - FORK_REMOTE_NAME + FORK_REMOTE_NAME, + false ) expect(result.action).toEqual('created') expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) @@ -1335,7 +1376,8 @@ describe('create-or-update-branch tests', () => { _commitMessage, BASE, BRANCH, - FORK_REMOTE_NAME + FORK_REMOTE_NAME, + false ) expect(_result.action).toEqual('updated') expect(_result.hasDiffWithBase).toBeTruthy() From 7ad9f6e012d8d788902a4da5baac1a9869876017 Mon Sep 17 00:00:00 2001 From: pvogt09 <50047961+pvogt09@users.noreply.github.com> Date: Thu, 30 Jul 2020 16:23:22 +0200 Subject: [PATCH 3/8] try -s instead of --signoff Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com> --- src/create-or-update-branch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index d927828..6a6435e 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -101,7 +101,7 @@ export async function createOrUpdateBranch( core.info('Uncommitted changes found. Adding a commit.') await git.exec(['add', '-A']) if (signoff == true) { - await git.commit(['--signoff', '-m', commitMessage]) + await git.commit(['-m', commitMessage, '-s']) } else { await git.commit(['-m', commitMessage]) } From 0c57887fe8559da82c7ea1f59a88969e3b31f05e Mon Sep 17 00:00:00 2001 From: pvogt09 Date: Thu, 30 Jul 2020 15:18:17 +0000 Subject: [PATCH 4/8] Update distribution --- dist/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 550235a..fee807c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1057,7 +1057,7 @@ function splitLines(multilineString) { .map(s => s.trim()) .filter(x => x !== ''); } -function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName) { +function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName, signoff) { return __awaiter(this, void 0, void 0, function* () { // Get the working base. This may or may not be the actual base. const workingBase = yield git.symbolicRef('HEAD', ['--short']); @@ -1077,7 +1077,12 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName if (yield git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.'); yield git.exec(['add', '-A']); - yield git.commit(['-m', commitMessage]); + if (signoff == true) { + yield git.commit(['-m', commitMessage, '-s']); + } + else { + yield git.commit(['-m', commitMessage]); + } } // Perform fetch and reset the working base // Commits made during the workflow will be removed @@ -1307,7 +1312,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', + signoff: core.getInput('signoff') === 'true' }; core.debug(`Inputs: ${util_1.inspect(inputs)}`); yield create_pull_request_1.createPullRequest(inputs); @@ -10578,7 +10584,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 create_or_update_branch_1.createOrUpdateBranch(git, inputs.commitMessage, inputs.base, inputs.branch, branchRemoteName); + const result = yield create_or_update_branch_1.createOrUpdateBranch(git, inputs.commitMessage, inputs.base, inputs.branch, branchRemoteName, inputs.signoff); core.endGroup(); if (['created', 'updated'].includes(result.action)) { // The branch was created or updated From ee482f51bde4d05171e37da16ac32f9b83d1f2bd Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 31 Jul 2020 16:56:04 +0900 Subject: [PATCH 5/8] Move input next to commit related inputs for context --- action.yml | 6 +++--- src/create-pull-request.ts | 2 +- src/main.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 6a65523..c306a7b 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,9 @@ inputs: The author name and email address in the format `Display Name `. Defaults to the user who triggered the workflow run. default: '${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>' + signoff: + description: 'Add `Signed-off-by` line by the committer at the end of the commit log message.' + default: false branch: description: 'The pull request branch name.' default: 'create-pull-request/patch' @@ -56,9 +59,6 @@ inputs: draft: description: 'Create a draft pull request' default: false - signoff: - description: 'Add "Signed-off-by" to commit message' - default: false outputs: pull-request-number: description: 'The pull request number' diff --git a/src/create-pull-request.ts b/src/create-pull-request.ts index 29a0e4a..23e00c6 100644 --- a/src/create-pull-request.ts +++ b/src/create-pull-request.ts @@ -11,6 +11,7 @@ export interface Inputs { commitMessage: string committer: string author: string + signoff: boolean branch: string branchSuffix: string base: string @@ -23,7 +24,6 @@ export interface Inputs { teamReviewers: string[] milestone: number draft: boolean - signoff: boolean } export async function createPullRequest(inputs: Inputs): Promise { diff --git a/src/main.ts b/src/main.ts index 1766428..7e7b017 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,6 +11,7 @@ async function run(): Promise { commitMessage: core.getInput('commit-message'), committer: core.getInput('committer'), author: core.getInput('author'), + signoff: core.getInput('signoff') === 'true', branch: core.getInput('branch'), branchSuffix: core.getInput('branch-suffix'), base: core.getInput('base'), @@ -22,8 +23,7 @@ async function run(): Promise { reviewers: utils.getInputAsArray('reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'), milestone: Number(core.getInput('milestone')), - draft: core.getInput('draft') === 'true', - signoff: core.getInput('signoff') === 'true' + draft: core.getInput('draft') === 'true' } core.debug(`Inputs: ${inspect(inputs)}`) From ba8309ff9c5fd6dd74e0150cdd257c20da23f010 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 31 Jul 2020 16:57:16 +0900 Subject: [PATCH 6/8] Refactor setting commit params --- dist/index.js | 13 ++++++------- src/create-or-update-branch.ts | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/dist/index.js b/dist/index.js index fee807c..687a1b3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1077,12 +1077,11 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName if (yield git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.'); yield git.exec(['add', '-A']); - if (signoff == true) { - yield git.commit(['-m', commitMessage, '-s']); - } - else { - yield git.commit(['-m', commitMessage]); + const params = ['-m', commitMessage]; + if (signoff) { + params.push('--signoff'); } + yield git.commit(params); } // Perform fetch and reset the working base // Commits made during the workflow will be removed @@ -1301,6 +1300,7 @@ function run() { commitMessage: core.getInput('commit-message'), committer: core.getInput('committer'), author: core.getInput('author'), + signoff: core.getInput('signoff') === 'true', branch: core.getInput('branch'), branchSuffix: core.getInput('branch-suffix'), base: core.getInput('base'), @@ -1312,8 +1312,7 @@ function run() { reviewers: utils.getInputAsArray('reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'), milestone: Number(core.getInput('milestone')), - draft: core.getInput('draft') === 'true', - signoff: core.getInput('signoff') === 'true' + draft: core.getInput('draft') === 'true' }; core.debug(`Inputs: ${util_1.inspect(inputs)}`); yield create_pull_request_1.createPullRequest(inputs); diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index 6a6435e..700cc14 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -100,11 +100,11 @@ export async function createOrUpdateBranch( if (await git.isDirty(true)) { core.info('Uncommitted changes found. Adding a commit.') await git.exec(['add', '-A']) - if (signoff == true) { - await git.commit(['-m', commitMessage, '-s']) - } else { - await git.commit(['-m', commitMessage]) + const params = ['-m', commitMessage] + if (signoff) { + params.push('--signoff') } + await git.commit(params) } // Perform fetch and reset the working base From 28fddffcf80e6d1a8ed1b0416da7fff9790259d2 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 31 Jul 2020 16:57:41 +0900 Subject: [PATCH 7/8] Add test for signoff --- __test__/create-or-update-branch.int.test.ts | 63 ++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/__test__/create-or-update-branch.int.test.ts b/__test__/create-or-update-branch.int.test.ts index d8db654..dfb01fd 100644 --- a/__test__/create-or-update-branch.int.test.ts +++ b/__test__/create-or-update-branch.int.test.ts @@ -757,6 +757,69 @@ describe('create-or-update-branch tests', () => { ).toBeTruthy() }) + it('tests create and update with signoff on commit', async () => { + // Create tracked and untracked file changes + const changes = await createChanges() + const commitMessage = uuidv4() + const result = await createOrUpdateBranch( + git, + commitMessage, + '', + BRANCH, + REMOTE_NAME, + true + ) + expect(result.action).toEqual('created') + expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) + expect(await getFileContent(UNTRACKED_FILE)).toEqual(changes.untracked) + expect( + await gitLogMatches([commitMessage, INIT_COMMIT_MESSAGE]) + ).toBeTruthy() + // Check signoff in commit body + const commitBody = ( + await git.exec(['log', `-1`, '--format=%b']) + ).stdout.trim() + expect(commitBody).toEqual( + 'Signed-off-by: Committer Name ' + ) + + // Push pull request branch to remote + await git.push([ + '--force-with-lease', + REMOTE_NAME, + `HEAD:refs/heads/${BRANCH}` + ]) + + await afterTest(false) + await beforeTest() + + // Create tracked and untracked file changes + const _changes = await createChanges() + const _commitMessage = uuidv4() + const _result = await createOrUpdateBranch( + git, + _commitMessage, + '', + BRANCH, + REMOTE_NAME, + true + ) + expect(_result.action).toEqual('updated') + expect(_result.hasDiffWithBase).toBeTruthy() + expect(await getFileContent(TRACKED_FILE)).toEqual(_changes.tracked) + expect(await getFileContent(UNTRACKED_FILE)).toEqual(_changes.untracked) + expect( + await gitLogMatches([_commitMessage, INIT_COMMIT_MESSAGE]) + ).toBeTruthy() + // Check signoff in commit body + const _commitBody = ( + await git.exec(['log', `-1`, '--format=%b']) + ).stdout.trim() + expect(_commitBody).toEqual( + 'Signed-off-by: Committer Name ' + ) + }) + // Working Base is Not Base (WBNB) it('tests no changes resulting in no new branch being created (WBNB)', async () => { From 64c8d492d5493036dc0a6290fdc29b65d82512c7 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 31 Jul 2020 16:59:26 +0900 Subject: [PATCH 8/8] Update documentation --- .github/workflows/cpr-example-command.yml | 1 + README.md | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpr-example-command.yml b/.github/workflows/cpr-example-command.yml index 00d793e..a545dfc 100644 --- a/.github/workflows/cpr-example-command.yml +++ b/.github/workflows/cpr-example-command.yml @@ -18,6 +18,7 @@ jobs: commit-message: Update report committer: GitHub author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + signoff: false title: '[Example] Update report' body: | Update report diff --git a/README.md b/README.md index 2106f3d..d916ac1 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ All inputs are **optional**. If not set, sensible defaults will be used. | `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>` | +| `signoff` | Add `Signed-off-by` line by the committer at the end of the commit log message. | `false` | | `branch` | The pull request branch name. | `create-pull-request/patch` | | `branch-suffix` | The branch suffix type when using the alternative branching strategy. Valid values are `random`, `timestamp` and `short-commit-hash`. See [Alternative strategy](#alternative-strategy---always-create-a-new-pull-request-branch) for details. | | | `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. | @@ -57,7 +58,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://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) may be required. See [this issue](https://github.com/peter-evans/create-pull-request/issues/155). | | | `milestone` | The number of the milestone to associate this pull request with. | | | `draft` | Create a [draft pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). | `false` | -| `signoff` | Add Signed-off-by to commit message | `false` | ### Action outputs @@ -157,7 +157,7 @@ To create a project card for the pull request, pass the `pull-request-number` st ## Reference Example -The following workflow is a reference example that sets all the main inputs. +The following workflow is a reference example that sets many of the main inputs. See [examples](docs/examples.md) for more realistic use cases. @@ -181,6 +181,7 @@ jobs: commit-message: Update report committer: GitHub author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + signoff: false branch: example-patches title: '[Example] Update report' body: |