Skip to content

Commit 83c2689

Browse files
committed
[add] model & card component of Open Source Project
[fix] Git tag & commit relation of GitHub-reward
1 parent e63932a commit 83c2689

File tree

11 files changed

+120
-18
lines changed

11 files changed

+120
-18
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ NEXT_PUBLIC_LARK_WIKI_URL = https://open-source-bazaar.feishu.cn/wiki/space/7052
88

99
NEXT_PUBLIC_LARK_BITABLE_ID = PNOGbGqhPacsHOsvJqHctS77nje
1010
NEXT_PUBLIC_ACTIVITY_TABLE_ID = tblREEMxDOECZZrK
11+
NEXT_PUBLIC_PROJECT_TABLE_ID = tblGnY6Hm0nTSBR9
1112

1213
NEXT_PUBLIC_STRAPI_API_HOST = https://china-ngo-db.onrender.com/api/

.github/scripts/share-reward.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,37 @@ interface PRMeta {
1919
assignees: components['schemas']['simple-user'][];
2020
}
2121

22-
const PR_URL = await $`gh api graphql -f query='{
22+
const PR_DATA = await $`gh api graphql -f query='{
2323
repository(owner: "${repositoryOwner}", name: "${repositoryName}") {
2424
issue(number: ${issueNumber}) {
2525
closedByPullRequestsReferences(first: 10) {
2626
nodes {
2727
url
2828
merged
29+
mergeCommit {
30+
oid
31+
}
2932
}
3033
}
3134
}
3235
}
33-
}' --jq '.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.merged == true) | .url' | head -n 1`;
36+
}' --jq '.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.merged == true) | {url: .url, mergeCommitSha: .mergeCommit.oid}' | head -n 1`;
3437

35-
if (!PR_URL.text().trim())
36-
throw new ReferenceError('No merged PR is found for the given issue number.');
38+
const prData = PR_DATA.text().trim();
39+
40+
if (!prData) throw new ReferenceError('No merged PR is found for the given issue number.');
41+
42+
const { url: PR_URL, mergeCommitSha } = JSON.parse(prData);
43+
44+
if (!PR_URL || !mergeCommitSha) throw new Error('Missing required fields in PR data');
45+
46+
console.table({ PR_URL, mergeCommitSha });
3747

3848
const { author, assignees }: PRMeta = await (
3949
await $`gh pr view ${PR_URL} --json author,assignees`
4050
).json();
4151

