chapa-cli 0.1.1 → 0.1.4

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 CHANGED
@@ -24,7 +24,7 @@ npx chapa-cli merge \
24
24
  | `--version`, `-v` | Show version number | |
25
25
  | `--help`, `-h` | Show help message | |
26
26
 
27
- *Tokens are resolved in order: flag > environment variable > `gh auth token`.
27
+ *Tokens are resolved in order: flag > environment variable (`GITHUB_TOKEN` / `GITHUB_EMU_TOKEN`).
28
28
 
29
29
  ## Token setup
30
30
 
@@ -39,7 +39,7 @@ Tokens need the `read:user` scope at minimum.
39
39
 
40
40
  ## How it works
41
41
 
42
- 1. Fetches your last 90 days of activity from the EMU account via GitHub GraphQL API
42
+ 1. Fetches your last 12 months of activity from the EMU account via GitHub GraphQL API
43
43
  2. Uploads the stats (commits, PRs merged, reviews) to the Chapa server
44
44
  3. Your Chapa badge recalculates on next refresh, combining personal + EMU contributions
45
45
 
package/dist/index.js CHANGED
@@ -90,6 +90,9 @@ query($login: String!, $since: DateTime!, $until: DateTime!, $historySince: GitT
90
90
  }
91
91
  }
92
92
  }
93
+ ownedRepos: repositories(ownerAffiliations: OWNER, first: 100, orderBy: {field: STARGAZERS, direction: DESC}) {
94
+ nodes { stargazerCount forkCount watchers { totalCount } }
95
+ }
93
96
  }
94
97
  }
