Skip to content

Commit

Permalink
Add option to use pull request title as commit message.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Sep 22, 2020
1 parent d6492cb commit 36c2ac3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ jobs:
- uses: ./
with:
token: ${{ secrets.MY_GITHUB_TOKEN }}
squash-title: true
do-not-merge-labels: never-merge
pull-request: ${{ github.event.inputs.pull-request }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Auto-merging is enabled for a branch given the following criteria:
|------|-----------|-------------|
| `token` | yes | A GitHub Token other than the default `GITHUB_TOKEN` needs to be specified in order to be able to trigger other workflows. |
| `merge-method` | no | Specify which merge method to use. By default, will select the first one available in this order: `merge`, `squash`, `rebase` |
| `squash-title` | no | Use the pull request title as the commit message when squashing. |
| `do-not-merge-labels` | no | When any of the labels in this comma-separated list is applied to a pull request, it will not be merged automatically. |
| `pull-request` | no | Try merging the specified pull request automatically. For example, you can pass an input from a `workflow_dispatch` event. |
| `dry-run` | no | If set to `true`, will not actually merge pull requests but still perform all other checks. |
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ inputs:
description: >
Specify which merge method to use. By default, will select the first one
available in this order: `merge`, `squash`, `rebase`
squash-title:
required: false
description: >
Use the pull request title as the commit message when squashing.
default: false
do-not-merge-labels:
required: false
description: >
Expand Down
20 changes: 12 additions & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions src/automerge-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,29 @@ export class AutomergeAction {

const mergeMethod = await this.determineMergeMethod()

try {
if (this.input.dryRun) {
core.info(`Would try merging pull request ${number}.`)
} else {
core.info(`Merging pull request ${number}:`)
const useTitle = this.input.squashTitle && mergeMethod === 'squash'
const commitTitle = useTitle ? `${pullRequest.title} (#${pullRequest.number})\n` : undefined
const commitMessage = useTitle ? '\n' : undefined

await this.octokit.pulls.merge({
...github.context.repo,
pull_number: number,
sha: pullRequest.head.sha,
merge_method: mergeMethod,
})
const titleMessage = useTitle ? ` with title '${commitTitle}'` : undefined

core.info(`Successfully merged pull request ${number}.`)
}
if (this.input.dryRun) {
core.info(`Would try merging pull request ${number}${titleMessage}.`)
return false
}

try {
core.info(`Merging pull request ${number}${titleMessage}:`)
await this.octokit.pulls.merge({
...github.context.repo,
pull_number: number,
sha: pullRequest.head.sha,
merge_method: mergeMethod,
commit_title: commitTitle,
commit_message: commitMessage,
})

core.info(`Successfully merged pull request ${number}.`)

return false
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function getNumber(input: string, options?: core.InputOptions): number | null {
export class Input {
token: string
mergeMethod: MergeMethod
squashTitle: boolean
doNotMergeLabels: string[]
pullRequest: number | null
dryRun: boolean
Expand All @@ -42,6 +43,7 @@ export class Input {
}
}

this.squashTitle = core.getInput('squash-title') === 'true'
this.doNotMergeLabels = core.getInput('do-not-merge-labels').split(',')
this.pullRequest = getNumber('pull-request')
this.dryRun = core.getInput('dry-run') === 'true'
Expand Down

0 comments on commit 36c2ac3

Please sign in to comment.