Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/reward-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ title: '[Reward] '
labels:
- reward
body:
- type: markdown
attributes:
value: This form is created from https://github.com/idea2app/GitHub-reward

- type: textarea
id: description
attributes:
label: Task description
validations:
required: true

- type: input
id: source
attributes:
label: Task source
description: URL from an External System
placeholder: https://example.com/task/123

- type: dropdown
id: currency
attributes:
Expand Down
26 changes: 18 additions & 8 deletions .github/scripts/count-reward.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { changeMonth, formatDate, makeDateRange } from 'npm:web-utility';
import { $, YAML } from 'npm:zx';

import { Reward } from './type.ts';
Expand All @@ -6,20 +7,26 @@ $.verbose = true;

const rawTags = await $`git tag --list "reward-*" --format="%(refname:short) %(creatordate:short)"`;

const lastMonth = new Date();
lastMonth.setMonth(lastMonth.getMonth() - 1);
const lastMonthStr = lastMonth.toJSON().slice(0, 7);
const [startDate, endDate] = makeDateRange(formatDate(changeMonth(Date.now(), -1), 'YYYY-MM'));

const rewardTags = rawTags.stdout
.split('\n')
.filter(line => line.split(/\s+/)[1] >= lastMonthStr)
.filter(line => {
const thisDate = new Date(line.split(/\s+/)[1]);

return startDate <= thisDate && thisDate < endDate;
})
.map(line => line.split(/\s+/)[0]);

let rawYAML = '';

for (const tag of rewardTags) rawYAML += (await $`git tag -l --format="%(contents)" ${tag}`) + '\n';

if (!rawYAML.trim()) throw new ReferenceError('No reward data is found for the last month.');
if (!rawYAML.trim()) {
console.warn('No reward data is found for the last month.');

process.exit(0);
}

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

Expand Down Expand Up @@ -48,10 +55,13 @@ console.log(summaryText);

const tagName = `statistic-${new Date().toJSON().slice(0, 7)}`;

await $`git config --global user.name "github-actions[bot]"`;
await $`git config --global user.email "github-actions[bot]@users.noreply.github.com"`;
await $`git config user.name "github-actions[bot]"`;
await $`git config user.email "github-actions[bot]@users.noreply.github.com"`;

await $`git tag -a ${tagName} $(git rev-parse HEAD) -m ${summaryText}`;
await $`git push origin --tags`;
await $`git push origin ${tagName} --no-verify`;

await $`git config unset user.name`;
await $`git config unset user.email`;

await $`gh release create ${tagName} --notes ${summaryText}`;
49 changes: 34 additions & 15 deletions .github/scripts/share-reward.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'npm:array-unique-proposal';

import { components } from 'npm:@octokit/openapi-types';
import { $, argv, YAML } from 'npm:zx';

Comment on lines +1 to 5
Expand All @@ -12,28 +14,37 @@ const [
payer, // GitHub username of the payer (provided by workflow, defaults to issue creator)
currency,
reward,
source,
] = argv._;

interface PRMeta {
author: components['schemas']['simple-user'];
assignees: components['schemas']['simple-user'][];
}

const PR_DATA = await $`gh api graphql -f query='{
repository(owner: "${repositoryOwner}", name: "${repositoryName}") {
issue(number: ${issueNumber}) {
closedByPullRequestsReferences(first: 10) {
nodes {
url
merged
mergeCommit {
oid
const graphqlQuery = `
query($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
issue(number: $number) {
closedByPullRequestsReferences(first: 10) {
nodes {
url
merged
mergeCommit {
oid
}
}
}
}
}
}
}' --jq '.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.merged == true) | {url: .url, mergeCommitSha: .mergeCommit.oid}' | head -n 1`;
`;
const PR_DATA = await $`gh api graphql \
-f query=${graphqlQuery} \
-f owner=${repositoryOwner} \
-f name=${repositoryName} \
-F number=${issueNumber} \
--jq '.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.merged == true) | {url: .url, mergeCommitSha: .mergeCommit.oid}' | head -n 1`;

const prData = PR_DATA.text().trim();

Expand All @@ -60,7 +71,8 @@ function isBotUser(login: string) {
}

// Filter out Bot users from the list
const allUsers = [author.login, ...assignees.map(({ login }) => login)];
const allUsers = [author.login, ...assignees.map(({ login }) => login)].uniqueBy();

Comment on lines +74 to +75
const users = allUsers.filter(login => !isBotUser(login));

console.log(`All users: ${allUsers.join(', ')}`);
Expand All @@ -86,15 +98,22 @@ const list: Reward[] = users.map(login => ({
payee: `@${login}`,
currency,
reward: parseFloat(averageReward),
source,
}));
const listText = YAML.stringify(list);

console.log(listText);

await $`git config --global user.name "github-actions[bot]"`;
await $`git config --global user.email "github-actions[bot]@users.noreply.github.com"`;
await $`git tag -a "reward-${issueNumber}" ${mergeCommitSha} -m ${listText}`;
await $`git push origin --tags`;
const tagName = `reward-${issueNumber}`;

await $`git config user.name "github-actions[bot]"`;
await $`git config user.email "github-actions[bot]@users.noreply.github.com"`;

await $`git tag -a ${tagName} ${mergeCommitSha} -m ${listText}`;
await $`git push origin ${tagName} --no-verify`;

await $`git config unset user.name`;
await $`git config unset user.email`;

const commentBody = `## Reward data