95
98
  `;
@@ -100,8 +103,12 @@ function computePrWeight(pr) {
100
103
  return Math.min(w, 3);
101
104
  }
102
105
 
106
+ // ../shared/src/constants.ts
107
+ var SCORING_WINDOW_DAYS = 365;
108
+ var PR_WEIGHT_AGG_CAP = 120;
109
+
103
110
  // ../shared/src/stats-aggregation.ts
104
- function buildStats90dFromRaw(raw) {
111
+ function buildStatsFromRaw(raw) {
105
112
  const heatmapData = [];
106
113
  for (const week of raw.contributionCalendar.weeks) {
107
114
  for (const day of week.contributionDays) {
@@ -114,7 +121,7 @@ function buildStats90dFromRaw(raw) {
114
121
  const prsMergedCount = mergedPRs.length;
115
122
  const prsMergedWeight = Math.min(
116
123
  mergedPRs.reduce((sum, pr) => sum + computePrWeight(pr), 0),
117
- 40
124
+ PR_WEIGHT_AGG_CAP
118
125
  );
119
126
  const linesAdded = mergedPRs.reduce((sum, pr) => sum + pr.additions, 0);
120
127
  const linesDeleted = mergedPRs.reduce((sum, pr) => sum + pr.deletions, 0);
@@ -129,6 +136,18 @@ function buildStats90dFromRaw(raw) {
129
136
  const topRepoShare = totalRepoCommits > 0 ? Math.max(...repoCommits.map((r) => r.commits)) / totalRepoCommits : 0;
130
137
  const maxDailyCount = Math.max(...heatmapData.map((d) => d.count), 0);
131
138
  const maxCommitsIn10Min = maxDailyCount >= 30 ? maxDailyCount : 0;
139
+ const totalStars = raw.ownedRepoStars.nodes.reduce(
140
+ (sum, r) => sum + r.stargazerCount,
141
+ 0
142
+ );
143
+ const totalForks = raw.ownedRepoStars.nodes.reduce(
144
+ (sum, r) => sum + r.forkCount,
145
+ 0
146
+ );
147
+ const totalWatchers = raw.ownedRepoStars.nodes.reduce(
148
+ (sum, r) => sum + r.watchers.totalCount,
149
+ 0
150
+ );
132
151
  return {
133
152
  handle: raw.login,
134
153
  displayName: raw.name ?? void 0,
@@ -144,6 +163,9 @@ function buildStats90dFromRaw(raw) {
144
163
  reposContributed,
145
164
  topRepoShare,
146
165
  maxCommitsIn10Min,
166
+ totalStars,
167
+ totalForks,
168
+ totalWatchers,
147
169
  heatmapData,
148
170
  fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
149
171
  };
@@ -153,7 +175,7 @@ function buildStats90dFromRaw(raw) {
153
175
  async function fetchEmuStats(login, emuToken) {
154
176
  const now = /* @__PURE__ */ new Date();
155
177
  const since = new Date(now);
156
- since.setDate(since.getDate() - 90);
178
+ since.setDate(since.getDate() - SCORING_WINDOW_DAYS);
157
179
  try {
158
180
  const res = await fetch("https://api.github.com/graphql", {
159
181
  method: "POST",
@@ -179,6 +201,9 @@ async function fetchEmuStats(login, emuToken) {
179
201
  return null;
180
202
  }
181
203
  const json = await res.json();
204
+ if (json.errors) {
205
+ console.error(`[cli] GraphQL errors for ${login}:`, json.errors);
206
+ }
182
207
  if (!json.data?.user) return null;
183
208
  const user = json.data.user;
184
209
  const cc = user.contributionsCollection;
@@ -201,9 +226,12 @@ async function fetchEmuStats(login, emuToken) {
201
226
  repositories: {
202
227
  totalCount: user.repositories.totalCount,
203
228
  nodes: user.repositories.nodes
229
+ },
230
+ ownedRepoStars: {
231
+ nodes: (user.ownedRepos?.nodes ?? []).filter((n) => n != null).map((n) => ({ stargazerCount: n.stargazerCount, forkCount: n.forkCount, watchers: { totalCount: n.watchers.totalCount } }))
204
232
  }
205
233
  };
206
- return buildStats90dFromRaw(raw);
234
+ return buildStatsFromRaw(raw);
207
235
  } catch (err) {
208
236
  console.error(`[cli] fetch error:`, err);
209
237
  return null;
@@ -244,7 +272,7 @@ async function uploadSupplementalStats(opts) {
244
272
  }
245
273
 
246
274
  // src/index.ts
247
- var VERSION = true ? "0.1.1" : "0.0.0-dev";
275
+ var VERSION = true ? "0.1.4" : "0.0.0-dev";
248
276
  var HELP_TEXT = `chapa-cli v${VERSION}
249
277
 
250
278
  Merge GitHub EMU (Enterprise Managed User) contributions into your Chapa badge.
@@ -284,12 +312,12 @@ async function main() {
284
312
  }
285
313
  const emuToken = resolveToken(args.emuToken, "GITHUB_EMU_TOKEN");
286
314
  if (!emuToken) {
287
- console.error("Error: EMU token required. Use --emu-token, set GITHUB_EMU_TOKEN, or ensure `gh auth token` works.");
315
+ console.error("Error: EMU token required. Use --emu-token or set GITHUB_EMU_TOKEN.");
288
316
  process.exit(1);
289
317
  }
290
318
  const personalToken = resolveToken(args.token, "GITHUB_TOKEN");
291
319
  if (!personalToken) {
292
- console.error("Error: Personal token required. Use --token, set GITHUB_TOKEN, or ensure `gh auth token` works.");
320
+ console.error("Error: Personal token required. Use --token or set GITHUB_TOKEN.");
293
321
  process.exit(1);
294
322
  }
295
323
  console.log(`Fetching stats for EMU account: ${emuHandle}...`);
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "chapa-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "Merge GitHub EMU contributions into your Chapa developer impact badge",
5
5
  "type": "module",
6
6
  "bin": {
7
+ "chapa-cli": "dist/index.js",
7
8
  "chapa": "dist/index.js"
8
9
  },
9
10
  "files": [