Skip to content

Commit f50553f

Browse files
committed
feat(reward): support custom reward content instead of fixed currency/amount
1 parent e60c211 commit f50553f

5 files changed

Lines changed: 12 additions & 42 deletions

File tree

‎.github/ISSUE_TEMPLATE/reward-task.yml‎

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,12 @@ body:
2222
description: URL from an External System
2323
placeholder: https://example.com/task/123
2424

25-
- type: dropdown
26-
id: currency
27-
attributes:
28-
label: Reward currency
29-
options:
30-
- 'USD $'
31-
- 'CAD C$'
32-
- 'AUD A$'
33-
- 'GBP £'
34-
- 'EUR €'
35-
- 'CNY ¥'
36-
- 'HKD HK$'
37-
- 'TWD NT$'
38-
- 'SGD S$'
39-
- 'KRW ₩'
40-
- 'JPY ¥'
41-
- 'INR ₹'
42-
- 'UAH ₴'
43-
validations:
44-
required: true
45-
4625
- type: input
47-
id: amount
26+
id: reward
4827
attributes:
49-
label: Reward amount
28+
label: Reward
29+
description: Please enter the reward details (e.g. 500 CNY, 50 USD, Exclusive Badge, Custom Gift)
30+
placeholder: 500 CNY / Official Badge
5031
validations:
5132
required: true
5233

‎.github/scripts/count-reward.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ const groupedRewards = Object.groupBy(rewards, ({ payee }) => payee);
3737

3838
const summaryList = Object.entries(groupedRewards).map(([payee, rewards]) => {
3939
const reward = rewards!.reduce(
40-
(acc, { currency, reward }) => {
41-
acc[currency] ??= 0;
42-
acc[currency] += reward;
40+
(acc, { reward }) => {
41+
// For custom reward string, we just append to an array or store uniquely
42+
// Since it's a string, we map it as count of strings or list of strings
43+
acc[reward] ??= 0;
44+
acc[reward] += 1;
4345
return acc;
4446
},
4547
{} as Record<string, number>,

‎.github/scripts/share-reward.ts‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const [
1212
repositoryName,
1313
issueNumber,
1414
payer, // GitHub username of the payer (provided by workflow, defaults to issue creator)
15-
currency,
1615
reward,
1716
source,
1817
] = argv._;
@@ -88,21 +87,11 @@ if (!users[0])
8887
"No real users found (all users are bots). Skipping reward distribution.",
8988
);
9089

91-
const rewardNumber = parseFloat(reward);
92-
93-
if (isNaN(rewardNumber) || rewardNumber <= 0)
94-
throw new RangeError(
95-
`Reward amount is not a valid number, can not proceed with reward distribution. Received reward value: ${reward}`,
96-
);
97-
98-
const averageReward = (rewardNumber / users.length).toFixed(2);
99-
10090
const list: Reward[] = users.map((login) => ({
10191
issue: `#${issueNumber}`,
10292
payer: `@${payer}`,
10393
payee: `@${login}`,
104-
currency,
105-
reward: parseFloat(averageReward),
94+
reward: String(reward),
10695
source,
10796
}));
10897
const listText = YAML.stringify(list);

‎.github/scripts/type.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export interface Reward {
22
issue: string;
33
payer: string;
44
payee: string;
5-
currency: string;
6-
reward: number;
5+
reward: string;
76
source?: string;
87
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@ jobs:
4242
"${{ github.event.repository.name }}" \
4343
"${{ github.event.issue.number }}" \
4444
"${{ steps.parse_issue.outputs.issueparser_payer || github.event.issue.user.login }}" \
45-
"${{ steps.parse_issue.outputs.issueparser_currency }}" \
46-
"${{ steps.parse_issue.outputs.issueparser_amount }}" \
45+
"${{ steps.parse_issue.outputs.issueparser_reward }}" \
4746
"${{ steps.parse_issue.outputs.issueparser_source || '' }}"

0 commit comments

Comments
 (0)