headreel 1.3.0 → 1.5.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 +64 -0
- package/assets/fonts/Caveat.ttf +0 -0
- package/assets/fonts/OFL-Caveat.txt +93 -0
- package/dist/cli/run.js +2 -2
- package/dist/core/data/now-playing.js +282 -0
- package/dist/core/data/receipt.js +144 -0
- package/dist/core/fonts.js +3 -0
- package/dist/core/streaks.js +38 -0
- package/dist/styles/highlights-reel/palette.js +2 -1
- package/dist/styles/highlights-reel/reel.js +2 -10
- package/dist/styles/index.js +4 -0
- package/dist/styles/now-playing/deck.js +105 -0
- package/dist/styles/now-playing/index.js +16 -0
- package/dist/styles/now-playing/options.js +19 -0
- package/dist/styles/now-playing/palette.js +69 -0
- package/dist/styles/now-playing/sketch.js +610 -0
- package/dist/styles/receipt/index.js +16 -0
- package/dist/styles/receipt/options.js +14 -0
- package/dist/styles/receipt/palette.js +48 -0
- package/dist/styles/receipt/receipt.js +229 -0
- package/dist/styles/receipt/sketch.js +296 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,6 +99,10 @@ Empty settings do not show on the banner. Your name comes from your GitHub profi
|
|
|
99
99
|
|
|
100
100
|
Set the style with `style: <name>` in the Action, or `--style <name>` in the command. Set an option with `options: 'accent: green'` in the Action, or `--option accent=green` in the command. For more than one option in the Action, put each on its own line.
|
|
101
101
|
|
|
102
|
+
<table>
|
|
103
|
+
<tr>
|
|
104
|
+
<td>
|
|
105
|
+
|
|
102
106
|
### Contribution City
|
|
103
107
|
|
|
104
108
|
`contribution-city`: each day of the last 12 months is one building. A taller building means more contributions. Beacons glow on your busiest days.
|
|
@@ -109,6 +113,14 @@ Set the style with `style: <name>` in the Action, or `--style <name>` in the com
|
|
|
109
113
|
| -------- | ------- | --------------------------------------------------------------------------------------------- |
|
|
110
114
|
| `accent` | `cyan` | Color of the roofs, windows, lights and links: `cyan`, `cobalt`, `green`, `violet` or `pink`. |
|
|
111
115
|
|
|
116
|
+
</td>
|
|
117
|
+
</tr>
|
|
118
|
+
</table>
|
|
119
|
+
|
|
120
|
+
<table>
|
|
121
|
+
<tr>
|
|
122
|
+
<td>
|
|
123
|
+
|
|
112
124
|
### Highlights Reel
|
|
113
125
|
|
|
114
126
|
`highlights-reel`: a few profile facts, each on its own card, filmed by one camera. The camera travels between the cards, pushes into your busiest week, and ends on a wide shot of the whole reel.
|
|
@@ -120,6 +132,54 @@ Set the style with `style: <name>` in the Action, or `--style <name>` in the com
|
|
|
120
132
|
| `theme` | `light` | `light` or `dark`. Use `dark` if your profile is mostly viewed in GitHub dark mode. |
|
|
121
133
|
| `accent` | `cobalt` | Color of the bars, numbers and links: `cobalt`, `green`, `violet`, `orange` or `pink`. |
|
|
122
134
|
|
|
135
|
+
</td>
|
|
136
|
+
</tr>
|
|
137
|
+
</table>
|
|
138
|
+
|
|
139
|
+
<table>
|
|
140
|
+
<tr>
|
|
141
|
+
<td>
|
|
142
|
+
|
|
143
|
+
### Now Playing
|
|
144
|
+
|
|
145
|
+
`now-playing`: a cassette deck playing the repository you committed to most in the last 30 days. The label names its language, your commit messages on it scroll across the deck's display as lyrics, and the level meter shows the month day by day. When nothing was committed in the last 30 days, the deck shows the repository you pushed to last as `LAST PLAYED`.
|
|
146
|
+
|
|
147
|
+

