Skip to content

Commit f4d8a0d

Browse files
committed
[add] Payer accounts data
[fix] some Empty Value bugs
1 parent 64f8b49 commit f4d8a0d

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

.github/ISSUE_TEMPLATE/reward-task.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Reward Task
1+
name: 💰 Reward Task
22
description: Task issue with Reward
33
title: '[Reward] '
44
labels:

.github/scripts/count-reward.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,27 @@ const rewardTags = rawTags.stdout
1919
let rawYAML = "";
2020

2121
for (const tag of rewardTags)
22-
rawYAML += await $`git tag -l --format="%(contents)" ${tag}`;
22+
rawYAML += (await $`git tag -l --format="%(contents)" ${tag}`) + "\n";
23+
24+
if (!rawYAML.trim())
25+
throw new ReferenceError("No reward data is found for the last month.");
2326

2427
const rewards = YAML.parse(rawYAML) as Reward[];
2528

26-
const groupedRewards = Object.groupBy(rewards, ({ id }) => id);
29+
const groupedRewards = Object.groupBy(rewards, ({ payee }) => payee);
2730

28-
const summaryList = Object.entries(groupedRewards).map(([id, rewards]) => {
31+
const summaryList = Object.entries(groupedRewards).map(([payee, rewards]) => {
2932
const reward = rewards!.reduce((acc, { currency, reward }) => {
3033
acc[currency] ??= 0;
3134
acc[currency] += reward;
3235
return acc;
3336
}, {} as Record<string, number>);
3437

35-
return { id, reward };
38+
return {
39+
payee,
40+
reward,
41+
accounts: rewards!.map(({ payee: _, ...account }) => account),
42+
};
3643
});
3744

3845
const summaryText = YAML.stringify(summaryList);

.github/scripts/share-reward.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import { Reward } from "./type.ts";
55

66
$.verbose = true;
77

8-
const [repositoryOwner, repositoryName, issueNumber, currency, reward] = argv._;
8+
const [
9+
repositoryOwner,
10+
repositoryName,
11+
issueNumber,
12+
issueAuthor,
13+
currency,
14+
reward,
15+
] = argv._;
916

1017
interface PRMeta {
1118
author: components["schemas"]["simple-user"];
@@ -25,6 +32,9 @@ const PR_URL = await $`gh api graphql -f query='{
2532
}
2633
}' --jq '.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.merged == true) | .url' | head -n 1`;
2734

35+
if (!PR_URL.text().trim())
36+
throw new ReferenceError("No merged PR is found for the given issue number.");
37+
2838
const { author, assignees }: PRMeta = await (
2939
await $`gh pr view ${PR_URL} --json author,assignees`
3040
).json();
@@ -34,7 +44,9 @@ const users = [author.login, ...assignees.map(({ login }) => login)];
3444
const averageReward = (parseFloat(reward) / users.length).toFixed(2);
3545

3646
const list: Reward[] = users.map((login) => ({
37-
id: `@${login}`,
47+
issue: `#${issueNumber}`,
48+
payer: `@${issueAuthor}`,
49+
payee: `@${login}`,
3850
currency,
3951
reward: parseFloat(averageReward),
4052
}));

.github/scripts/type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export interface Reward {
2-
id: string;
2+
issue: string;
3+
payer: string;
4+
payee: string;
35
currency: string;
46
reward: number;
57
}

.github/workflows/claim-issue-reward.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ jobs:
3535
${{ github.repository_owner }} \
3636
${{ github.event.repository.name }} \
3737
${{ github.event.issue.number }} \
38+
${{ github.event.issue.user.login }} \
3839
"${{ steps.parse_issue.outputs.issueparser_currency }}" \
3940
${{ steps.parse_issue.outputs.issueparser_amount }} \
40-
reward.yml

0 commit comments

Comments
 (0)