Skip to content
Merged
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
17 changes: 8 additions & 9 deletions .github/workflows/approvals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ jobs:
pull_number: pr.number,
});

// Count unique human approvals (latest review per user)
// Determine if PR author is a bot/GitHub Actions
const authorType = pr.user.type; // 'Bot' vs 'User'
const authorLogin = pr.user.login; // e.g. 'github-actions[bot]'
const isBot = authorType === 'Bot' || authorLogin.endsWith('[bot]');
const oneApprovalBotAuthors = new Set(['renovate[bot]']);

// Count unique approvals, including bot approvals.
const latestByUser = {};
for (const review of reviews.data) {
if (review.user.type === 'Bot') continue;
latestByUser[review.user.login] = review.state;
}
const approvalCount = Object.values(latestByUser)
.filter(state => state === 'APPROVED').length;

// Determine if PR author is a bot/GitHub Actions
const authorType = pr.user.type; // 'Bot' vs 'User'
const authorLogin = pr.user.login; // e.g. 'github-actions[bot]'
const isBot = authorType === 'Bot' || authorLogin.endsWith('[bot]');
const oneApprovalBotAuthors = new Set(['renovate[bot]']);

const required = isBot && !oneApprovalBotAuthors.has(authorLogin) ? 2 : 1;

console.log(`PR author: ${authorLogin} (${authorType}), isBot: ${isBot}`);
Expand All @@ -46,7 +45,7 @@ jobs:

if (isBot && (approvalCount < required)) {
core.setFailed(
`This PR needs ${required} human approval(s) but has ${approvalCount}. ` +
`This PR needs ${required} approval(s) but has ${approvalCount}. ` +
`(Author is ${isBot ? 'a bot' : 'human'})`
);
}
Loading