@stats-forge/github-stats-forge-core 0.0.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -10
- package/build/api/api-result.d.ts +6 -7
- package/build/api/api-result.d.ts.map +1 -1
- package/build/api/api-result.js +4 -5
- package/build/api/contributed-to.d.ts +23 -0
- package/build/api/contributed-to.d.ts.map +1 -0
- package/build/api/contributed-to.js +43 -0
- package/build/api/gist.d.ts +8 -22
- package/build/api/gist.d.ts.map +1 -1
- package/build/api/gist.js +14 -36
- package/build/api/handler.d.ts +16 -0
- package/build/api/handler.d.ts.map +1 -0
- package/build/api/handler.js +29 -0
- package/build/api/index.d.ts +13 -12
- package/build/api/index.d.ts.map +1 -1
- package/build/api/index.js +1 -0
- package/build/api/params.d.ts +21 -12
- package/build/api/params.d.ts.map +1 -1
- package/build/api/params.js +41 -19
- package/build/api/pin.d.ts +11 -31
- package/build/api/pin.d.ts.map +1 -1
- package/build/api/pin.js +35 -63
- package/build/api/stats.d.ts +15 -16
- package/build/api/stats.d.ts.map +1 -1
- package/build/api/stats.js +60 -99
- package/build/api/top-langs.d.ts +13 -18
- package/build/api/top-langs.d.ts.map +1 -1
- package/build/api/top-langs.js +35 -72
- package/build/api/wakatime.d.ts +11 -17
- package/build/api/wakatime.d.ts.map +1 -1
- package/build/api/wakatime.js +27 -64
- package/build/calculateRank.d.ts +0 -9
- package/build/calculateRank.d.ts.map +1 -1
- package/build/calculateRank.js +12 -17
- package/build/cards/contributed-to.d.ts +19 -0
- package/build/cards/contributed-to.d.ts.map +1 -0
- package/build/cards/contributed-to.js +242 -0
- package/build/cards/gist.d.ts +3 -4
- package/build/cards/gist.d.ts.map +1 -1
- package/build/cards/gist.js +38 -43
- package/build/cards/options.d.ts +1 -1
- package/build/cards/repo.d.ts +14 -5
- package/build/cards/repo.d.ts.map +1 -1
- package/build/cards/repo.js +93 -103
- package/build/cards/stats.d.ts +18 -11
- package/build/cards/stats.d.ts.map +1 -1
- package/build/cards/stats.js +191 -222
- package/build/cards/top-languages.d.ts +18 -33
- package/build/cards/top-languages.d.ts.map +1 -1
- package/build/cards/top-languages.js +196 -387
- package/build/cards/wakatime.d.ts +17 -8
- package/build/cards/wakatime.d.ts.map +1 -1
- package/build/cards/wakatime.js +133 -187
- package/build/common/Card.d.ts +20 -59
- package/build/common/Card.d.ts.map +1 -1
- package/build/common/Card.js +131 -198
- package/build/common/I18n.d.ts +1 -7
- package/build/common/I18n.d.ts.map +1 -1
- package/build/common/I18n.js +7 -8
- package/build/common/brand.d.ts +76 -0
- package/build/common/brand.d.ts.map +1 -0
- package/build/common/brand.js +73 -0
- package/build/common/color.d.ts +4 -17
- package/build/common/color.d.ts.map +1 -1
- package/build/common/color.js +67 -49
- package/build/common/config.d.ts +4 -14
- package/build/common/config.d.ts.map +1 -1
- package/build/common/config.js +3 -16
- package/build/common/constants.d.ts +6 -2
- package/build/common/constants.d.ts.map +1 -1
- package/build/common/constants.js +5 -1
- package/build/common/date.d.ts +50 -5
- package/build/common/date.d.ts.map +1 -1
- package/build/common/date.js +104 -4
- package/build/common/emojiMap.d.ts +8 -0
- package/build/common/emojiMap.d.ts.map +1 -0
- package/build/common/emojiMap.js +10 -0
- package/build/common/emojiMap.json +1915 -0
- package/build/common/error.d.ts +1 -10
- package/build/common/error.d.ts.map +1 -1
- package/build/common/error.js +1 -10
- package/build/common/fmt.d.ts +3 -15
- package/build/common/fmt.d.ts.map +1 -1
- package/build/common/fmt.js +7 -35
- package/build/common/http.d.ts +2 -7
- package/build/common/http.d.ts.map +1 -1
- package/build/common/http.js +8 -17
- package/build/common/icons.d.ts +20 -20
- package/build/common/icons.d.ts.map +1 -1
- package/build/common/icons.js +108 -67
- package/build/common/languageColors.d.ts +0 -1
- package/build/common/languageColors.d.ts.map +1 -1
- package/build/common/languageColors.js +1 -4
- package/build/common/languageColors.json +18 -2
- package/build/common/ops.d.ts +11 -17
- package/build/common/ops.d.ts.map +1 -1
- package/build/common/ops.js +22 -39
- package/build/common/render.d.ts +34 -82
- package/build/common/render.d.ts.map +1 -1
- package/build/common/render.js +225 -259
- package/build/common/retryer.d.ts +2 -7
- package/build/common/retryer.d.ts.map +1 -1
- package/build/common/retryer.js +4 -11
- package/build/fetchers/contributed-to.d.ts +62 -0
- package/build/fetchers/contributed-to.d.ts.map +1 -0
- package/build/fetchers/contributed-to.js +184 -0
- package/build/fetchers/gist.d.ts +2 -5
- package/build/fetchers/gist.d.ts.map +1 -1
- package/build/fetchers/gist.js +1 -5
- package/build/fetchers/graphql-error.d.ts +13 -0
- package/build/fetchers/graphql-error.d.ts.map +1 -0
- package/build/fetchers/graphql-error.js +29 -0
- package/build/fetchers/index.d.ts +13 -12
- package/build/fetchers/index.d.ts.map +1 -1
- package/build/fetchers/index.js +1 -0
- package/build/fetchers/repo.d.ts +2 -11
- package/build/fetchers/repo.d.ts.map +1 -1
- package/build/fetchers/repo.js +20 -33
- package/build/fetchers/stats.d.ts +16 -40
- package/build/fetchers/stats.d.ts.map +1 -1
- package/build/fetchers/stats.js +89 -271
- package/build/fetchers/top-languages.d.ts +2 -9
- package/build/fetchers/top-languages.d.ts.map +1 -1
- package/build/fetchers/top-languages.js +16 -47
- package/build/fetchers/types.d.ts +25 -1
- package/build/fetchers/types.d.ts.map +1 -1
- package/build/fetchers/wakatime.d.ts +2 -6
- package/build/fetchers/wakatime.d.ts.map +1 -1
- package/build/fetchers/wakatime.js +1 -5
- package/build/graphql/contributionsCollection.d.ts +9 -0
- package/build/graphql/contributionsCollection.d.ts.map +1 -0
- package/build/graphql/contributionsCollection.js +12 -0
- package/build/graphql/contributionsDocument.d.ts +6 -6
- package/build/graphql/contributionsDocument.d.ts.map +1 -1
- package/build/graphql/contributionsDocument.js +8 -16
- package/build/graphql/generated/contributed-to.d.ts +22 -0
- package/build/graphql/generated/contributed-to.d.ts.map +1 -0
- package/build/graphql/generated/contributed-to.js +11 -0
- package/build/graphql/generated/gist.d.ts +1 -1
- package/build/graphql/generated/repo.d.ts +1 -1
- package/build/graphql/generated/stats.d.ts +16 -4
- package/build/graphql/generated/stats.d.ts.map +1 -1
- package/build/graphql/generated/stats.js +2 -2
- package/build/graphql/generated/top-languages.d.ts +2 -2
- package/build/graphql/graphqlDocument.d.ts +1 -2
- package/build/graphql/graphqlDocument.d.ts.map +1 -1
- package/build/graphql/graphqlDocument.js +0 -1
- package/build/graphql/reposContributedToDocument.d.ts +4 -5
- package/build/graphql/reposContributedToDocument.d.ts.map +1 -1
- package/build/graphql/reposContributedToDocument.js +11 -7
- package/build/markup/css.d.ts +35 -0
- package/build/markup/css.d.ts.map +1 -0
- package/build/markup/css.js +64 -0
- package/build/markup/element.d.ts +41 -0
- package/build/markup/element.d.ts.map +1 -0
- package/build/markup/element.js +127 -0
- package/build/markup/html.d.ts +13 -0
- package/build/markup/html.d.ts.map +1 -0
- package/build/markup/html.js +27 -0
- package/build/markup/index.d.ts +9 -0
- package/build/markup/index.d.ts.map +1 -0
- package/build/markup/index.js +6 -0
- package/build/markup/serialize.d.ts +16 -0
- package/build/markup/serialize.d.ts.map +1 -0
- package/build/markup/serialize.js +17 -0
- package/build/themes/index.d.ts +332 -333
- package/build/themes/index.d.ts.map +1 -1
- package/build/themes/index.js +1 -1
- package/build/translations.d.ts +66 -7
- package/build/translations.d.ts.map +1 -1
- package/build/translations.js +686 -629
- package/package.json +17 -26
- package/src/api/api-result.ts +10 -9
- package/src/api/contributed-to.ts +84 -0
- package/src/api/gist.ts +22 -46
- package/src/api/handler.ts +42 -0
- package/src/api/index.ts +13 -12
- package/src/api/params.ts +74 -29
- package/src/api/pin.ts +38 -65
- package/src/api/stats.ts +81 -118
- package/src/api/top-langs.ts +38 -80
- package/src/api/wakatime.ts +35 -73
- package/src/calculateRank.ts +12 -23
- package/src/cards/contributed-to.ts +373 -0
- package/src/cards/gist.ts +55 -49
- package/src/cards/options.ts +1 -1
- package/src/cards/repo.ts +134 -120
- package/src/cards/stats.ts +262 -252
- package/src/cards/top-languages.ts +315 -422
- package/src/cards/wakatime.ts +207 -225
- package/src/common/Card.ts +207 -214
- package/src/common/I18n.ts +7 -8
- package/src/common/brand.ts +109 -0
- package/src/common/color.ts +80 -57
- package/src/common/config.ts +5 -18
- package/src/common/constants.ts +8 -2
- package/src/common/date.ts +135 -5
- package/src/common/emojiMap.json +1915 -0
- package/src/common/emojiMap.ts +13 -0
- package/src/common/error.ts +2 -11
- package/src/common/fmt.ts +7 -44
- package/src/common/http.ts +9 -15
- package/src/common/icons.ts +122 -42
- package/src/common/languageColors.json +18 -2
- package/src/common/languageColors.ts +1 -4
- package/src/common/ops.ts +31 -48
- package/src/common/render.ts +334 -284
- package/src/common/retryer.ts +8 -15
- package/src/fetchers/contributed-to.ts +271 -0
- package/src/fetchers/gist.ts +8 -12
- package/src/fetchers/graphql-error.ts +36 -0
- package/src/fetchers/index.ts +15 -12
- package/src/fetchers/repo.ts +27 -40
- package/src/fetchers/stats.ts +157 -366
- package/src/fetchers/top-languages.ts +27 -55
- package/src/fetchers/types.ts +27 -1
- package/src/fetchers/wakatime.ts +5 -9
- package/src/graphql/contributionsCollection.ts +18 -0
- package/src/graphql/contributionsDocument.ts +14 -19
- package/src/graphql/generated/contributed-to.ts +25 -0
- package/src/graphql/generated/gist.ts +1 -1
- package/src/graphql/generated/repo.ts +1 -1
- package/src/graphql/generated/stats.ts +21 -8
- package/src/graphql/generated/top-languages.ts +2 -2
- package/src/graphql/graphqlDocument.ts +1 -2
- package/src/graphql/queries/contributed-to.graphql +8 -0
- package/src/graphql/queries/stats.graphql +14 -2
- package/src/graphql/reposContributedToDocument.ts +16 -15
- package/src/markup/css.ts +118 -0
- package/src/markup/element.ts +246 -0
- package/src/markup/html.ts +34 -0
- package/src/markup/index.ts +9 -0
- package/src/markup/serialize.ts +27 -0
- package/src/themes/index.ts +1 -1
- package/src/translations.ts +699 -629
- package/build/cards/index.d.ts +0 -11
- package/build/cards/index.d.ts.map +0 -1
- package/build/cards/index.js +0 -7
- package/build/common/html.d.ts +0 -8
- package/build/common/html.d.ts.map +0 -1
- package/build/common/html.js +0 -14
- package/build/index.d.ts +0 -15
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -10
- package/src/_emoji-name-map.d.ts +0 -10
- package/src/_github-username-regex.d.ts +0 -4
- package/src/cards/index.ts +0 -21
- package/src/common/html.ts +0 -17
- package/src/index.ts +0 -18
package/src/api/pin.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
2
|
|
|
3
|
-
import { renderRepoCard } from '../cards/repo.
|
|
4
|
-
import
|
|
5
|
-
import { fetchRepo } from '../fetchers/repo.js';
|
|
3
|
+
import { renderRepoCard } from '../cards/repo.ts';
|
|
4
|
+
import { fetchRepo } from '../fetchers/repo.ts';
|
|
6
5
|
|
|
7
|
-
import
|
|
8
|
-
import { errorResult } from './api-result.js';
|
|
9
|
-
import type { ApiQuery } from './params.js';
|
|
6
|
+
import { cardHandler } from './handler.ts';
|
|
10
7
|
import {
|
|
11
8
|
booleanParam,
|
|
12
9
|
listParam,
|
|
13
10
|
localeParam,
|
|
14
11
|
looseIntParam,
|
|
15
12
|
numberParam,
|
|
16
|
-
parseColorParams,
|
|
17
|
-
parseParams,
|
|
18
13
|
rawParam,
|
|
19
14
|
safeParam,
|
|
20
|
-
|
|
15
|
+
usernameParam,
|
|
16
|
+
} from './params.ts';
|
|
21
17
|
|
|
22
18
|
/** What the pin endpoint accepts, on top of the shared color params. */
|
|
23
19
|
const pinQuery = z.object({
|
|
24
|
-
username:
|
|
20
|
+
username: usernameParam,
|
|
25
21
|
repo: safeParam,
|
|
26
22
|
hide_border: booleanParam,
|
|
27
23
|
card_width: looseIntParam,
|
|
@@ -37,41 +33,15 @@ const pinQuery = z.object({
|
|
|
37
33
|
description_lines_count: looseIntParam,
|
|
38
34
|
});
|
|
39
35
|
|
|
40
|
-
/** The query this endpoint accepts, checked against the schema above. */
|
|
41
|
-
type PinApiQuery = ApiQuery<typeof pinQuery>;
|
|
42
|
-
|
|
43
36
|
/**
|
|
44
37
|
* Render the repository card for a set of query params.
|
|
45
38
|
*
|
|
46
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
47
|
-
* @param query.username GitHub username the repository belongs to.
|
|
48
|
-
* @param query.repo Repository name.
|
|
49
|
-
* @param query.hide_border Whether to hide the card border.
|
|
50
|
-
* @param query.card_width Card width.
|
|
51
|
-
* @param query.show_owner Whether to show the repository owner.
|
|
52
|
-
* @param query.browser_rendering Whether the browser wraps the description text.
|
|
53
|
-
* @param query.show Comma-separated extra stats to show.
|
|
54
|
-
* @param query.show_icons Whether to show the stat icons.
|
|
55
|
-
* @param query.number_format How numbers are abbreviated.
|
|
56
|
-
* @param query.text_bold Whether the stat values are bold.
|
|
57
|
-
* @param query.line_height Line height between the stats.
|
|
58
|
-
* @param query.locale Language the card is rendered in.
|
|
59
|
-
* @param query.border_radius Card border radius.
|
|
60
|
-
* @param query.description_lines_count Lines the description is wrapped to.
|
|
61
|
-
* @param config Deployment config supplying the PAT pool.
|
|
62
39
|
* @returns The rendered card, or a rendered error.
|
|
63
40
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
} catch (err) {
|
|
69
|
-
// A rejected color cannot be used to draw its own error card.
|
|
70
|
-
return errorResult(err);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
const {
|
|
41
|
+
const renderPin = cardHandler(
|
|
42
|
+
pinQuery,
|
|
43
|
+
async (
|
|
44
|
+
{
|
|
75
45
|
username,
|
|
76
46
|
repo,
|
|
77
47
|
hide_border,
|
|
@@ -86,8 +56,10 @@ export const pin = async (query: PinApiQuery, config: CardConfig): Promise<ApiRe
|
|
|
86
56
|
locale,
|
|
87
57
|
border_radius,
|
|
88
58
|
description_lines_count,
|
|
89
|
-
}
|
|
90
|
-
|
|
59
|
+
},
|
|
60
|
+
colors,
|
|
61
|
+
config,
|
|
62
|
+
) => {
|
|
91
63
|
const repoData = await fetchRepo(
|
|
92
64
|
{
|
|
93
65
|
username,
|
|
@@ -101,26 +73,27 @@ export const pin = async (query: PinApiQuery, config: CardConfig): Promise<ApiRe
|
|
|
101
73
|
config,
|
|
102
74
|
);
|
|
103
75
|
|
|
104
|
-
return {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
76
|
+
return renderRepoCard(repoData, {
|
|
77
|
+
...colors,
|
|
78
|
+
hide_border,
|
|
79
|
+
border_radius,
|
|
80
|
+
card_width_input: card_width,
|
|
81
|
+
show_owner,
|
|
82
|
+
browser_rendering,
|
|
83
|
+
show,
|
|
84
|
+
show_icons,
|
|
85
|
+
number_format,
|
|
86
|
+
text_bold,
|
|
87
|
+
line_height,
|
|
88
|
+
username,
|
|
89
|
+
locale,
|
|
90
|
+
description_lines_count,
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The card, and the values each of its options accepts, keyed by the option's own name.
|
|
97
|
+
* A UI reads them off the function it calls: `pin.OPTIONS.show`.
|
|
98
|
+
*/
|
|
99
|
+
export const pin = Object.assign(renderPin, { OPTIONS: renderRepoCard.OPTIONS });
|
package/src/api/stats.ts
CHANGED
|
@@ -1,100 +1,65 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import { fetchStats } from '../fetchers/stats.
|
|
3
|
+
import { renderStatsCard } from '../cards/stats.ts';
|
|
4
|
+
import { OWNER_AFFILIATIONS } from '../common/constants.ts';
|
|
5
|
+
import { fetchStats } from '../fetchers/stats.ts';
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
import { errorResult } from './api-result.js';
|
|
9
|
-
import type { ApiQuery } from './params.js';
|
|
7
|
+
import { cardHandler } from './handler.ts';
|
|
10
8
|
import {
|
|
11
9
|
booleanParam,
|
|
12
10
|
enumParam,
|
|
11
|
+
fromParam,
|
|
13
12
|
listParam,
|
|
14
13
|
localeParam,
|
|
15
14
|
looseIntParam,
|
|
16
15
|
numberParam,
|
|
17
|
-
|
|
18
|
-
parseParams,
|
|
16
|
+
ORDERED_RANGE,
|
|
19
17
|
rawParam,
|
|
20
18
|
safeListParam,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from './params.
|
|
19
|
+
toParam,
|
|
20
|
+
usernameParam,
|
|
21
|
+
} from './params.ts';
|
|
24
22
|
|
|
25
23
|
/** What the stats endpoint accepts, on top of the shared color params. */
|
|
26
|
-
const statsQuery = z
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
24
|
+
const statsQuery = z
|
|
25
|
+
.object({
|
|
26
|
+
username: usernameParam,
|
|
27
|
+
repo: safeListParam,
|
|
28
|
+
owner: safeListParam,
|
|
29
|
+
hide: listParam,
|
|
30
|
+
hide_title: booleanParam,
|
|
31
|
+
hide_border: booleanParam,
|
|
32
|
+
card_width: looseIntParam,
|
|
33
|
+
hide_rank: booleanParam,
|
|
34
|
+
show_icons: booleanParam,
|
|
35
|
+
include_all_commits: booleanParam,
|
|
36
|
+
from: fromParam,
|
|
37
|
+
to: toParam,
|
|
38
|
+
line_height: rawParam,
|
|
39
|
+
text_bold: booleanParam,
|
|
40
|
+
exclude_repo: listParam,
|
|
41
|
+
custom_title: rawParam,
|
|
42
|
+
locale: localeParam,
|
|
43
|
+
disable_animations: booleanParam,
|
|
44
|
+
border_radius: numberParam,
|
|
45
|
+
number_format: rawParam,
|
|
46
|
+
role: listParam,
|
|
47
|
+
number_precision: looseIntParam,
|
|
48
|
+
rank_icon: enumParam(renderStatsCard.OPTIONS.rank_icon),
|
|
49
|
+
show: listParam,
|
|
50
|
+
contribs_include_own_repos: booleanParam,
|
|
51
|
+
})
|
|
52
|
+
.check(ORDERED_RANGE);
|
|
55
53
|
|
|
56
54
|
/**
|
|
57
55
|
* Render the stats card for a set of query params.
|
|
58
56
|
*
|
|
59
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
60
|
-
* @param query.username GitHub username.
|
|
61
|
-
* @param query.repo Comma-separated repositories the search-based stats are scoped to.
|
|
62
|
-
* @param query.owner Comma-separated owners the search-based stats are scoped to.
|
|
63
|
-
* @param query.hide Comma-separated stats to hide.
|
|
64
|
-
* @param query.hide_title Whether to hide the card title.
|
|
65
|
-
* @param query.hide_border Whether to hide the card border.
|
|
66
|
-
* @param query.card_width Card width.
|
|
67
|
-
* @param query.hide_rank Whether to hide the rank circle.
|
|
68
|
-
* @param query.show_icons Whether to show the stat icons.
|
|
69
|
-
* @param query.include_all_commits Whether to count commits of all time.
|
|
70
|
-
* @param query.commits_year Year the commits are counted for.
|
|
71
|
-
* @param query.line_height Line height between the stats.
|
|
72
|
-
* @param query.text_bold Whether the stat values are bold.
|
|
73
|
-
* @param query.exclude_repo Comma-separated repositories to exclude.
|
|
74
|
-
* @param query.custom_title Card title.
|
|
75
|
-
* @param query.locale Language the card is rendered in.
|
|
76
|
-
* @param query.disable_animations Whether to disable the card animations.
|
|
77
|
-
* @param query.border_radius Card border radius.
|
|
78
|
-
* @param query.number_format How numbers are abbreviated.
|
|
79
|
-
* @param query.role Comma-separated owner affiliations to include.
|
|
80
|
-
* @param query.number_precision Decimals kept when a number is abbreviated.
|
|
81
|
-
* @param query.rank_icon Which rank indicator to draw.
|
|
82
|
-
* @param query.show Comma-separated extra stats to show.
|
|
83
|
-
* @param query.contribs_include_own_repos Whether the contributed-to counts include the user's own repositories.
|
|
84
|
-
* @param config Deployment config supplying the PAT pool.
|
|
85
57
|
* @returns The rendered card, or a rendered error.
|
|
86
58
|
*/
|
|
87
|
-
const renderStats =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
} catch (err) {
|
|
92
|
-
// A rejected color cannot be used to draw its own error card.
|
|
93
|
-
return errorResult(err);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
const {
|
|
59
|
+
const renderStats = cardHandler(
|
|
60
|
+
statsQuery,
|
|
61
|
+
async (
|
|
62
|
+
{
|
|
98
63
|
username,
|
|
99
64
|
repo,
|
|
100
65
|
owner,
|
|
@@ -105,7 +70,8 @@ const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<Ap
|
|
|
105
70
|
hide_rank,
|
|
106
71
|
show_icons,
|
|
107
72
|
include_all_commits,
|
|
108
|
-
|
|
73
|
+
from,
|
|
74
|
+
to,
|
|
109
75
|
line_height,
|
|
110
76
|
text_bold,
|
|
111
77
|
exclude_repo,
|
|
@@ -119,8 +85,10 @@ const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<Ap
|
|
|
119
85
|
rank_icon,
|
|
120
86
|
show,
|
|
121
87
|
contribs_include_own_repos,
|
|
122
|
-
}
|
|
123
|
-
|
|
88
|
+
},
|
|
89
|
+
colors,
|
|
90
|
+
config,
|
|
91
|
+
) => {
|
|
124
92
|
// A bare repo name is scoped to the user whose card this is.
|
|
125
93
|
const repository = repo.map((name) =>
|
|
126
94
|
name.includes('/') ? name : `${username ?? ''}/${name}`,
|
|
@@ -135,7 +103,8 @@ const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<Ap
|
|
|
135
103
|
show.includes('prs_merged') || show.includes('prs_merged_percentage'),
|
|
136
104
|
include_discussions: show.includes('discussions_started'),
|
|
137
105
|
include_discussions_answers: show.includes('discussions_answered'),
|
|
138
|
-
|
|
106
|
+
from,
|
|
107
|
+
to,
|
|
139
108
|
repo: repository,
|
|
140
109
|
owner,
|
|
141
110
|
include_prs_authored: show.includes('prs_authored'),
|
|
@@ -151,45 +120,39 @@ const renderStats = async (query: StatsApiQuery, config: CardConfig): Promise<Ap
|
|
|
151
120
|
config,
|
|
152
121
|
);
|
|
153
122
|
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
),
|
|
183
|
-
};
|
|
184
|
-
} catch (err) {
|
|
185
|
-
return errorResult(err, colors);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
123
|
+
return renderStatsCard(
|
|
124
|
+
stats,
|
|
125
|
+
{
|
|
126
|
+
...colors,
|
|
127
|
+
hide,
|
|
128
|
+
show_icons,
|
|
129
|
+
hide_title,
|
|
130
|
+
hide_border,
|
|
131
|
+
card_width,
|
|
132
|
+
hide_rank,
|
|
133
|
+
include_all_commits,
|
|
134
|
+
line_height,
|
|
135
|
+
text_bold,
|
|
136
|
+
custom_title,
|
|
137
|
+
border_radius,
|
|
138
|
+
number_format,
|
|
139
|
+
number_precision,
|
|
140
|
+
locale,
|
|
141
|
+
disable_animations,
|
|
142
|
+
rank_icon,
|
|
143
|
+
show,
|
|
144
|
+
},
|
|
145
|
+
username,
|
|
146
|
+
repository,
|
|
147
|
+
owner,
|
|
148
|
+
);
|
|
149
|
+
},
|
|
150
|
+
);
|
|
188
151
|
|
|
189
152
|
/**
|
|
190
|
-
* The card,
|
|
191
|
-
* A UI reads them off the function it calls
|
|
153
|
+
* The card, and the values each of its options accepts, keyed by the option's own name.
|
|
154
|
+
* A UI reads them off the function it calls: `stats.OPTIONS.rank_icon`.
|
|
192
155
|
*/
|
|
193
156
|
export const stats = Object.assign(renderStats, {
|
|
194
|
-
|
|
157
|
+
OPTIONS: { ...renderStatsCard.OPTIONS, role: OWNER_AFFILIATIONS },
|
|
195
158
|
});
|
package/src/api/top-langs.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import * as z from 'zod/mini';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
renderTopLanguages,
|
|
7
|
-
} from '../cards/top-languages.js';
|
|
8
|
-
import type { CardConfig } from '../common/config.js';
|
|
9
|
-
import { fetchTopLanguages } from '../fetchers/top-languages.js';
|
|
3
|
+
import { renderTopLanguages } from '../cards/top-languages.ts';
|
|
4
|
+
import { OWNER_AFFILIATIONS } from '../common/constants.ts';
|
|
5
|
+
import { fetchTopLanguages } from '../fetchers/top-languages.ts';
|
|
10
6
|
|
|
11
|
-
import
|
|
12
|
-
import { errorResult } from './api-result.js';
|
|
13
|
-
import type { ApiQuery } from './params.js';
|
|
7
|
+
import { cardHandler } from './handler.ts';
|
|
14
8
|
import {
|
|
15
9
|
booleanParam,
|
|
16
10
|
enumParam,
|
|
@@ -18,20 +12,18 @@ import {
|
|
|
18
12
|
localeParam,
|
|
19
13
|
looseIntParam,
|
|
20
14
|
numberParam,
|
|
21
|
-
parseColorParams,
|
|
22
|
-
parseParams,
|
|
23
15
|
rawParam,
|
|
24
|
-
|
|
25
|
-
} from './params.
|
|
16
|
+
usernameParam,
|
|
17
|
+
} from './params.ts';
|
|
26
18
|
|
|
27
19
|
/** What the top-languages endpoint accepts, on top of the shared color params. */
|
|
28
20
|
const topLangsQuery = z.object({
|
|
29
|
-
username:
|
|
21
|
+
username: usernameParam,
|
|
30
22
|
hide: listParam,
|
|
31
23
|
hide_title: booleanParam,
|
|
32
24
|
hide_border: booleanParam,
|
|
33
25
|
card_width: looseIntParam,
|
|
34
|
-
layout: enumParam(
|
|
26
|
+
layout: enumParam(renderTopLanguages.OPTIONS.layout),
|
|
35
27
|
langs_count: looseIntParam,
|
|
36
28
|
exclude_repo: listParam,
|
|
37
29
|
size_weight: numberParam,
|
|
@@ -43,48 +35,18 @@ const topLangsQuery = z.object({
|
|
|
43
35
|
disable_animations: booleanParam,
|
|
44
36
|
hide_progress: booleanParam,
|
|
45
37
|
hide_values: booleanParam,
|
|
46
|
-
stats_format: enumParam(
|
|
38
|
+
stats_format: enumParam(renderTopLanguages.OPTIONS.stats_format),
|
|
47
39
|
});
|
|
48
40
|
|
|
49
|
-
/** The query this endpoint accepts, checked against the schema above. */
|
|
50
|
-
type TopLangsApiQuery = ApiQuery<typeof topLangsQuery>;
|
|
51
|
-
|
|
52
41
|
/**
|
|
53
42
|
* Render the top languages card for a set of query params.
|
|
54
43
|
*
|
|
55
|
-
* @param query Raw query params, plus any of the shared color params.
|
|
56
|
-
* @param query.username GitHub username.
|
|
57
|
-
* @param query.hide Comma-separated languages to hide.
|
|
58
|
-
* @param query.hide_title Whether to hide the card title.
|
|
59
|
-
* @param query.hide_border Whether to hide the card border.
|
|
60
|
-
* @param query.card_width Card width.
|
|
61
|
-
* @param query.layout How the languages are laid out.
|
|
62
|
-
* @param query.langs_count Number of languages to show.
|
|
63
|
-
* @param query.exclude_repo Comma-separated repositories to exclude.
|
|
64
|
-
* @param query.size_weight Weight given to a language's size.
|
|
65
|
-
* @param query.count_weight Weight given to a language's repository count.
|
|
66
|
-
* @param query.custom_title Card title.
|
|
67
|
-
* @param query.locale Language the card is rendered in.
|
|
68
|
-
* @param query.border_radius Card border radius.
|
|
69
|
-
* @param query.role Comma-separated owner affiliations to include.
|
|
70
|
-
* @param query.disable_animations Whether to disable the card animations.
|
|
71
|
-
* @param query.hide_progress Whether to hide the progress bars.
|
|
72
|
-
* @param query.hide_values Whether to hide the language values.
|
|
73
|
-
* @param query.stats_format Whether values are shown as bytes or percentages.
|
|
74
|
-
* @param config Deployment config supplying the PAT pool.
|
|
75
44
|
* @returns The rendered card, or a rendered error.
|
|
76
45
|
*/
|
|
77
|
-
const renderTopLangs =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
} catch (err) {
|
|
82
|
-
// A rejected color cannot be used to draw its own error card.
|
|
83
|
-
return errorResult(err);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
const {
|
|
46
|
+
const renderTopLangs = cardHandler(
|
|
47
|
+
topLangsQuery,
|
|
48
|
+
async (
|
|
49
|
+
{
|
|
88
50
|
username,
|
|
89
51
|
hide,
|
|
90
52
|
hide_title,
|
|
@@ -103,8 +65,10 @@ const renderTopLangs = async (query: TopLangsApiQuery, config: CardConfig): Prom
|
|
|
103
65
|
hide_progress,
|
|
104
66
|
hide_values,
|
|
105
67
|
stats_format,
|
|
106
|
-
}
|
|
107
|
-
|
|
68
|
+
},
|
|
69
|
+
colors,
|
|
70
|
+
config,
|
|
71
|
+
) => {
|
|
108
72
|
const topLangs = await fetchTopLanguages(
|
|
109
73
|
{
|
|
110
74
|
username,
|
|
@@ -116,35 +80,29 @@ const renderTopLangs = async (query: TopLangsApiQuery, config: CardConfig): Prom
|
|
|
116
80
|
config,
|
|
117
81
|
);
|
|
118
82
|
|
|
119
|
-
return {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
};
|
|
138
|
-
} catch (err) {
|
|
139
|
-
return errorResult(err, colors);
|
|
140
|
-
}
|
|
141
|
-
};
|
|
83
|
+
return renderTopLanguages(topLangs, {
|
|
84
|
+
...colors,
|
|
85
|
+
custom_title,
|
|
86
|
+
hide_title,
|
|
87
|
+
hide_border,
|
|
88
|
+
card_width,
|
|
89
|
+
hide,
|
|
90
|
+
layout,
|
|
91
|
+
langs_count,
|
|
92
|
+
border_radius,
|
|
93
|
+
locale,
|
|
94
|
+
disable_animations,
|
|
95
|
+
hide_progress,
|
|
96
|
+
hide_values,
|
|
97
|
+
stats_format,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
);
|
|
142
101
|
|
|
143
102
|
/**
|
|
144
|
-
* The card,
|
|
145
|
-
* A UI reads them off the function it calls
|
|
103
|
+
* The card, and the values each of its options accepts, keyed by the option's own name.
|
|
104
|
+
* A UI reads them off the function it calls: `topLangs.OPTIONS.layout`.
|
|
146
105
|
*/
|
|
147
106
|
export const topLangs = Object.assign(renderTopLangs, {
|
|
148
|
-
|
|
149
|
-
STATS_FORMATS: TOP_LANG_STATS_FORMATS,
|
|
107
|
+
OPTIONS: { ...renderTopLanguages.OPTIONS, role: OWNER_AFFILIATIONS },
|
|
150
108
|
});
|