42-
// Function to check if a user is a Copilot/bot user
43-
function isCopilotUser(login: string): boolean {
52+
function isBotUser(login: string) {
4453
const lowerLogin = login.toLowerCase();
4554
return (
4655
lowerLogin.includes('copilot') ||
@@ -50,19 +59,17 @@ function isCopilotUser(login: string): boolean {
5059
);
5160
}
5261

53-
// Filter out Copilot and bot users from the list
62+
// Filter out Bot users from the list
5463
const allUsers = [author.login, ...assignees.map(({ login }) => login)];
55-
const users = allUsers.filter(login => !isCopilotUser(login));
64+
const users = allUsers.filter(login => !isBotUser(login));
5665

5766
console.log(`All users: ${allUsers.join(', ')}`);
58-
console.log(`Filtered users (excluding bots/copilot): ${users.join(', ')}`);
67+
console.log(`Filtered users (excluding bots): ${users.join(', ')}`);
5968

60-
// Handle case where all users are bots/copilot
61-
if (users.length === 0) {
62-
console.log('No real users found (all users are bots/copilot). Skipping reward distribution.');
63-
console.log(`Filtered users: ${allUsers.join(', ')}`);
64-
process.exit(0);
65-
}
69+
if (!users[0])
70+
throw new ReferenceError(
71+
'No real users found (all users are bots). Skipping reward distribution.',
72+
);
6673

6774
const rewardNumber = parseFloat(reward);
6875

@@ -86,7 +93,7 @@ console.log(listText);
8693

8794
await $`git config --global user.name "github-actions[bot]"`;
8895
await $`git config --global user.email "github-actions[bot]@users.noreply.github.com"`;
89-
await $`git tag -a "reward-${issueNumber}" -m ${listText}`;
96+
await $`git tag -a "reward-${issueNumber}" ${mergeCommitSha} -m ${listText}`;
9097
await $`git push origin --tags`;
9198

9299
const commentBody = `## Reward data

components/Navigator/MainNavigator.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const topNavBarMenu = ({ t }: typeof i18n): MenuItem[] => [
3838
{
3939
title: t('open_source_projects'),
4040
subs: [
41-
{ href: '/project', title: t('open_source_projects') },
41+
{ href: '/project', title: t('self_developed_projects') },
42+
{ href: '/search/project', title: t('bazaar_projects') },
4243
{ href: '/issue', title: 'GitHub issues' },
4344
{ href: '/license-filter', title: t('license_filter') },
4445
{ href: '/finance', title: t('finance_page_title') },

components/Project/Card.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { FC } from 'react';
2+
3+
import { Project } from '../../models/Project';
4+
import { GitCard } from '../Git/Card';
5+
6+
export const ProjectCard: FC<Project> = ({ name, sourceLink, link, languages, tags, summary }) => (
7+
<GitCard
8+
full_name={name as string}
9+
html_url={sourceLink as string}
10+
homepage={link as string}
11+
languages={languages as string[]}
12+
topics={tags as string[]}
13+
description={summary as string}
14+
/>
15+
);

models/Project.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {
2+
BiDataQueryOptions,
3+
BiDataTable,
4+
BiSearch,
5+
TableCellLink,
6+
TableCellValue,
7+
TableRecord,
8+
} from 'mobx-lark';
9+
10+
import { LarkBase, larkClient } from './Base';
11+
import { LarkBitableId, ProjectTableId } from './configuration';
12+
13+
export type Project = LarkBase &
14+
Record<
15+
| 'name'
16+
| 'type'
17+
| 'sourceLink'
18+
| 'link'
19+
| 'license'
20+
| 'languages'
21+
| 'tags'
22+
| 'summary'
23+
| 'logo'
24+
| 'status'
25+
| 'reason',
26+
TableCellValue
27+
>;
28+
29+
export class ProjectModel extends BiDataTable<Project>() {
30+
client = larkClient;
31+
32+
queryOptions: BiDataQueryOptions = { text_field_as_array: false };
33+
34+
constructor(appId = LarkBitableId, tableId = ProjectTableId) {
35+
super(appId, tableId);
36+
}
37+
38+
extractFields({
39+
fields: { sourceLink, link, languages, tags, ...fields },
40+
...meta
41+
}: TableRecord<Project>) {
42+
return {
43+
...meta,
44+
...fields,
45+
sourceLink: (sourceLink as TableCellLink)?.link,
46+
link: (link as TableCellLink)?.link,
47+
languages: languages?.toString().split(/\s*,\s*/) || [],
48+
tags: tags?.toString().split(/\s*,\s*/) || [],
49+
};
50+
}
51+
}
52+
53+
export class SearchProjectModel extends BiSearch<Project>(ProjectModel) {
54+
searchKeys = [
55+
'name',
56+
'type',
57+
'sourceLink',
58+
'link',
59+
'license',
60+
'languages',
61+
'tags',
62+
'summary',
63+
'status',
64+
'reason',
65+
];
66+
}

models/System.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Constructor } from 'web-utility';
66
import { SearchActivityModel } from './Activity';
77
import { ownClient } from './Base';
88
import { OrganizationModel } from './Organization';
9+
import { SearchProjectModel } from './Project';
910

1011
export type SearchableFilter<D extends DataObject> = Filter<D> & {
1112
keywords?: string;
@@ -22,6 +23,7 @@ export type CityCoordinateMap = Record<string, [number, number]>;
2223
export class SystemModel extends BaseModel {
2324
searchMap = {
2425
activity: SearchActivityModel,
26+
project: SearchProjectModel,
2527
NGO: OrganizationModel,
2628
} as Record<string, Constructor<SearchModel<DataObject>>>;
2729

models/configuration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ export const LarkWikiDomain = hostname;
3535
export const LarkWikiId = pathname.split('/').pop()!;
3636

3737
export const LarkBitableId = process.env.NEXT_PUBLIC_LARK_BITABLE_ID!,
38-
ActivityTableId = process.env.NEXT_PUBLIC_ACTIVITY_TABLE_ID!;
38+
ActivityTableId = process.env.NEXT_PUBLIC_ACTIVITY_TABLE_ID!,
39+
ProjectTableId = process.env.NEXT_PUBLIC_PROJECT_TABLE_ID!;

pages/search/[model]/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CardPage, CardPageProps } from '../../../components/Layout/CardPage';
1010
import { PageHead } from '../../../components/Layout/PageHead';
1111
import { SearchBar } from '../../../components/Navigator/SearchBar';
1212
import { OrganizationCard } from '../../../components/Organization/Card';
13+
import { ProjectCard } from '../../../components/Project/Card';
1314
import systemStore, { SearchPageMeta } from '../../../models/System';
1415
import { i18n, I18nContext } from '../../../models/Translation';
1516

@@ -40,11 +41,13 @@ export const getServerSideProps = compose<{ model: string }, SearchModelPageProp
4041

4142
const SearchNameMap = ({ t }: typeof i18n): Record<string, string> => ({
4243
activity: t('activity'),
44+
project: t('open_source_projects'),
4345
NGO: t('NGO'),
4446
});
4547

4648
const SearchCardMap: Record<string, CardPageProps['Card']> = {
4749
activity: ActivityCard,
50+
project: ProjectCard,
4851
NGO: OrganizationCard,
4952
};
5053

translation/en-US.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export default {
99
hackathon: 'Hackathon',
1010
bounty: 'Open Source Bounty',
1111
open_source_projects: 'Open Source projects',
12+
self_developed_projects: 'Self-developed projects',
13+
bazaar_projects: 'Bazaar projects',
1214
open_source_bazaar: 'Open Source Bazaar',
1315
home_page: 'Home Page',
1416
wiki: 'Wiki',

translation/zh-CN.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export default {
77
join_us: '参与',
88
open_collaborator_award: '开放协作人奖',
99
open_source_projects: '开源项目',
10+
self_developed_projects: '自研项目',
11+
bazaar_projects: '市集项目',
1012
activity: '活动',
1113
hackathon: '黑客马拉松',
1214
bounty: '开源悬赏',

0 commit comments

Comments
 (0)