|
|
148
|
+
|
|
149
|
+
| Option | Default | Description |
|
|
150
|
+
| --------- | ------- | --------------------------------------------------------------------------------------------------- |
|
|
151
|
+
| `theme` | `dark` | `dark` (graphite deck) or `light` (silver deck). |
|
|
152
|
+
| `accent` | `cyan` | Display color, meter and links: `cyan`, `green` or `orange`. |
|
|
153
|
+
| `exclude` | empty | Comma-separated repositories never picked, for example your profile repository: `exclude: octocat`. |
|
|
154
|
+
|
|
155
|
+
</td>
|
|
156
|
+
</tr>
|
|
157
|
+
</table>
|
|
158
|
+
|
|
159
|
+
<table>
|
|
160
|
+
<tr>
|
|
161
|
+
<td>
|
|
162
|
+
|
|
163
|
+
### Receipt
|
|
164
|
+
|
|
165
|
+
`receipt`: a thermal printer feeds out your last 12 months as a till receipt: repositories as items, contribution counts as the totals, streaks and your best day printed below, and a barcode encoding your activity week by week. The paper prints line by line, tears off, and the next receipt starts.
|
|
166
|
+
|
|
167
|
+

|
|
168
|
+
|
|
169
|
+
| Option | Default | Description |
|
|
170
|
+
| -------- | -------- | ------------------------------------------------------------------------------- |
|
|
171
|
+
| `theme` | `dark` | `dark` or `light`. Use `light` if your profile is mostly viewed in light mode. |
|
|
172
|
+
| `accent` | `cobalt` | Prompt, cursor, tagline and LED: `cobalt`, `green`, `violet`, `orange`, `pink`. |
|
|
173
|
+
| `items` | `5` | Repositories printed as line items, `0` to `5`. |
|
|
174
|
+
|
|
175
|
+
</td>
|
|
176
|
+
</tr>
|
|
177
|
+
</table>
|
|
178
|
+
|
|
179
|
+
<table>
|
|
180
|
+
<tr>
|
|
181
|
+
<td>
|
|
182
|
+
|
|
123
183
|
### Repo Galaxy
|
|
124
184
|
|
|
125
185
|
`repo-galaxy`: your most starred repositories orbit a sun. A bigger planet has more stars, and its color is the repository's main language. Repositories you pushed to recently orbit closer to the sun.
|
|
@@ -132,6 +192,10 @@ Set the style with `style: <name>` in the Action, or `--style <name>` in the com
|
|
|
132
192
|
| `include_forks` | `false` | Show forked repositories too. |
|
|
133
193
|
| `labels` | `top3` | `top3` names the three most starred repositories. `none` hides names. |
|
|
134
194
|
|
|
195
|
+
</td>
|
|
196
|
+
</tr>
|
|
197
|
+
</table>
|
|
198
|
+
|
|
135
199
|
## Troubleshooting
|
|
136
200
|
|
|
137
201
|
| Problem | Fix |
|
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2014 The Caveat Project Authors (https://github.com/googlefonts/caveat)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
package/dist/cli/run.js
CHANGED
|
@@ -24,7 +24,7 @@ async function render(settings, io) {
|
|
|
24
24
|
throw new Error(`Output must be a .gif file, got "${settings.out}".`);
|
|
25
25
|
}
|
|
26
26
|
// Fail on bad options before any API call.
|
|
27
|
-
parseOptions(style, settings.options);
|
|
27
|
+
const options = parseOptions(style, settings.options);
|
|
28
28
|
let login;
|
|
29
29
|
let name;
|
|
30
30
|
let data;
|
|
@@ -38,7 +38,7 @@ async function render(settings, io) {
|
|
|
38
38
|
const user = settings.user;
|
|
39
39
|
const [profile, fetched] = await Promise.all([
|
|
40
40
|
fetchProfile(client, user),
|
|
41
|
-
style.data.fetch(client, user, io.now()),
|
|
41
|
+
style.data.fetch(client, user, io.now(), options),
|
|
42
42
|
]);
|
|
43
43
|
({ login, name } = profile);
|
|
44
44
|
data = fetched;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// The tape is the user's most active public repository of the last 30 days.
|
|
3
|
+
// Two queries when something is playing; a third one finds the fallback.
|
|
4
|
+
// Query 1: every repository the user committed to in the window, with its
|
|
5
|
+
// daily commit counts. The user's id feeds the author filter of query 2.
|
|
6
|
+
const QUERY = /* GraphQL */ `
|
|
7
|
+
query NowPlaying($login: String!, $from: DateTime!, $to: DateTime!) {
|
|
8
|
+
user(login: $login) {
|
|
9
|
+
id
|
|
10
|
+
contributionsCollection(from: $from, to: $to) {
|
|
11
|
+
commitContributionsByRepository(maxRepositories: 25) {
|
|
12
|
+
repository {
|
|
13
|
+
name
|
|
14
|
+
owner {
|
|
15
|
+
login
|
|
16
|
+
}
|
|
17
|
+
isPrivate
|
|
18
|
+
primaryLanguage {
|
|
19
|
+
name
|
|
20
|
+
color
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
contributions(first: 31) {
|
|
24
|
+
totalCount
|
|
25
|
+
nodes {
|
|
26
|
+
occurredAt
|
|
27
|
+
commitCount
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
// Query 2: the playing repository's default-branch commits authored by the
|
|
36
|
+
// user since the window started. GitHub counts commit contributions on the
|
|
37
|
+
// default branch (or gh-pages) only, the same source as query 1.
|
|
38
|
+
const COMMIT_HISTORY = /* GraphQL */ `
|
|
39
|
+
edges {
|
|
40
|
+
node {
|
|
41
|
+
messageHeadline
|
|
42
|
+
parents {
|
|
43
|
+
totalCount
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const COMMITS_QUERY = /* GraphQL */ `
|
|
49
|
+
query NowPlayingCommits($owner: String!, $name: String!, $id: ID!, $since: GitTimestamp!) {
|
|
50
|
+
repository(owner: $owner, name: $name) {
|
|
51
|
+
defaultBranchRef {
|
|
52
|
+
target {
|
|
53
|
+
... on Commit {
|
|
54
|
+
history(author: { id: $id }, since: $since, first: 30) {
|
|
55
|
+
${COMMIT_HISTORY}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
// Fallback: the most recently pushed owned public repository and the user's
|
|
64
|
+
// latest commits on it, without `since`. The history rides on every node, so
|
|
65
|
+
// one query covers whichever repository the picker lands on.
|
|
66
|
+
const FALLBACK_QUERY = /* GraphQL */ `
|
|
67
|
+
query NowPlayingFallback($login: String!, $id: ID!, $first: Int!) {
|
|
68
|
+
user(login: $login) {
|
|
69
|
+
repositories(
|
|
70
|
+
first: $first
|
|
71
|
+
ownerAffiliations: OWNER
|
|
72
|
+
privacy: PUBLIC
|
|
73
|
+
isFork: false
|
|
74
|
+
orderBy: { field: PUSHED_AT, direction: DESC }
|
|
75
|
+
) {
|
|
76
|
+
nodes {
|
|
77
|
+
name
|
|
78
|
+
owner {
|
|
79
|
+
login
|
|
80
|
+
}
|
|
81
|
+
primaryLanguage {
|
|
82
|
+
name
|
|
83
|
+
color
|
|
84
|
+
}
|
|
85
|
+
defaultBranchRef {
|
|
86
|
+
target {
|
|
87
|
+
... on Commit {
|
|
88
|
+
history(author: { id: $id }, first: 30) {
|
|
89
|
+
${COMMIT_HISTORY}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
export const WINDOW_DAYS = 30;
|
|
100
|
+
export const statusSchema = z.enum(['playing', 'last-played', 'empty']);
|
|
101
|
+
const languageSchema = z
|
|
102
|
+
.object({
|
|
103
|
+
name: z.string().min(1),
|
|
104
|
+
/** Linguist color; null when the repo has no language or color. */
|
|
105
|
+
color: z
|
|
106
|
+
.string()
|
|
107
|
+
.regex(/^#[0-9a-fA-F]{6}$/)
|
|
108
|
+
.nullable(),
|
|
109
|
+
})
|
|
110
|
+
.nullable();
|
|
111
|
+
export const nowPlayingSchema = z.object({
|
|
112
|
+
/** Fetch date, YYYY-MM-DD (UTC). */
|
|
113
|
+
asOf: z.iso.date(),
|
|
114
|
+
status: statusSchema,
|
|
115
|
+
repo: z
|
|
116
|
+
.object({
|
|
117
|
+
/** Not always the user: contributions to another user's project show as owner/name. */
|
|
118
|
+
owner: z.string().min(1),
|
|
119
|
+
name: z.string().min(1),
|
|
120
|
+
language: languageSchema,
|
|
121
|
+
})
|
|
122
|
+
.nullable(),
|
|
123
|
+
/** The playing repo's commits in the window; 0 on fallback. */
|
|
124
|
+
commits: z.number().int().min(0),
|
|
125
|
+
/** Its part of all public commits in the window, 0..1. */
|
|
126
|
+
share: z.number().min(0).max(1),
|
|
127
|
+
/** The playing repo's daily commits in the window, oldest first. */
|
|
128
|
+
days: z.array(z.number().int().min(0)).length(WINDOW_DAYS),
|
|
129
|
+
/** The repo's default-branch commit headlines, newest first, merges dropped. */
|
|
130
|
+
lyrics: z.array(z.string().min(1)).max(8),
|
|
131
|
+
});
|
|
132
|
+
const DAY_MS = 86_400_000;
|
|
133
|
+
/**
|
|
134
|
+
* The 30 days ending on `now` (UTC): `from` is 29 days back at midnight, `to`
|
|
135
|
+
* is today, matching the run date the banner is rendered on.
|
|
136
|
+
*/
|
|
137
|
+
export function nowPlayingWindow(now) {
|
|
138
|
+
const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
|
139
|
+
return {
|
|
140
|
+
from: new Date(today - (WINDOW_DAYS - 1) * DAY_MS).toISOString().slice(0, 10),
|
|
141
|
+
to: new Date(today).toISOString().slice(0, 10),
|
|
142
|
+
asOf: new Date(today).toISOString().slice(0, 10),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The daily commit counts of one repository across the window, oldest first.
|
|
147
|
+
* `occurredAt` days outside the window are dropped.
|
|
148
|
+
*/
|
|
149
|
+
export function windowDays(contributions, from, to) {
|
|
150
|
+
const counts = new Map();
|
|
151
|
+
for (const node of contributions.nodes ?? []) {
|
|
152
|
+
counts.set(node.occurredAt.slice(0, 10), (counts.get(node.occurredAt.slice(0, 10)) ?? 0) + node.commitCount);
|
|
153
|
+
}
|
|
154
|
+
const days = [];
|
|
155
|
+
for (let t = Date.parse(`${from}T00:00:00Z`); t <= Date.parse(`${to}T00:00:00Z`); t += DAY_MS) {
|
|
156
|
+
days.push(counts.get(new Date(t).toISOString().slice(0, 10)) ?? 0);
|
|
157
|
+
}
|
|
158
|
+
return days;
|
|
159
|
+
}
|
|
160
|
+
/** Index of the last day with a commit, -1 when the repository had none. */
|
|
161
|
+
function lastActiveIndex(days) {
|
|
162
|
+
for (let i = days.length - 1; i >= 0; i--) {
|
|
163
|
+
if (days[i] > 0)
|
|
164
|
+
return i;
|
|
165
|
+
}
|
|
166
|
+
return -1;
|
|
167
|
+
}
|
|
168
|
+
function excludedBy(exclude) {
|
|
169
|
+
const names = new Set(exclude.map((n) => n.trim().toLowerCase()));
|
|
170
|
+
return (owner, name) => names.has(name.toLowerCase()) || names.has(`${owner}/${name}`.toLowerCase());
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Drops excluded names, then picks the playing one: most commits in the
|
|
174
|
+
* window, ties to the latest active day, then name.
|
|
175
|
+
*/
|
|
176
|
+
export function pickRepo(candidates, exclude = []) {
|
|
177
|
+
const isExcluded = excludedBy(exclude);
|
|
178
|
+
let best = null;
|
|
179
|
+
for (const c of candidates) {
|
|
180
|
+
if (isExcluded(c.owner, c.name))
|
|
181
|
+
continue;
|
|
182
|
+
if (!best || better(c, best))
|
|
183
|
+
best = c;
|
|
184
|
+
}
|
|
185
|
+
return best;
|
|
186
|
+
}
|
|
187
|
+
function better(a, b) {
|
|
188
|
+
if (a.commits !== b.commits)
|
|
189
|
+
return a.commits > b.commits;
|
|
190
|
+
const ai = lastActiveIndex(a.days);
|
|
191
|
+
const bi = lastActiveIndex(b.days);
|
|
192
|
+
if (ai !== bi)
|
|
193
|
+
return ai > bi;
|
|
194
|
+
return a.name.localeCompare(b.name) < 0;
|
|
195
|
+
}
|
|
196
|
+
/** Merges (more than one parent) and empty headlines never become lyrics. */
|
|
197
|
+
export function lyricsFromHistory(nodes) {
|
|
198
|
+
return nodes
|
|
199
|
+
.filter((n) => n.parents.totalCount <= 1 && n.messageHeadline.trim().length > 0)
|
|
200
|
+
.map((n) => n.messageHeadline.trim())
|
|
201
|
+
.slice(0, 8);
|
|
202
|
+
}
|
|
203
|
+
const ZEROS = Array.from({ length: WINDOW_DAYS }).fill(0);
|
|
204
|
+
export async function fetchNowPlaying(client, login, now, options = {}) {
|
|
205
|
+
const { from, to, asOf } = nowPlayingWindow(now);
|
|
206
|
+
const since = `${from}T00:00:00Z`;
|
|
207
|
+
const { user } = await client(QUERY, {
|
|
208
|
+
login,
|
|
209
|
+
from: since,
|
|
210
|
+
to: `${to}T23:59:59Z`,
|
|
211
|
+
});
|
|
212
|
+
// Private repositories are dropped before anything is picked: repo names
|
|
213
|
+
// and commit messages of private repos never reach the banner.
|
|
214
|
+
const candidates = user.contributionsCollection.commitContributionsByRepository
|
|
215
|
+
.filter((entry) => !entry.repository.isPrivate)
|
|
216
|
+
.map((entry) => ({
|
|
217
|
+
owner: entry.repository.owner.login,
|
|
218
|
+
name: entry.repository.name,
|
|
219
|
+
commits: entry.contributions.totalCount,
|
|
220
|
+
days: windowDays(entry.contributions, from, to),
|
|
221
|
+
language: entry.repository.primaryLanguage
|
|
222
|
+
? {
|
|
223
|
+
name: entry.repository.primaryLanguage.name,
|
|
224
|
+
color: entry.repository.primaryLanguage.color,
|
|
225
|
+
}
|
|
226
|
+
: null,
|
|
227
|
+
}));
|
|
228
|
+
const picked = pickRepo(candidates, options.exclude ?? []);
|
|
229
|
+
if (picked) {
|
|
230
|
+
const all = candidates.reduce((sum, c) => sum + c.commits, 0);
|
|
231
|
+
const { repository } = await client(COMMITS_QUERY, {
|
|
232
|
+
owner: picked.owner,
|
|
233
|
+
name: picked.name,
|
|
234
|
+
id: user.id,
|
|
235
|
+
since,
|
|
236
|
+
});
|
|
237
|
+
return {
|
|
238
|
+
asOf,
|
|
239
|
+
status: 'playing',
|
|
240
|
+
repo: { owner: picked.owner, name: picked.name, language: picked.language },
|
|
241
|
+
commits: picked.commits,
|
|
242
|
+
share: all > 0 ? picked.commits / all : 0,
|
|
243
|
+
days: picked.days,
|
|
244
|
+
lyrics: lyricsFromHistory(repository?.defaultBranchRef?.target?.history?.edges.map((e) => e.node) ?? []),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
// Nothing playing: the most recently pushed owned public repository, whose
|
|
248
|
+
// latest default-branch commits become the lyrics without a window.
|
|
249
|
+
const fallback = await client(FALLBACK_QUERY, {
|
|
250
|
+
login,
|
|
251
|
+
id: user.id,
|
|
252
|
+
first: 25,
|
|
253
|
+
});
|
|
254
|
+
const isExcluded = excludedBy(options.exclude ?? []);
|
|
255
|
+
const repo = fallback.user.repositories.nodes.find((n) => !isExcluded(n.owner.login, n.name));
|
|
256
|
+
if (!repo) {
|
|
257
|
+
return {
|
|
258
|
+
asOf,
|
|
259
|
+
status: 'empty',
|
|
260
|
+
repo: null,
|
|
261
|
+
commits: 0,
|
|
262
|
+
share: 0,
|
|
263
|
+
days: [...ZEROS],
|
|
264
|
+
lyrics: [],
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
asOf,
|
|
269
|
+
status: 'last-played',
|
|
270
|
+
repo: {
|
|
271
|
+
owner: repo.owner.login,
|
|
272
|
+
name: repo.name,
|
|
273
|
+
language: repo.primaryLanguage
|
|
274
|
+
? { name: repo.primaryLanguage.name, color: repo.primaryLanguage.color }
|
|
275
|
+
: null,
|
|
276
|
+
},
|
|
277
|
+
commits: 0,
|
|
278
|
+
share: 0,
|
|
279
|
+
days: [...ZEROS],
|
|
280
|
+
lyrics: lyricsFromHistory(repo.defaultBranchRef?.target?.history?.edges.map((e) => e.node) ?? []),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { contributionWindow } from './contributions.js';
|
|
3
|
+
// One query for the whole receipt: the 365-day calendar (TOTAL, the streaks,
|
|
4
|
+
// the best day and the barcode), the per-type contribution counts, and the
|
|
5
|
+
// repositories the user committed to (the line items). Field names checked
|
|
6
|
+
// against the live GraphQL schema (2026-09-19).
|
|
7
|
+
const QUERY = /* GraphQL */ `
|
|
8
|
+
query Receipt($login: String!, $from: DateTime!, $to: DateTime!) {
|
|
9
|
+
user(login: $login) {
|
|
10
|
+
contributionsCollection(from: $from, to: $to) {
|
|
11
|
+
contributionCalendar {
|
|
12
|
+
totalContributions
|
|
13
|
+
weeks {
|
|
14
|
+
contributionDays {
|
|
15
|
+
date
|
|
16
|
+
contributionCount
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
totalCommitContributions
|
|
21
|
+
totalPullRequestContributions
|
|
22
|
+
totalPullRequestReviewContributions
|
|
23
|
+
totalIssueContributions
|
|
24
|
+
totalRepositoryContributions
|
|
25
|
+
restrictedContributionsCount
|
|
26
|
+
commitContributionsByRepository(maxRepositories: 25) {
|
|
27
|
+
repository {
|
|
28
|
+
name
|
|
29
|
+
owner {
|
|
30
|
+
login
|
|
31
|
+
}
|
|
32
|
+
isPrivate
|
|
33
|
+
primaryLanguage {
|
|
34
|
+
name
|
|
35
|
+
color
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
contributions {
|
|
39
|
+
totalCount
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
/** Line items printed, at most. */
|
|
47
|
+
export const MAX_ITEMS = 5;
|
|
48
|
+
/** Days in the contribution window: 364 back plus the run date. */
|
|
49
|
+
export const WINDOW_DAYS = 365;
|
|
50
|
+
const languageSchema = z
|
|
51
|
+
.object({
|
|
52
|
+
name: z.string().min(1),
|
|
53
|
+
/** Linguist color; null when the repo has no language or color. */
|
|
54
|
+
color: z
|
|
55
|
+
.string()
|
|
56
|
+
.regex(/^#[0-9a-fA-F]{6}$/)
|
|
57
|
+
.nullable(),
|
|
58
|
+
})
|
|
59
|
+
.nullable();
|
|
60
|
+
export const receiptSchema = z.object({
|
|
61
|
+
/** Fetch date (= window end), YYYY-MM-DD (UTC). */
|
|
62
|
+
asOf: z.iso.date(),
|
|
63
|
+
from: z.iso.date(),
|
|
64
|
+
to: z.iso.date(),
|
|
65
|
+
/** The calendar's total, the number the profile shows. */
|
|
66
|
+
total: z.number().int().min(0),
|
|
67
|
+
commits: z.number().int().min(0),
|
|
68
|
+
pullRequests: z.number().int().min(0),
|
|
69
|
+
reviews: z.number().int().min(0),
|
|
70
|
+
issues: z.number().int().min(0),
|
|
71
|
+
newRepos: z.number().int().min(0),
|
|
72
|
+
/** Private contributions the token could see, without any repository named. */
|
|
73
|
+
restricted: z.number().int().min(0),
|
|
74
|
+
/** Public repositories committed to, most commits first. */
|
|
75
|
+
items: z
|
|
76
|
+
.array(z.object({
|
|
77
|
+
/** A repository the user does not own prints as `owner/name`. */
|
|
78
|
+
name: z.string().min(1),
|
|
79
|
+
language: languageSchema,
|
|
80
|
+
commits: z.number().int().min(1),
|
|
81
|
+
}))
|
|
82
|
+
.max(MAX_ITEMS),
|
|
83
|
+
/** Commits summed over the private repositories, never named. */
|
|
84
|
+
privateCommits: z.number().int().min(0),
|
|
85
|
+
/** Daily counts over the window, oldest first. */
|
|
86
|
+
days: z.array(z.number().int().min(0)).length(WINDOW_DAYS),
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* The line items: public repositories by commits in the window, ties by name.
|
|
90
|
+
* Private repositories are dropped here, before ranking; their commits are
|
|
91
|
+
* summed into `privateCommits` and never named.
|
|
92
|
+
*/
|
|
93
|
+
export function selectItems(entries, login, cap = MAX_ITEMS) {
|
|
94
|
+
const items = [];
|
|
95
|
+
let privateCommits = 0;
|
|
96
|
+
for (const entry of entries) {
|
|
97
|
+
const { repository } = entry;
|
|
98
|
+
if (repository.isPrivate) {
|
|
99
|
+
privateCommits += entry.contributions.totalCount;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
items.push({
|
|
103
|
+
name: repository.owner.login === login
|
|
104
|
+
? repository.name
|
|
105
|
+
: `${repository.owner.login}/${repository.name}`,
|
|
106
|
+
language: repository.primaryLanguage
|
|
107
|
+
? { name: repository.primaryLanguage.name, color: repository.primaryLanguage.color }
|
|
108
|
+
: null,
|
|
109
|
+
commits: entry.contributions.totalCount,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
items.sort((a, b) => b.commits - a.commits || a.name.localeCompare(b.name));
|
|
113
|
+
return { items: items.slice(0, cap), privateCommits };
|
|
114
|
+
}
|
|
115
|
+
export async function fetchReceipt(client, login, now) {
|
|
116
|
+
const { from, to } = contributionWindow(now);
|
|
117
|
+
const { user } = await client(QUERY, {
|
|
118
|
+
login,
|
|
119
|
+
from: `${from}T00:00:00Z`,
|
|
120
|
+
to: `${to}T23:59:59Z`,
|
|
121
|
+
});
|
|
122
|
+
const cc = user.contributionsCollection;
|
|
123
|
+
// Calendar weeks are padded to full weeks; keep only the window's days.
|
|
124
|
+
const days = cc.contributionCalendar.weeks
|
|
125
|
+
.flatMap((week) => week.contributionDays)
|
|
126
|
+
.filter((day) => day.date >= from && day.date <= to)
|
|
127
|
+
.map((day) => day.contributionCount);
|
|
128
|
+
const { items, privateCommits } = selectItems(cc.commitContributionsByRepository, login);
|
|
129
|
+
return {
|
|
130
|
+
asOf: to,
|
|
131
|
+
from,
|
|
132
|
+
to,
|
|
133
|
+
total: cc.contributionCalendar.totalContributions,
|
|
134
|
+
commits: cc.totalCommitContributions,
|
|
135
|
+
pullRequests: cc.totalPullRequestContributions,
|
|
136
|
+
reviews: cc.totalPullRequestReviewContributions,
|
|
137
|
+
issues: cc.totalIssueContributions,
|
|
138
|
+
newRepos: cc.totalRepositoryContributions,
|
|
139
|
+
restricted: cc.restrictedContributionsCount,
|
|
140
|
+
items,
|
|
141
|
+
privateCommits,
|
|
142
|
+
days,
|
|
143
|
+
};
|
|
144
|
+
}
|
package/dist/core/fonts.js
CHANGED
|
@@ -5,6 +5,9 @@ const FONT_FILES = [
|
|
|
5
5
|
'SpaceGrotesk-Medium.ttf',
|
|
6
6
|
'SpaceGrotesk-Bold.ttf',
|
|
7
7
|
'JetBrainsMono-Regular.ttf',
|
|
8
|
+
// Handwriting face for Now Playing's cassette label. Variable font: Skia
|
|
9
|
+
// registers the default 400 instance and ignores other weights.
|
|
10
|
+
'Caveat.ttf',
|
|
8
11
|
];
|
|
9
12
|
// Resolves from both src/core (tsx, vitest) and dist/core (published build).
|
|
10
13
|
const FONT_DIR = new URL('../../assets/fonts/', import.meta.url);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaks and peaks over a flat array of daily contribution counts, oldest
|
|
3
|
+
* first. Shared by Highlights Reel and Receipt.
|
|
4
|
+
*/
|
|
5
|
+
/** Longest run of consecutive days with at least one contribution. */
|
|
6
|
+
export function longestStreak(days) {
|
|
7
|
+
let best = 0;
|
|
8
|
+
let run = 0;
|
|
9
|
+
for (const count of days) {
|
|
10
|
+
run = count > 0 ? run + 1 : 0;
|
|
11
|
+
if (run > best)
|
|
12
|
+
best = run;
|
|
13
|
+
}
|
|
14
|
+
return best;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Consecutive active days ending on the last day, or on the day before it
|
|
18
|
+
* when the last day is still empty: a scheduled run often happens before the
|
|
19
|
+
* day's work.
|
|
20
|
+
*/
|
|
21
|
+
export function currentStreak(days) {
|
|
22
|
+
let end = days.length - 1;
|
|
23
|
+
if (days[end] <= 0)
|
|
24
|
+
end--;
|
|
25
|
+
let run = 0;
|
|
26
|
+
for (let i = end; i >= 0 && days[i] > 0; i--)
|
|
27
|
+
run++;
|
|
28
|
+
return run;
|
|
29
|
+
}
|
|
30
|
+
/** The day with the highest count, or null when every day is empty. */
|
|
31
|
+
export function bestDay(days) {
|
|
32
|
+
let best = null;
|
|
33
|
+
days.forEach((count, index) => {
|
|
34
|
+
if (count > 0 && (best === null || count >= best.count))
|
|
35
|
+
best = { index, count };
|
|
36
|
+
});
|
|
37
|
+
return best;
|
|
38
|
+
}
|
|
@@ -2,8 +2,9 @@ const AMBER = [232, 163, 61];
|
|
|
2
2
|
/**
|
|
3
3
|
* Accent presets, [light, dark]. Each passes 4.5:1 against its theme's desk,
|
|
4
4
|
* the lowest background its small type sits on (see SPEC, Highlights Reel).
|
|
5
|
+
* Receipt shares them: its counter is this desk.
|
|
5
6
|
*/
|
|
6
|
-
const ACCENT_VALUES = {
|
|
7
|
+
export const ACCENT_VALUES = {
|
|
7
8
|
cobalt: [
|
|
8
9
|
[53, 88, 232],
|
|
9
10
|
[123, 147, 255],
|