forked from squalrus/merge-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from comnoco/feat/github-nodejs20
Update to work on node20
- Loading branch information
Showing
2 changed files
with
66 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,87 @@ | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
const { context, getOctokit } = require('@actions/github'); | ||
|
||
const Config = require('./lib/config') | ||
const Pull = require('./lib/pull'); | ||
const renderMessage = require('./lib/message'); | ||
|
||
async function run() { | ||
try { | ||
console.log(`action: ${github.context.payload.action}`); | ||
console.log(`[data] payload: ${JSON.stringify(github.context.payload)}`); | ||
try { | ||
console.log(`action: ${context.payload.action}`); | ||
console.log(`[data] payload: ${JSON.stringify(context.payload)}`); | ||
|
||
const config = new Config(core); | ||
console.log(`[data] config: ${JSON.stringify(config)}`); | ||
const config = new Config(core); | ||
console.log(`[data] config: ${JSON.stringify(config)}`); | ||
|
||
const pull = new Pull(github.context.payload); | ||
console.log(`[data] pull (payload): ${JSON.stringify(pull)}`); | ||
const pull = new Pull(context.payload); | ||
console.log(`[data] pull (payload): ${JSON.stringify(pull)}`); | ||
|
||
const token = core.getInput('GITHUB_TOKEN'); | ||
const octokit = new github.getOctokit(token); | ||
|
||
console.log(`[info] get reviews`); | ||
const reviews = await octokit.pulls.listReviews({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
pull_number: pull.pull_number | ||
}); | ||
const token = core.getInput('GITHUB_TOKEN'); | ||
const octokit = getOctokit(token); | ||
|
||
console.log(`[info] get checks`); | ||
const checks = await octokit.checks.listForRef({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
ref: pull.branch_name | ||
}); | ||
console.log(`[info] get reviews`); | ||
const reviews = await octokit.pulls.listReviews({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
pull_number: pull.pull_number | ||
}); | ||
|
||
pull.compileReviews(reviews); | ||
pull.compileChecks(checks); | ||
console.log(`[data] pull (checks + reviews): ${JSON.stringify(pull)}`); | ||
console.log(`[info] get checks`); | ||
const checks = await octokit.checks.listForRef({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
ref: pull.branch_name | ||
}); | ||
|
||
console.log(`merge: ${pull.canMerge(config)}`); | ||
pull.compileReviews(reviews); | ||
pull.compileChecks(checks); | ||
console.log(`[data] pull (checks + reviews): ${JSON.stringify(pull)}`); | ||
|
||
if (config.test_mode) { | ||
console.log(`merge: ${pull.canMerge(config)}`); | ||
|
||
// comment in test mode | ||
await octokit.issues.createComment({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
issue_number: pull.pull_number, | ||
body: renderMessage(github.context.payload.action, config, pull) | ||
}); | ||
if (config.test_mode) { | ||
|
||
// comment in test mode | ||
await octokit.issues.createComment({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
issue_number: pull.pull_number, | ||
body: renderMessage(github.context.payload.action, config, pull) | ||
}); | ||
|
||
} else { | ||
if (pull.canMerge(config)) { | ||
|
||
// merge the pull request | ||
console.log(`[info] merge start`); | ||
await octokit.pulls.merge({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
pull_number: pull.pull_number, | ||
merge_method: config.merge_method | ||
}); | ||
console.log(`[info] merge complete`); | ||
|
||
if (config.delete_source_branch) { | ||
if (pull.headRepoId !== pull.baseRepoId) { | ||
console.log(`[warning] unable to delete branch from fork, branch retained`); | ||
} else { | ||
// delete the branch | ||
console.log(`[info] delete start`); | ||
await octokit.git.deleteRef({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
ref: pull.ref | ||
}); | ||
console.log(`[info] delete complete`); | ||
} | ||
} | ||
} | ||
} else { | ||
if (pull.canMerge(config)) { | ||
|
||
// merge the pull request | ||
console.log(`[info] merge start`); | ||
await octokit.pulls.merge({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
pull_number: pull.pull_number, | ||
merge_method: config.merge_method | ||
}); | ||
console.log(`[info] merge complete`); | ||
|
||
if (config.delete_source_branch) { | ||
if (pull.headRepoId !== pull.baseRepoId) { | ||
console.log(`[warning] unable to delete branch from fork, branch retained`); | ||
} else { | ||
// delete the branch | ||
console.log(`[info] delete start`); | ||
await octokit.git.deleteRef({ | ||
owner: pull.owner, | ||
repo: pull.repo, | ||
ref: pull.ref | ||
}); | ||
console.log(`[info] delete complete`); | ||
} | ||
} | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
run(); |