Skip to content

Commit

Permalink
Merge pull request #21 from comnoco/feat/github-nodejs20
Browse files Browse the repository at this point in the history
Update to work on node20
  • Loading branch information
tomoconnor authored Sep 25, 2024
2 parents 598d83c + cc20326 commit d1dfcbe
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 65 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ inputs:
description: 'Authorization Token for accessing GitHub'
required: true
runs:
using: 'node16'
using: 'node20'
main: 'index.js'
129 changes: 65 additions & 64 deletions index.js
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();

0 comments on commit d1dfcbe

Please sign in to comment.