Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 0 additions & 234 deletions .github/scripts/bot-on-commit.js

This file was deleted.

71 changes: 71 additions & 0 deletions .github/scripts/bot-on-pr-open.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: Apache-2.0
//
// bot-on-pr-open.js
//
// Runs when a PR is opened, reopened, or converted from draft (ready_for_review).
// Performs all 4 checks (DCO, GPG, merge conflict, issue link), posts/updates
// the unified dashboard comment, auto-assigns the author, and applies the
// appropriate status label.

const {
createLogger,
buildBotContext,
addAssignees,
requireSafeUsername,
runAllChecksAndComment,
swapStatusLabel,
} = require('./helpers');

const logger = createLogger('on-pr-open');

/**
* Auto-assigns the PR author if not already assigned.
* @param {object} botContext
*/
async function autoAssignAuthor(botContext) {
const prAuthor = botContext.pr?.user?.login;
if (!prAuthor) {
logger.log('Exit: missing pull request author');
return;
}
try {
requireSafeUsername(prAuthor, 'pr.author');
} catch (err) {
logger.log('Exit: invalid pr.author', err.message);
return;
}

const currentAssignees = botContext.pr?.assignees || [];
const isAlreadyAssigned = currentAssignees.some(
(a) => (a?.login || '').toLowerCase() === prAuthor.toLowerCase()
);
if (isAlreadyAssigned) {
logger.log(`Author ${prAuthor} is already assigned`);
return;
}
await addAssignees(botContext, [prAuthor]);
}

module.exports = async ({ github, context }) => {
try {
const botContext = buildBotContext({ github, context });

await autoAssignAuthor(botContext);

if (botContext.pr?.user?.type === 'Bot') {
logger.log('Skipping bot-authored PR');
return;
}

const { allPassed } = await runAllChecksAndComment(botContext);
await swapStatusLabel(botContext, allPassed, { force: true });

logger.log('On-PR-open bot completed');
} catch (error) {
logger.error('Error:', {
message: error.message,
number: context?.payload?.pull_request?.number,
});
throw error;
}
};
45 changes: 45 additions & 0 deletions .github/scripts/bot-on-pr-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: Apache-2.0
//
// bot-on-pr-update.js
//
// Runs on new commits (synchronize) and PR body edits (edited). Performs all
// 4 checks (DCO, GPG, merge conflict, issue link), posts/updates the unified
// dashboard comment, and conditionally swaps the status label.
// For edited events, exits early if only the title or base branch changed.

const {
createLogger,
buildBotContext,
swapStatusLabel,
runAllChecksAndComment,
} = require('./helpers');

const logger = createLogger('on-pr-update');

module.exports = async ({ github, context }) => {
try {
const botContext = buildBotContext({ github, context });

if (botContext.pr?.user?.type === 'Bot') {
logger.log('Skipping bot-authored PR');
return;
}

// Edits can be triggered by title changes, but we only care about body changes.
if (context.payload.action === 'edited' && !context.payload.changes?.body) {
logger.log('Body not changed, skipping');
return;
}

const { allPassed } = await runAllChecksAndComment(botContext);
await swapStatusLabel(botContext, allPassed);

logger.log('On-PR-update bot completed');
} catch (error) {
logger.error('Error:', {
message: error.message,
number: context?.payload?.pull_request?.number,
});
throw error;
}
};
Loading
Loading