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/4] 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/4] 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/4] 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/4] 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