Skip to content

Commit

Permalink
Update workflow
Browse files Browse the repository at this point in the history
Signed-off-by: KeisukeYamashita <[email protected]>
  • Loading branch information
KeisukeYamashita committed Jan 15, 2021
1 parent e9db431 commit 37070a5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: ./
id: merge
with:
intervalSeconds: 1
timeoutSeconds: 30
ignoreLabels: 'ignore'
- name: Create Comment
uses: KeisukeYamashita/create-comment@v1
with:
comment: ${{ steps.merge.outputs.merged }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
| --- | --- | --- |
| `checkStatus` | Check all status before merge' | `true` |
| `comment` | Comments to post before merging the pull request | - |
| `dryRun` | Dry run the merge or not | `false` |
| `failStep` | Fail the step if no PR has merged | `true` |
| `ignoreLabels` | Label that the target pull request shouldn't have | - |
| `ignoreLabelsStrategy` | Check condition on how to check the labels (Options are `all`, `atLeastOne`). | `all` |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
required: false
description: 'Comment before merge'
default: ''
dryRun:
required: false
description: 'Dry run'
default: 'false'
intervalSeconds:
required: false
description: 'Seconds between the check'
Expand Down
44 changes: 25 additions & 19 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.

1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async function run(): Promise<void> {
const inputs: Inputs = {
checkStatus: core.getInput('checkStatus') === 'true',
comment: core.getInput('comment'),
dryRun: core.getInput('dryRun') === 'true',
ignoreLabels:
core.getInput('ignoreLabels') === ''
? []
Expand Down
45 changes: 25 additions & 20 deletions src/merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type labelStrategies = 'all' | 'atLeastOne'
export interface Inputs {
checkStatus: boolean
comment: string
dryRun: boolean
ignoreLabels: string[]
ignoreLabelsStrategy: labelStrategies
failStep: boolean
Expand All @@ -27,7 +28,7 @@ export interface Inputs {
export type Strategy = 'merge' | 'squash' | 'rebase'

interface ValidationResult {
status: boolean
failed: boolean
message: string
}

Expand All @@ -52,16 +53,16 @@ export class Merger {
})
.map(label => label.name)

let status = true
let failed = true
if (type === 'labels' && hasLabels.length === labels.length) {
status = false
failed = false
}
if (type === 'ignoreLabels' && hasLabels.length) {
status = false
if (type === 'ignoreLabels' && !hasLabels.length) {
failed = false
}

return {
status,
failed,
message: `PR ${pr.id} ${
type === 'ignoreLabels' ? "does't" : ''
} contains all ${inspect(labels)}`
Expand All @@ -79,19 +80,19 @@ export class Merger {
})
.map(label => label.name)

let status = true
let failed = true
if (type === 'labels' && hasLabels.length) {
status = false
failed = false
}
if (type === 'ignoreLabels' && hasLabels.length) {
status = false
failed = false
}

return {
status,
failed,
message: `PR ${pr.id} ${
type === 'ignoreLabels' ? "does't" : ''
} contains ${labels}`
} contains ${inspect(labels)}`
}
}

Expand Down Expand Up @@ -131,7 +132,7 @@ export class Merger {
this.cfg.labelsStrategy,
'labels'
)
if (!labelResult.status) {
if (labelResult.failed) {
throw new Error(labelResult.message)
}

Expand All @@ -147,7 +148,7 @@ export class Merger {
this.cfg.ignoreLabelsStrategy,
'ignoreLabels'
)
if (!ignoreLabelResult.status) {
if (ignoreLabelResult.failed) {
throw new Error(ignoreLabelResult.message)
}

Expand Down Expand Up @@ -200,13 +201,17 @@ export class Merger {
core.setOutput(`commentID`, resp.id)
}

await client.pulls.merge({
owner,
repo,
pull_number: this.cfg.pullRequestNumber,
merge_method: this.cfg.strategy
})
core.setOutput('merged', true)
if (!this.cfg.dryRun) {
await client.pulls.merge({
owner,
repo,
pull_number: this.cfg.pullRequestNumber,
merge_method: this.cfg.strategy
})
core.setOutput('merged', true)
} else {
core.setOutput('merged', false)
}
} catch (err) {
core.debug(`Error on retry error:${inspect(err)}`)
if (this.cfg.failStep) {
Expand Down

0 comments on commit 37070a5

Please sign in to comment.