Skip to content

Commit 4d2e386

Browse files
Update calculate-final-score.yml
1 parent 1638b32 commit 4d2e386

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

.github/workflows/calculate-final-score.yml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ jobs:
2727
const scoreRegex = /^score:\s*(\d)/i;
2828
let totalScore = 0;
2929
let numScores = 0;
30-
30+
const reviewers = [];
3131
const seenUsers = new Set();
3232
3333
comments.data.forEach(comment => {
3434
const match = comment.body.match(scoreRegex);
35-
if (match) {
36-
const score = parseInt(match[1]);
37-
const author = comment.user.login;
35+
const author = comment.user.login;
3836
39-
if (!seenUsers.has(author) && score >= 1 && score <= 5) {
37+
if (match && !seenUsers.has(author)) {
38+
const score = parseInt(match[1]);
39+
if (score >= 1 && score <= 5) {
4040
totalScore += score;
4141
numScores++;
4242
seenUsers.add(author);
43+
reviewers.push(`@${author}`);
4344
}
4445
}
4546
});
@@ -50,20 +51,38 @@ jobs:
5051
}
5152
5253
const average = totalScore / numScores;
53-
console.log(`Average score is ${average} based on ${numScores} unique reviewers.`);
54-
5554
const finalLabel = average >= 3.0 ? "approved" : "rejected";
55+
const oppositeLabel = finalLabel === "approved" ? "rejected" : "approved";
56+
57+
// Remove opposite label if it exists
58+
const existingLabels = (await github.rest.issues.get({
59+
owner,
60+
repo,
61+
issue_number
62+
})).data.labels.map(label => label.name);
63+
64+
if (existingLabels.includes(oppositeLabel)) {
65+
await github.rest.issues.removeLabel({
66+
owner,
67+
repo,
68+
issue_number,
69+
name: oppositeLabel
70+
});
71+
}
5672
73+
// Add the correct outcome label
5774
await github.rest.issues.addLabels({
5875
owner,
5976
repo,
6077
issue_number,
6178
labels: [finalLabel]
6279
});
6380
81+
// Post comment with reviewer names and score summary
82+
const reviewersList = reviewers.join(", ");
6483
await github.rest.issues.createComment({
6584
owner,
6685
repo,
6786
issue_number,
68-
body: `🧮 Average score from ${numScores} reviewers: **${average.toFixed(2)}**. Final decision: **${finalLabel.toUpperCase()}**.`
87+
body: `🧮 Average score from ${numScores} reviewer(s): **${average.toFixed(2)}**\n👥 Reviewed by: ${reviewersList}\n📌 Final decision: **${finalLabel.toUpperCase()}**`
6988
});

0 commit comments

Comments
 (0)