Skip to content

Commit 1638b32

Browse files
Create calculate-final-score.yml
1 parent 5cf3160 commit 1638b32

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
name: "Finalize Nomination Ranking"
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
finalize-decision:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Calculate Average Score from Comments & Approve/Reject
12+
uses: actions/github-script@v6
13+
with:
14+
github-token: ${{ secrets.GITHUB_TOKEN }}
15+
script: |
16+
const issue_number = context.payload.issue.number;
17+
const repo = context.repo.repo;
18+
const owner = context.repo.owner;
19+
20+
// Get all comments on the issue
21+
const comments = await github.rest.issues.listComments({
22+
owner,
23+
repo,
24+
issue_number
25+
});
26+
27+
const scoreRegex = /^score:\s*(\d)/i;
28+
let totalScore = 0;
29+
let numScores = 0;
30+
31+
const seenUsers = new Set();
32+
33+
comments.data.forEach(comment => {
34+
const match = comment.body.match(scoreRegex);
35+
if (match) {
36+
const score = parseInt(match[1]);
37+
const author = comment.user.login;
38+
39+
if (!seenUsers.has(author) && score >= 1 && score <= 5) {
40+
totalScore += score;
41+
numScores++;
42+
seenUsers.add(author);
43+
}
44+
}
45+
});
46+
47+
if (numScores === 0) {
48+
console.log("No valid scores found.");
49+
return;
50+
}
51+
52+
const average = totalScore / numScores;
53+
console.log(`Average score is ${average} based on ${numScores} unique reviewers.`);
54+
55+
const finalLabel = average >= 3.0 ? "approved" : "rejected";
56+
57+
await github.rest.issues.addLabels({
58+
owner,
59+
repo,
60+
issue_number,
61+
labels: [finalLabel]
62+
});
63+
64+
await github.rest.issues.createComment({
65+
owner,
66+
repo,
67+
issue_number,
68+
body: `🧮 Average score from ${numScores} reviewers: **${average.toFixed(2)}**. Final decision: **${finalLabel.toUpperCase()}**.`
69+
});

0 commit comments

Comments
 (0)