diff --git a/action.yml b/action.yml index ef3288b..cbec0bd 100644 --- a/action.yml +++ b/action.yml @@ -27,8 +27,9 @@ inputs: required: false body: description: > - Override the default generated PR body, the special string `{old_pull_request_id}` will be substituted - for the ID of the pull request which triggered the action + Override the default generated PR body. The special string `{old_pull_request_id}` will be substituted + for the ID of the pull request which triggered the action, and `{old_body}` will be substituted + for the body of the pull request which triggered the action. required: false labels: description: "A comma or newline separated list of labels." diff --git a/dist/index.js b/dist/index.js index a0b951b..0718fca 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9195,6 +9195,7 @@ function createPullRequest(inputs, prBranch) { // if the body comes from inputs, we replace {old_pull_request_id} // to make it easy to reference the previous pull request in the new body = body.replace('{old_pull_request_id}', pull_request.number.toString()); + body = body.replace('{old_body}', pull_request.body ?? ''); } core.info(`Using body '${body}'`); // Create PR @@ -9383,7 +9384,16 @@ function run() { } // Take whatever is suggested by git if there are conflicts yield gitExecution(['add', '.']) - yield gitExecution(['commit', "--no-edit"]) + + // only commit if there are changes + const status = yield gitExecution(['status', '--porcelain']); + if (status.stdout.trim().length === 0) { + core.info('Working tree clean; skipping commit.'); + } + else { + yield gitExecution(['commit', '--no-edit']); + } + core.endGroup(); // Push new branch core.startGroup('Push new branch to remote'); diff --git a/src/github-helper.ts b/src/github-helper.ts index ad00fd6..e08cf8f 100644 --- a/src/github-helper.ts +++ b/src/github-helper.ts @@ -58,6 +58,9 @@ export async function createPullRequest( '{old_pull_request_id}', pull_request.number.toString() ) + // replace {old_body} with the original PR body so callers can prepend + // or append text while still including the original description + body = body.replace('{old_body}', pull_request.body ?? '') } core.info(`Using body '${body}'`) diff --git a/src/index.ts b/src/index.ts index 799d355..dfe4518 100644 --- a/src/index.ts +++ b/src/index.ts @@ -75,7 +75,15 @@ export async function run(): Promise { } // Take whatever is suggested by git if there are conflicts await gitExecution(['add', '.']) - await gitExecution(['commit']) + + // only commit if there are changes + const status = await gitExecution(['status', '--porcelain']) + if (status.stdout.trim().length === 0) { + core.info('Working tree clean; skipping commit.') + } else { + await gitExecution(['commit', '--no-edit']) + } + core.endGroup() // Push new branch