chapa-cli 0.2.7 → 0.2.8
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/LICENSE +21 -0
- package/README.md +84 -32
- package/dist/index.js +13 -16
- package/package.json +16 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 juan294
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,58 +1,110 @@
|
|
|
1
1
|
# chapa-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/chapa-cli)
|
|
4
|
+
[](https://github.com/juan294/chapa-cli/actions/workflows/ci.yml)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://nodejs.org)
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
Merge GitHub Enterprise Managed User (EMU) contributions into your [Chapa](https://chapa.thecreativetoken.com) developer impact badge.
|
|
11
|
+
|
|
12
|
+
## Why?
|
|
13
|
+
|
|
14
|
+
If you use a GitHub EMU account at work, your contributions live on a separate identity from your personal GitHub. Chapa badges only see your personal account. This CLI bridges the gap by fetching your EMU stats and merging them into your Chapa badge.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g chapa-cli
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requires Node.js 18+.
|
|
6
23
|
|
|
7
24
|
## Quick start
|
|
8
25
|
|
|
9
26
|
```bash
|
|
10
|
-
# 1.
|
|
11
|
-
|
|
27
|
+
# 1. Log in with your personal GitHub (opens browser)
|
|
28
|
+
chapa login
|
|
12
29
|
|
|
13
|
-
# 2. Merge your EMU
|
|
14
|
-
|
|
30
|
+
# 2. Merge your EMU contributions
|
|
31
|
+
chapa merge --emu-handle your-emu-handle --emu-token ghp_your_emu_token
|
|
15
32
|
```
|
|
16
33
|
|
|
17
|
-
That's it! Your personal handle and auth token are auto-detected from the login step.
|
|
18
|
-
|
|
19
34
|
## Commands
|
|
20
35
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
### `chapa login`
|
|
37
|
+
|
|
38
|
+
Authenticate with the Chapa server. Opens a browser window where you approve the CLI with your **personal** GitHub account.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
chapa login
|
|
42
|
+
chapa login --server http://localhost:3001 # local dev
|
|
43
|
+
chapa login --insecure # corporate TLS interception
|
|
44
|
+
chapa login --verbose # debug polling
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `chapa logout`
|
|
48
|
+
|
|
49
|
+
Clear stored credentials from `~/.chapa/credentials.json`.
|
|
26
50
|
|
|
27
|
-
|
|
51
|
+
```bash
|
|
52
|
+
chapa logout
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### `chapa merge`
|
|
56
|
+
|
|
57
|
+
Fetch stats from your EMU account and upload them to Chapa.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
chapa merge --emu-handle your-emu-handle
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The EMU token can be provided via `--emu-token` flag or `GITHUB_EMU_TOKEN` environment variable. The token needs `read:user` scope.
|
|
28
64
|
|
|
29
|
-
|
|
30
|
-
|------|-------------|----------|
|
|
31
|
-
| `--emu-handle <handle>` | Your EMU GitHub handle | Yes |
|
|
32
|
-
| `--emu-token <token>` | EMU GitHub token | No* |
|
|
33
|
-
| `--handle <handle>` | Override personal handle | No |
|
|
34
|
-
| `--token <token>` | Override auth token | No |
|
|
35
|
-
| `--server <url>` | Chapa server URL | No |
|
|
36
|
-
| `--version`, `-v` | Show version number | |
|
|
37
|
-
| `--help`, `-h` | Show help message | |
|
|
65
|
+
## Options
|
|
38
66
|
|
|
39
|
-
|
|
67
|
+
| Flag | Description |
|
|
68
|
+
|------|-------------|
|
|
69
|
+
| `--emu-handle <handle>` | Your EMU GitHub handle (required for merge) |
|
|
70
|
+
| `--emu-token <token>` | EMU GitHub token (or set `GITHUB_EMU_TOKEN`) |
|
|
71
|
+
| `--handle <handle>` | Override personal handle (auto-detected from login) |
|
|
72
|
+
| `--token <token>` | Override auth token (auto-detected from login) |
|
|
73
|
+
| `--server <url>` | Chapa server URL (default: production) |
|
|
74
|
+
| `--verbose` | Show detailed polling logs during login |
|
|
75
|
+
| `--insecure` | Skip TLS certificate verification |
|
|
76
|
+
| `--version`, `-v` | Show version number |
|
|
77
|
+
| `--help`, `-h` | Show help message |
|
|
40
78
|
|
|
41
|
-
##
|
|
79
|
+
## Corporate networks
|
|
42
80
|
|
|
43
|
-
|
|
81
|
+
Many corporate networks use TLS interception (MITM proxies). If you see errors like:
|
|
82
|
+
|
|
83
|
+
- `UNABLE_TO_VERIFY_LEAF_SIGNATURE`
|
|
84
|
+
- `SELF_SIGNED_CERT_IN_CHAIN`
|
|
85
|
+
- `self-signed certificate in certificate chain`
|
|
86
|
+
|
|
87
|
+
Use the `--insecure` flag:
|
|
44
88
|
|
|
45
89
|
```bash
|
|
46
|
-
|
|
90
|
+
chapa login --insecure
|
|
91
|
+
chapa merge --emu-handle your-emu --insecure
|
|
47
92
|
```
|
|
48
93
|
|
|
94
|
+
This disables TLS certificate verification for the CLI session only.
|
|
95
|
+
|
|
49
96
|
## How it works
|
|
50
97
|
|
|
51
|
-
1.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
98
|
+
1. **Login**: The CLI generates a session ID, displays an authorization URL, and polls the Chapa server until you approve in the browser. Credentials are saved to `~/.chapa/credentials.json`.
|
|
99
|
+
|
|
100
|
+
2. **Merge**: The CLI fetches your EMU account's contribution data via GitHub's GraphQL API (using your EMU token), then uploads the aggregated stats to the Chapa server. Your badge will reflect the combined data on next refresh.
|
|
101
|
+
|
|
102
|
+
## Contributing
|
|
103
|
+
|
|
104
|
+
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
|
|
105
|
+
|
|
106
|
+
- [Report a bug](https://github.com/juan294/chapa-cli/issues/new?template=bug_report.yml)
|
|
107
|
+
- [Request a feature](https://github.com/juan294/chapa-cli/issues/new?template=feature_request.yml)
|
|
56
108
|
|
|
57
109
|
## License
|
|
58
110
|
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,9 @@ function resolveToken(flag, envVar) {
|
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
//
|
|
48
|
+
// src/shared.ts
|
|
49
|
+
var SCORING_WINDOW_DAYS = 365;
|
|
50
|
+
var PR_WEIGHT_AGG_CAP = 120;
|
|
49
51
|
var CONTRIBUTION_QUERY = `
|
|
50
52
|
query($login: String!, $since: DateTime!, $until: DateTime!, $historySince: GitTimestamp!, $historyUntil: GitTimestamp!) {
|
|
51
53
|
user(login: $login) {
|
|
@@ -101,18 +103,10 @@ query($login: String!, $since: DateTime!, $until: DateTime!, $historySince: GitT
|
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
`;
|
|
104
|
-
|
|
105
|
-
// ../shared/src/scoring.ts
|
|
106
106
|
function computePrWeight(pr) {
|
|
107
107
|
const w = 0.5 + 0.25 * Math.log(1 + pr.changedFiles) + 0.25 * Math.log(1 + pr.additions + pr.deletions);
|
|
108
108
|
return Math.min(w, 3);
|
|
109
109
|
}
|
|
110
|
-
|
|
111
|
-
// ../shared/src/constants.ts
|
|
112
|
-
var SCORING_WINDOW_DAYS = 365;
|
|
113
|
-
var PR_WEIGHT_AGG_CAP = 120;
|
|
114
|
-
|
|
115
|
-
// ../shared/src/stats-aggregation.ts
|
|
116
110
|
function buildStatsFromRaw(raw) {
|
|
117
111
|
const heatmapData = [];
|
|
118
112
|
for (const week of raw.contributionCalendar.weeks) {
|
|
@@ -177,6 +171,10 @@ function buildStatsFromRaw(raw) {
|
|
|
177
171
|
}
|
|
178
172
|
|
|
179
173
|
// src/fetch-emu.ts
|
|
174
|
+
var MAX_ERROR_BODY_LENGTH = 200;
|
|
175
|
+
function truncate(s, max) {
|
|
176
|
+
return s.length > max ? s.slice(0, max) + "..." : s;
|
|
177
|
+
}
|
|
180
178
|
async function fetchEmuStats(login2, emuToken) {
|
|
181
179
|
const now = /* @__PURE__ */ new Date();
|
|
182
180
|
const since = new Date(now);
|
|
@@ -202,21 +200,20 @@ async function fetchEmuStats(login2, emuToken) {
|
|
|
202
200
|
});
|
|
203
201
|
if (!res.ok) {
|
|
204
202
|
const body = await res.text().catch(() => "(unreadable)");
|
|
205
|
-
console.error(`[cli] GraphQL HTTP ${res.status}: ${body}`);
|
|
203
|
+
console.error(`[cli] GraphQL HTTP ${res.status}: ${truncate(body, MAX_ERROR_BODY_LENGTH)}`);
|
|
206
204
|
return null;
|
|
207
205
|
}
|
|
208
206
|
const json = await res.json();
|
|
209
207
|
if (json.errors) {
|
|
210
|
-
|
|
208
|
+
const errStr = truncate(JSON.stringify(json.errors), MAX_ERROR_BODY_LENGTH);
|
|
209
|
+
console.error(`[cli] GraphQL errors for ${login2}: ${errStr}`);
|
|
211
210
|
}
|
|
212
211
|
if (!json.data?.user) return null;
|
|
213
212
|
const user = json.data.user;
|
|
214
213
|
const cc = user.contributionsCollection;
|
|
215
214
|
const prNodes = cc.pullRequestContributions.nodes.filter(
|
|
216
215
|
(n) => n != null && n.pullRequest != null
|
|
217
|
-
).map(
|
|
218
|
-
(n) => n.pullRequest
|
|
219
|
-
);
|
|
216
|
+
).map((n) => n.pullRequest);
|
|
220
217
|
const raw = {
|
|
221
218
|
login: user.login,
|
|
222
219
|
name: user.name,
|
|
@@ -238,7 +235,7 @@ async function fetchEmuStats(login2, emuToken) {
|
|
|
238
235
|
};
|
|
239
236
|
return buildStatsFromRaw(raw);
|
|
240
237
|
} catch (err) {
|
|
241
|
-
console.error(
|
|
238
|
+
console.error("[cli] fetch error:", err.message);
|
|
242
239
|
return null;
|
|
243
240
|
}
|
|
244
241
|
}
|
|
@@ -431,7 +428,7 @@ Logged in as ${data.handle}!`);
|
|
|
431
428
|
}
|
|
432
429
|
|
|
433
430
|
// src/index.ts
|
|
434
|
-
var VERSION = true ? "0.2.
|
|
431
|
+
var VERSION = true ? "0.2.8" : "0.0.0-dev";
|
|
435
432
|
var HELP_TEXT = `chapa-cli v${VERSION}
|
|
436
433
|
|
|
437
434
|
Merge GitHub EMU (Enterprise Managed User) contributions into your Chapa badge.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chapa-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Merge GitHub EMU contributions into your Chapa developer impact badge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "tsup",
|
|
15
15
|
"prepublishOnly": "tsup",
|
|
16
|
-
"typecheck": "tsc --noEmit"
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"test:watch": "vitest",
|
|
19
|
+
"test:coverage": "vitest run --coverage",
|
|
20
|
+
"lint": "tsc --noEmit"
|
|
17
21
|
},
|
|
18
22
|
"keywords": [
|
|
19
23
|
"chapa",
|
|
@@ -22,22 +26,27 @@
|
|
|
22
26
|
"developer",
|
|
23
27
|
"impact",
|
|
24
28
|
"emu",
|
|
25
|
-
"cli"
|
|
29
|
+
"cli",
|
|
30
|
+
"enterprise-managed-users"
|
|
26
31
|
],
|
|
27
32
|
"author": "juan294",
|
|
28
33
|
"license": "MIT",
|
|
29
34
|
"repository": {
|
|
30
35
|
"type": "git",
|
|
31
|
-
"url": "https://github.com/juan294/chapa"
|
|
32
|
-
|
|
36
|
+
"url": "https://github.com/juan294/chapa-cli"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/juan294/chapa-cli#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/juan294/chapa-cli/issues"
|
|
33
41
|
},
|
|
34
42
|
"engines": {
|
|
35
43
|
"node": ">=18"
|
|
36
44
|
},
|
|
37
45
|
"devDependencies": {
|
|
38
|
-
"@chapa/shared": "workspace:*",
|
|
39
46
|
"@types/node": "^22.19.10",
|
|
47
|
+
"@vitest/coverage-v8": "^4.0.0",
|
|
40
48
|
"tsup": "^8.5.1",
|
|
41
|
-
"typescript": "^5.7.3"
|
|
49
|
+
"typescript": "^5.7.3",
|
|
50
|
+
"vitest": "^4.0.0"
|
|
42
51
|
}
|
|
43
52
|
}
|