Expand Down
1 change: 1 addition & 0 deletions .github/scripts/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface Reward {
payee: string;
currency: string;
reward: number;
source?: string;
}
10 changes: 4 additions & 6 deletions .github/workflows/Lark-notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ jobs:

- name: Event Message serialization
id: message
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: |
CARD_JSON=$(
cat <<JSON | deno run --allow-all .github/scripts/transform-message.ts
${{ toJSON(github) }}
JSON
)
YAML=$(printf '%s' "$GITHUB_CONTEXT" | deno run --allow-all .github/scripts/transform-message.ts)
{
echo 'content<<EOF'
echo "$CARD_JSON"
echo "$YAML"
echo 'EOF'
} >> "$GITHUB_OUTPUT"

Expand Down
27 changes: 17 additions & 10 deletions .github/workflows/claim-issue-reward.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,45 @@ on:
issues:
types:
- closed
env:
GH_TOKEN: ${{ github.token }}

concurrency:
group: claim-issue-reward-${{ github.event.issue.number }}
cancel-in-progress: false

jobs:
claim-issue-reward:
runs-on: ubuntu-latest
if: contains(github.event.issue.labels.*.name, 'reward')
permissions:
contents: write
issues: write
pull-requests: read
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
fetch-tags: true

- uses: denoland/setup-deno@v2
- uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4
with:
deno-version: v2.x

- name: Get Issue details
id: parse_issue
uses: stefanbuck/github-issue-parser@v3
uses: stefanbuck/github-issue-parser@10dcc54158ba4c137713d9d69d70a2da63b6bda3 # v3.2.3
with:
template-path: '.github/ISSUE_TEMPLATE/reward-task.yml'

- name: Calculate & Save Reward
env:
GH_TOKEN: ${{ github.token }}
run: |
deno --allow-all .github/scripts/share-reward.ts \
${{ github.repository_owner }} \
${{ github.event.repository.name }} \
${{ github.event.issue.number }} \
deno --allow-run --allow-sys --allow-env --allow-read --allow-net=api.github.com \
.github/scripts/share-reward.ts \
Comment on lines +39 to +40
"${{ github.repository_owner }}" \
"${{ github.event.repository.name }}" \
"${{ github.event.issue.number }}" \
"${{ steps.parse_issue.outputs.issueparser_payer || github.event.issue.user.login }}" \
"${{ steps.parse_issue.outputs.issueparser_currency }}" \
${{ steps.parse_issue.outputs.issueparser_amount }}
"${{ steps.parse_issue.outputs.issueparser_amount }}" \
"${{ steps.parse_issue.outputs.issueparser_source || '' }}"
10 changes: 5 additions & 5 deletions .github/workflows/statistic-member-reward.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ name: Statistic Member Reward
on:
schedule:
- cron: '0 0 1 * *' # Run at 00:00 on the first day of every month
env:
GH_TOKEN: ${{ github.token }}

jobs:
statistic-member-reward:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
fetch-tags: true
Expand All @@ -33,11 +31,13 @@ jobs:
echo "NEW_COMMITS=true" >> $GITHUB_ENV
fi
fi
- uses: denoland/setup-deno@v2
- uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4
if: env.NEW_COMMITS == 'true'
with:
deno-version: v2.x

- name: Statistic rewards
if: env.NEW_COMMITS == 'true'
run: deno --allow-all .github/scripts/count-reward.ts
env:
GH_TOKEN: ${{ github.token }}
run: deno --allow-run --allow-sys --allow-env --allow-read --allow-net=api.github.com .github/scripts/count-reward.ts
Comment on lines +41 to +43
2 changes: 1 addition & 1 deletion components/Organization/Landscape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class OpenCollaborationLandscape extends Component<OpenCollaborationLands
<ul className={`list-unstyled d-flex flex-${screenNarrow ? 'column' : 'row'} gap-2`}>
{row.map(([name, list]) => (
<li key={name} className="flex-fill">
<h2 className={`h5 p-2 text-white ${styles.groupTitle}`}>{name}</h2>
<h2 className={`h5 p-2 text-nowrap text-white ${styles.groupTitle}`}>{name}</h2>

<ol className="list-unstyled d-flex flex-wrap gap-2">
{list.map(this.renderLogo)}
Expand Down
Loading
Loading