Skip to content

Commit 1ae29d7

Browse files
author
release bot
committed
1.2.3
1 parent f4ce3f3 commit 1ae29d7

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

dist/cli.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function getInput(name) {
5353
*/
5454
function parseArgs(argv) {
5555
const parsed = {
56+
defaultColors: false,
5657
dark: false,
5758
light: false,
5859
};
@@ -64,6 +65,9 @@ function parseArgs(argv) {
6465
else if (arg === "--token" && i + 1 < argv.length) {
6566
parsed.token = argv[++i];
6667
}
68+
else if (arg === "--default-colors") {
69+
parsed.defaultColors = true;
70+
}
6771
else if (arg === "--dark") {
6872
parsed.dark = true;
6973
}
@@ -101,6 +105,7 @@ const bricksColorsFromInput = bricksColorsInput.length === 5
101105
const options = {
102106
username: cliArgs.username || getInput("GITHUB_USERNAME"),
103107
token: cliArgs.token || getInput("GITHUB_TOKEN"),
108+
defaultColors: cliArgs.defaultColors,
104109
dark: cliArgs.dark,
105110
light: cliArgs.light,
106111
enableGhostBricks: (_b = cliArgs.enableGhostBricks) !== null && _b !== void 0 ? _b : ((_c = getInput("ENABLE_GHOST_BRICKS")) !== null && _c !== void 0 ? _c : "true") === "true",
@@ -118,10 +123,11 @@ if (!options.username || !options.token) {
118123
// Default options
119124
if (!options.dark &&
120125
!options.light &&
126+
!options.defaultColors &&
121127
!options.bricksColors &&
122128
!options.paddleColor &&
123129
!options.ballColor) {
124-
options.light = true; // Default to light mode if neither is specified
130+
options.defaultColors = true; // Default colors if neither is specified
125131
// Enable both for GitHub actions by default
126132
if (process.env.GITHUB_ACTIONS === "true") {
127133
options.dark = true;
@@ -144,6 +150,9 @@ if (options.paddleColor || options.ballColor || options.bricksColors) {
144150
name: "custom",
145151
});
146152
}
153+
if (options.defaultColors) {
154+
variants.push({ bricksColors: undefined, name: "light" });
155+
}
147156
if (options.light) {
148157
variants.push({ bricksColors: "github_light", name: "light" });
149158
}

dist/svg.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const GITHUB_DARK = [
4444
*
4545
* @param userName - The GitHub username to fetch contributions for.
4646
* @param githubToken - A GitHub personal access token with appropriate permissions.
47-
* @returns A 2D array representing weeks and days, where each element contains the color string or null.
47+
* @returns The default color palette and a 2D array representing weeks and days, where each element contains the color string or null.
4848
* @throws Will throw an error if the API request fails or returns errors.
4949
*/
5050
function fetchGithubContributionsGraphQL(userName, githubToken) {
@@ -58,6 +58,7 @@ function fetchGithubContributionsGraphQL(userName, githubToken) {
5858
contributionDays {
5959
contributionLevel
6060
contributionCount
61+
color
6162
}
6263
}
6364
}
@@ -84,22 +85,34 @@ function fetchGithubContributionsGraphQL(userName, githubToken) {
8485
}
8586
// Format the contribution days into a 2D array of objects (weeks x days)
8687
const weeks = json.data.user.contributionsCollection.contributionCalendar.weeks;
88+
const defaultColorPalette = {
89+
0: "#000",
90+
1: "#000",
91+
2: "#000",
92+
3: "#000",
93+
4: "#000",
94+
};
8795
const levels = [];
8896
for (let c = 0; c < weeks.length; c++) {
8997
levels[c] = [];
9098
const days = weeks[c].contributionDays;
9199
for (let r = 0; r < days.length; r++) {
100+
const level = (days[r].contributionLevel === "FOURTH_QUARTILE" && 4) ||
101+
(days[r].contributionLevel === "THIRD_QUARTILE" && 3) ||
102+
(days[r].contributionLevel === "SECOND_QUARTILE" && 2) ||
103+
(days[r].contributionLevel === "FIRST_QUARTILE" && 1) ||
104+
0;
105+
defaultColorPalette[level] = days[r].color;
92106
levels[c][r] = {
93-
level: (days[r].contributionLevel === "FOURTH_QUARTILE" && 4) ||
94-
(days[r].contributionLevel === "THIRD_QUARTILE" && 3) ||
95-
(days[r].contributionLevel === "SECOND_QUARTILE" && 2) ||
96-
(days[r].contributionLevel === "FIRST_QUARTILE" && 1) ||
97-
0,
107+
level,
98108
contributionCount: days[r].contributionCount,
99109
};
100110
}
101111
}
102-
return levels;
112+
return {
113+
days: levels,
114+
defaultColorPalette: Object.values(defaultColorPalette),
115+
};
103116
});
104117
}
105118
/**
@@ -233,10 +246,10 @@ function minifySVG(svg) {
233246
*/
234247
function generateSVG(username_1, githubToken_1) {
235248
return __awaiter(this, arguments, void 0, function* (username, githubToken, options = {}) {
236-
const { enableGhostBricks = true, paddleColor = "#1F6FEB", ballColor = "#1F6FEB", bricksColors = "github_light", } = options;
249+
const { enableGhostBricks = true, paddleColor = "#1F6FEB", ballColor = "#1F6FEB", bricksColors, } = options;
237250
const colorDays = yield fetchGithubContributionsGraphQL(username, githubToken);
238251
// The number of columns (weeks) is determined by the API response
239-
const brickColumnCount = colorDays.length;
252+
const brickColumnCount = colorDays.days.length;
240253
// Calculate canvasWidth and canvasHeight dynamically
241254
const canvasWidth = brickColumnCount * (BRICK_SIZE + BRICK_GAP) + PADDING * 2 - BRICK_GAP; // right edge flush
242255
// Bricks area height
@@ -248,7 +261,7 @@ function generateSVG(username_1, githubToken_1) {
248261
// The ball and paddle should have enough space at the bottom (add a little margin)
249262
const canvasHeight = paddleY + PADDLE_HEIGHT + PADDING;
250263
// Pick palette
251-
let colorPalette = GITHUB_LIGHT;
264+
let colorPalette = colorDays.defaultColorPalette;
252265
if (bricksColors === "github_light") {
253266
colorPalette = GITHUB_LIGHT;
254267
}
@@ -262,7 +275,7 @@ function generateSVG(username_1, githubToken_1) {
262275
const bricks = [];
263276
for (let c = 0; c < brickColumnCount; c++) {
264277
for (let r = 0; r < 7; r++) {
265-
const day = (colorDays[c] && colorDays[c][r]) || null;
278+
const day = (colorDays.days[c] && colorDays.days[c][r]) || null;
266279
if (!day)
267280
continue; // skip bricks for missing days
268281
bricks.push({

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-breakout",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "Generate a Breakout game SVG from a GitHub user's contributions graph",
55
"main": "src/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)