contribute-now 0.4.0 → 0.4.1-dev.6ee6f2c
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 +88 -8
- package/dist/index.js +559 -72
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ bun install -g contribute-now
|
|
|
64
64
|
## Prerequisites
|
|
65
65
|
|
|
66
66
|
- **[Git](https://git-scm.com/)** — required
|
|
67
|
-
- **[GitHub CLI](https://cli.github.com)** (`gh`) —
|
|
67
|
+
- **[GitHub CLI](https://cli.github.com)** (`gh`) — recommended; required for PR creation, role detection, and merge status checks
|
|
68
68
|
- **[GitHub Copilot](https://github.com/features/copilot)** — optional; enables AI features
|
|
69
69
|
|
|
70
70
|
---
|
|
@@ -129,10 +129,13 @@ Stage your changes and create a validated, AI-generated commit message matching
|
|
|
129
129
|
contrib commit # AI-generated message
|
|
130
130
|
contrib commit --no-ai # manual entry, still validated
|
|
131
131
|
contrib commit --model gpt-4.1 # specific AI model
|
|
132
|
+
contrib commit --group # AI groups changes into atomic commits
|
|
132
133
|
```
|
|
133
134
|
|
|
134
135
|
After the AI generates a message, you can **accept**, **edit**, **regenerate**, or **write manually**. Messages are always validated against your convention — with a soft warning if they don't match (you can still commit).
|
|
135
136
|
|
|
137
|
+
**Group commit mode** (`--group`): AI analyzes all staged and unstaged changes, groups related files into logical atomic commits, and generates a commit message for each group. Great for splitting a large set of changes into clean, reviewable commits.
|
|
138
|
+
|
|
136
139
|
---
|
|
137
140
|
|
|
138
141
|
### `contrib update`
|
|
@@ -180,6 +183,57 @@ contrib status
|
|
|
180
183
|
|
|
181
184
|
---
|
|
182
185
|
|
|
186
|
+
### `contrib doctor`
|
|
187
|
+
|
|
188
|
+
Diagnose the contribute-now CLI environment and configuration. Checks tools, dependencies, config, git state, fork setup, workflow, and environment.
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
contrib doctor # pretty-printed report
|
|
192
|
+
contrib doctor --json # machine-readable JSON output
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Checks include:
|
|
196
|
+
- CLI version and runtime (Bun/Node)
|
|
197
|
+
- git and GitHub CLI availability and authentication
|
|
198
|
+
- `.contributerc.json` validity and `.gitignore` status
|
|
199
|
+
- Git repo state (uncommitted changes, lock files, shallow clone)
|
|
200
|
+
- Fork and remote configuration
|
|
201
|
+
- Workflow and branch setup
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
### `contrib log`
|
|
206
|
+
|
|
207
|
+
Show a colorized, workflow-aware commit log. By default it shows only **local unpushed commits** — the changes you've made since the last push (or since branching off the base branch). Use flags to switch between different views.
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
contrib log # local unpushed commits (default)
|
|
211
|
+
contrib log --remote # commits on remote not yet pulled
|
|
212
|
+
contrib log --full # full history for the current branch
|
|
213
|
+
contrib log --all # commits across all branches
|
|
214
|
+
contrib log -n 50 # change the commit limit (default: 20)
|
|
215
|
+
contrib log -b feature/x # log for a specific branch
|
|
216
|
+
contrib log --no-graph # flat view without graph lines
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
When no upstream tracking is set (branch hasn't been pushed yet), the command automatically compares against the base branch from your config (e.g., `origin/dev`). Protected branches are highlighted, and the current branch is color-coded for quick orientation.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### `contrib branch`
|
|
224
|
+
|
|
225
|
+
List branches with workflow-aware labels and tracking status.
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
contrib branch # local branches
|
|
229
|
+
contrib branch --all # local + remote branches
|
|
230
|
+
contrib branch --remote # remote branches only
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Branches are annotated with workflow labels (e.g., base, dev, feature) and tracking info (upstream, gone, no remote).
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
183
237
|
### `contrib hook`
|
|
184
238
|
|
|
185
239
|
Install or uninstall a `commit-msg` git hook that validates every commit against your configured convention — no Husky or lint-staged needed.
|
|
@@ -210,8 +264,9 @@ contrib validate "added stuff" # exit 1
|
|
|
210
264
|
All AI features are powered by **GitHub Copilot** via `@github/copilot-sdk` and are entirely **optional** — every command has a manual fallback.
|
|
211
265
|
|
|
212
266
|
| Command | AI Feature | Fallback |
|
|
213
|
-
|
|
267
|
+
|---------|------------|----------|
|
|
214
268
|
| `commit` | Generate commit message from staged diff | Type manually |
|
|
269
|
+
| `commit --group` | Group related changes into atomic commits | Manual staging + commit |
|
|
215
270
|
| `start` | Suggest branch name from natural language | Prefix picker + manual |
|
|
216
271
|
| `update` | Conflict resolution guidance | Standard git instructions |
|
|
217
272
|
| `submit` | Generate PR title and body | `gh pr create --fill` or manual |
|
|
@@ -299,15 +354,40 @@ bun test # run tests
|
|
|
299
354
|
bun run lint # check code quality
|
|
300
355
|
```
|
|
301
356
|
|
|
302
|
-
## Contributing
|
|
357
|
+
## 🎯 Contributing
|
|
303
358
|
|
|
304
|
-
Contributions are welcome
|
|
359
|
+
Contributions are welcome, create a pull request to this repo and I will review your code. Please consider to submit your pull request to the `dev` branch. Thank you!
|
|
305
360
|
|
|
306
|
-
|
|
361
|
+
Read the project's [contributing guide](./CONTRIBUTING.md) for more info.
|
|
307
362
|
|
|
308
|
-
|
|
363
|
+
## 🐛 Issues
|
|
309
364
|
|
|
310
|
-
|
|
365
|
+
Please report any issues and bugs by [creating a new issue here](https://github.com/warengonzaga/contribute-now/issues/new/choose), also make sure you're reporting an issue that doesn't exist. Any help to improve the project would be appreciated. Thanks! 🙏✨
|
|
366
|
+
|
|
367
|
+
## 🙏 Sponsor
|
|
368
|
+
|
|
369
|
+
Like this project? **Leave a star**! ⭐⭐⭐⭐⭐
|
|
370
|
+
|
|
371
|
+
Want to support my work and get some perks? [Become a sponsor](https://github.com/sponsors/warengonzaga)! 💖
|
|
372
|
+
|
|
373
|
+
Or, you just love what I do? [Buy me a coffee](https://buymeacoffee.com/warengonzaga)! ☕
|
|
311
374
|
|
|
312
|
-
|
|
375
|
+
Recognized my open-source contributions? [Nominate me](https://stars.github.com/nominate) as GitHub Star! 💫
|
|
376
|
+
|
|
377
|
+
## 📋 Code of Conduct
|
|
378
|
+
|
|
379
|
+
Read the project's [code of conduct](./CODE_OF_CONDUCT.md).
|
|
380
|
+
|
|
381
|
+
## 📃 License
|
|
382
|
+
|
|
383
|
+
This project is licensed under [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0).
|
|
384
|
+
|
|
385
|
+
## 📝 Author
|
|
386
|
+
|
|
387
|
+
This project is created by **[Waren Gonzaga](https://github.com/warengonzaga)**, with the help of awesome [contributors](https://github.com/warengonzaga/contribute-now/graphs/contributors).
|
|
388
|
+
|
|
389
|
+
[](https://github.com/warengonzaga/contribute-now/graphs/contributors)
|
|
390
|
+
|
|
391
|
+
---
|
|
313
392
|
|
|
393
|
+
💻💖☕ by [Waren Gonzaga](https://warengonzaga.com) & [YHWH](https://www.youtube.com/watch?v=VOZbswniA-g) 🙏 — Without *Him*, none of this exists, *even me*.
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { defineCommand } from "citty";
|
|
|
10
10
|
import pc2 from "picocolors";
|
|
11
11
|
|
|
12
12
|
// src/utils/config.ts
|
|
13
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { appendFileSync, existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
var CONFIG_FILENAME = ".contributerc.json";
|
|
16
16
|
function getConfigPath(cwd = process.cwd()) {
|
|
@@ -86,6 +86,23 @@ function isGitignored(cwd = process.cwd()) {
|
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
function ensureGitignored(cwd = process.cwd()) {
|
|
90
|
+
if (isGitignored(cwd))
|
|
91
|
+
return false;
|
|
92
|
+
const gitignorePath = join(cwd, ".gitignore");
|
|
93
|
+
const line = `${CONFIG_FILENAME}
|
|
94
|
+
`;
|
|
95
|
+
if (!existsSync(gitignorePath)) {
|
|
96
|
+
writeFileSync(gitignorePath, line, "utf-8");
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
const content = readFileSync(gitignorePath, "utf-8");
|
|
100
|
+
const needsLeadingNewline = content.length > 0 && !content.endsWith(`
|
|
101
|
+
`);
|
|
102
|
+
appendFileSync(gitignorePath, `${needsLeadingNewline ? `
|
|
103
|
+
` : ""}${line}`, "utf-8");
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
89
106
|
function getDefaultConfig() {
|
|
90
107
|
return {
|
|
91
108
|
workflow: "clean-flow",
|
|
@@ -530,6 +547,76 @@ async function getLogEntries(options) {
|
|
|
530
547
|
return { hash: hash.trim(), subject: subject.trim(), refs: refs.trim() };
|
|
531
548
|
});
|
|
532
549
|
}
|
|
550
|
+
async function getLocalCommitsGraph(options) {
|
|
551
|
+
const count = options?.count ?? 20;
|
|
552
|
+
const upstream = options?.upstream;
|
|
553
|
+
if (!upstream)
|
|
554
|
+
return [];
|
|
555
|
+
const args = [
|
|
556
|
+
"log",
|
|
557
|
+
"--oneline",
|
|
558
|
+
"--graph",
|
|
559
|
+
"--decorate",
|
|
560
|
+
`--max-count=${count}`,
|
|
561
|
+
"--color=never",
|
|
562
|
+
`${upstream}..HEAD`
|
|
563
|
+
];
|
|
564
|
+
const { exitCode, stdout } = await run(args);
|
|
565
|
+
if (exitCode !== 0)
|
|
566
|
+
return [];
|
|
567
|
+
return stdout.trimEnd().split(`
|
|
568
|
+
`).filter(Boolean);
|
|
569
|
+
}
|
|
570
|
+
async function getLocalCommitsEntries(options) {
|
|
571
|
+
const count = options?.count ?? 20;
|
|
572
|
+
const upstream = options?.upstream;
|
|
573
|
+
if (!upstream)
|
|
574
|
+
return [];
|
|
575
|
+
const args = ["log", `--format=%h||%s||%D`, `--max-count=${count}`, `${upstream}..HEAD`];
|
|
576
|
+
const { exitCode, stdout } = await run(args);
|
|
577
|
+
if (exitCode !== 0)
|
|
578
|
+
return [];
|
|
579
|
+
return stdout.trimEnd().split(`
|
|
580
|
+
`).filter(Boolean).map((line) => {
|
|
581
|
+
const [hash = "", subject = "", refs = ""] = line.split("||");
|
|
582
|
+
return { hash: hash.trim(), subject: subject.trim(), refs: refs.trim() };
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
async function getRemoteOnlyCommitsGraph(options) {
|
|
586
|
+
const count = options?.count ?? 20;
|
|
587
|
+
const upstream = options?.upstream;
|
|
588
|
+
if (!upstream)
|
|
589
|
+
return [];
|
|
590
|
+
const args = [
|
|
591
|
+
"log",
|
|
592
|
+
"--oneline",
|
|
593
|
+
"--graph",
|
|
594
|
+
"--decorate",
|
|
595
|
+
`--max-count=${count}`,
|
|
596
|
+
"--color=never",
|
|
597
|
+
`HEAD..${upstream}`
|
|
598
|
+
];
|
|
599
|
+
const { exitCode, stdout } = await run(args);
|
|
600
|
+
if (exitCode !== 0)
|
|
601
|
+
return [];
|
|
602
|
+
return stdout.trimEnd().split(`
|
|
603
|
+
`).filter(Boolean);
|
|
604
|
+
}
|
|
605
|
+
async function getRemoteOnlyCommitsEntries(options) {
|
|
606
|
+
const count = options?.count ?? 20;
|
|
607
|
+
const upstream = options?.upstream;
|
|
608
|
+
if (!upstream)
|
|
609
|
+
return [];
|
|
610
|
+
const args = ["log", `--format=%h||%s||%D`, `--max-count=${count}`, `HEAD..${upstream}`];
|
|
611
|
+
const { exitCode, stdout } = await run(args);
|
|
612
|
+
if (exitCode !== 0)
|
|
613
|
+
return [];
|
|
614
|
+
return stdout.trimEnd().split(`
|
|
615
|
+
`).filter(Boolean).map((line) => {
|
|
616
|
+
const [hash = "", subject = "", refs = ""] = line.split("||");
|
|
617
|
+
return { hash: hash.trim(), subject: subject.trim(), refs: refs.trim() };
|
|
618
|
+
});
|
|
619
|
+
}
|
|
533
620
|
async function getLocalBranches() {
|
|
534
621
|
const { exitCode, stdout } = await run(["branch", "-vv", "--no-color"]);
|
|
535
622
|
if (exitCode !== 0)
|
|
@@ -953,6 +1040,79 @@ function withTimeout(promise, ms) {
|
|
|
953
1040
|
}
|
|
954
1041
|
var COPILOT_TIMEOUT_MS = 30000;
|
|
955
1042
|
var COPILOT_LONG_TIMEOUT_MS = 90000;
|
|
1043
|
+
var BATCH_CONFIG = {
|
|
1044
|
+
LARGE_CHANGESET_THRESHOLD: 15,
|
|
1045
|
+
COMPACT_PER_FILE_CHARS: 300,
|
|
1046
|
+
MAX_COMPACT_PAYLOAD: 1e4,
|
|
1047
|
+
FALLBACK_BATCH_SIZE: 15
|
|
1048
|
+
};
|
|
1049
|
+
function parseDiffByFile(rawDiff) {
|
|
1050
|
+
const sections = new Map;
|
|
1051
|
+
const headerPattern = /^diff --git a\/(.+?) b\/(.+?)$/gm;
|
|
1052
|
+
const positions = [];
|
|
1053
|
+
for (let match = headerPattern.exec(rawDiff);match !== null; match = headerPattern.exec(rawDiff)) {
|
|
1054
|
+
const aFile = match[1];
|
|
1055
|
+
const bFile = match[2] ?? aFile;
|
|
1056
|
+
positions.push({ aFile, bFile, start: match.index });
|
|
1057
|
+
}
|
|
1058
|
+
for (let i = 0;i < positions.length; i++) {
|
|
1059
|
+
const { aFile, bFile, start } = positions[i];
|
|
1060
|
+
const end = i + 1 < positions.length ? positions[i + 1].start : rawDiff.length;
|
|
1061
|
+
const section = rawDiff.slice(start, end);
|
|
1062
|
+
sections.set(aFile, section);
|
|
1063
|
+
if (bFile && bFile !== aFile) {
|
|
1064
|
+
sections.set(bFile, section);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
return sections;
|
|
1068
|
+
}
|
|
1069
|
+
function extractDiffStats(diffSection) {
|
|
1070
|
+
let added = 0;
|
|
1071
|
+
let removed = 0;
|
|
1072
|
+
for (const line of diffSection.split(`
|
|
1073
|
+
`)) {
|
|
1074
|
+
if (line.startsWith("+") && !line.startsWith("+++"))
|
|
1075
|
+
added++;
|
|
1076
|
+
if (line.startsWith("-") && !line.startsWith("---"))
|
|
1077
|
+
removed++;
|
|
1078
|
+
}
|
|
1079
|
+
return { added, removed };
|
|
1080
|
+
}
|
|
1081
|
+
function createCompactDiff(files, rawDiff, maxTotalChars = BATCH_CONFIG.MAX_COMPACT_PAYLOAD) {
|
|
1082
|
+
if (files.length === 0)
|
|
1083
|
+
return "";
|
|
1084
|
+
const diffSections = parseDiffByFile(rawDiff);
|
|
1085
|
+
const perFileBudget = Math.min(BATCH_CONFIG.COMPACT_PER_FILE_CHARS, Math.floor(maxTotalChars / files.length));
|
|
1086
|
+
const parts = [];
|
|
1087
|
+
for (const file of files) {
|
|
1088
|
+
const section = diffSections.get(file);
|
|
1089
|
+
if (section) {
|
|
1090
|
+
const stats = extractDiffStats(section);
|
|
1091
|
+
const header = `[${file}] (+${stats.added}/-${stats.removed})`;
|
|
1092
|
+
if (section.length <= perFileBudget) {
|
|
1093
|
+
parts.push(`${header}
|
|
1094
|
+
${section}`);
|
|
1095
|
+
} else {
|
|
1096
|
+
const availableForBody = perFileBudget - header.length - 20;
|
|
1097
|
+
if (availableForBody <= 0) {
|
|
1098
|
+
parts.push(header);
|
|
1099
|
+
} else {
|
|
1100
|
+
const truncated = section.slice(0, availableForBody);
|
|
1101
|
+
parts.push(`${header}
|
|
1102
|
+
${truncated}
|
|
1103
|
+
...(truncated)`);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
} else {
|
|
1107
|
+
parts.push(`[${file}] (new/binary file — no diff available)`);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
const result = parts.join(`
|
|
1111
|
+
|
|
1112
|
+
`);
|
|
1113
|
+
return result.length > maxTotalChars ? `${result.slice(0, maxTotalChars - 15)}
|
|
1114
|
+
...(truncated)` : result;
|
|
1115
|
+
}
|
|
956
1116
|
async function checkCopilotAvailable() {
|
|
957
1117
|
try {
|
|
958
1118
|
const client = await getManagedClient();
|
|
@@ -1053,16 +1213,18 @@ function extractJson(raw) {
|
|
|
1053
1213
|
}
|
|
1054
1214
|
async function generateCommitMessage(diff, stagedFiles, model, convention = "clean-commit") {
|
|
1055
1215
|
try {
|
|
1216
|
+
const isLarge = stagedFiles.length >= BATCH_CONFIG.LARGE_CHANGESET_THRESHOLD;
|
|
1056
1217
|
const multiFileHint = stagedFiles.length > 1 ? `
|
|
1057
1218
|
|
|
1058
1219
|
IMPORTANT: Multiple files are staged. Generate ONE commit message that captures the high-level purpose of ALL changes together. Focus on the overall intent, not individual file changes. Be specific but concise — do not list every file.` : "";
|
|
1220
|
+
const diffContent = isLarge ? createCompactDiff(stagedFiles, diff) : diff.slice(0, 4000);
|
|
1059
1221
|
const userMessage = `Generate a commit message for these staged changes:
|
|
1060
1222
|
|
|
1061
|
-
Files: ${stagedFiles.join(", ")}
|
|
1223
|
+
Files (${stagedFiles.length}): ${stagedFiles.join(", ")}
|
|
1062
1224
|
|
|
1063
1225
|
Diff:
|
|
1064
|
-
${
|
|
1065
|
-
const result = await callCopilot(getCommitSystemPrompt(convention), userMessage, model);
|
|
1226
|
+
${diffContent}${multiFileHint}`;
|
|
1227
|
+
const result = await callCopilot(getCommitSystemPrompt(convention), userMessage, model, isLarge ? COPILOT_LONG_TIMEOUT_MS : COPILOT_TIMEOUT_MS);
|
|
1066
1228
|
return result?.trim() ?? null;
|
|
1067
1229
|
} catch {
|
|
1068
1230
|
return null;
|
|
@@ -1111,16 +1273,23 @@ ${conflictDiff.slice(0, 4000)}`;
|
|
|
1111
1273
|
}
|
|
1112
1274
|
}
|
|
1113
1275
|
async function generateCommitGroups(files, diffs, model, convention = "clean-commit") {
|
|
1276
|
+
const isLarge = files.length >= BATCH_CONFIG.LARGE_CHANGESET_THRESHOLD;
|
|
1277
|
+
const diffContent = isLarge ? createCompactDiff(files, diffs) : diffs.slice(0, 6000);
|
|
1278
|
+
const largeHint = isLarge ? `
|
|
1279
|
+
|
|
1280
|
+
NOTE: This is a large changeset (${files.length} files). Compact diffs are provided for every file. Focus on creating well-organized logical groups.` : "";
|
|
1114
1281
|
const userMessage = `Group these changed files into logical atomic commits:
|
|
1115
1282
|
|
|
1116
1283
|
Files:
|
|
1117
1284
|
${files.join(`
|
|
1118
1285
|
`)}
|
|
1119
1286
|
|
|
1120
|
-
Diffs
|
|
1121
|
-
${
|
|
1287
|
+
Diffs:
|
|
1288
|
+
${diffContent}${largeHint}`;
|
|
1122
1289
|
const result = await callCopilot(getGroupingSystemPrompt(convention), userMessage, model, COPILOT_LONG_TIMEOUT_MS);
|
|
1123
1290
|
if (!result) {
|
|
1291
|
+
if (isLarge)
|
|
1292
|
+
return generateCommitGroupsInBatches(files, diffs, model, convention);
|
|
1124
1293
|
throw new Error("AI returned an empty response");
|
|
1125
1294
|
}
|
|
1126
1295
|
const cleaned = extractJson(result);
|
|
@@ -1128,10 +1297,14 @@ ${diffs.slice(0, 6000)}`;
|
|
|
1128
1297
|
try {
|
|
1129
1298
|
parsed = JSON.parse(cleaned);
|
|
1130
1299
|
} catch {
|
|
1300
|
+
if (isLarge)
|
|
1301
|
+
return generateCommitGroupsInBatches(files, diffs, model, convention);
|
|
1131
1302
|
throw new Error(`AI response is not valid JSON. Raw start: "${result.slice(0, 120)}..."`);
|
|
1132
1303
|
}
|
|
1133
1304
|
const groups = parsed;
|
|
1134
1305
|
if (!Array.isArray(groups) || groups.length === 0) {
|
|
1306
|
+
if (isLarge)
|
|
1307
|
+
return generateCommitGroupsInBatches(files, diffs, model, convention);
|
|
1135
1308
|
throw new Error("AI response was not a valid JSON array of commit groups");
|
|
1136
1309
|
}
|
|
1137
1310
|
for (const group of groups) {
|
|
@@ -1141,7 +1314,63 @@ ${diffs.slice(0, 6000)}`;
|
|
|
1141
1314
|
}
|
|
1142
1315
|
return groups;
|
|
1143
1316
|
}
|
|
1317
|
+
async function generateCommitGroupsInBatches(files, diffs, model, convention = "clean-commit") {
|
|
1318
|
+
const batchSize = BATCH_CONFIG.FALLBACK_BATCH_SIZE;
|
|
1319
|
+
const allGroups = [];
|
|
1320
|
+
const diffSections = parseDiffByFile(diffs);
|
|
1321
|
+
for (let i = 0;i < files.length; i += batchSize) {
|
|
1322
|
+
const batchFiles = files.slice(i, i + batchSize);
|
|
1323
|
+
const batchDiff = batchFiles.map((f) => diffSections.get(f) ?? "").filter(Boolean).join(`
|
|
1324
|
+
`);
|
|
1325
|
+
const batchDiffContent = batchFiles.length >= BATCH_CONFIG.LARGE_CHANGESET_THRESHOLD ? createCompactDiff(batchFiles, batchDiff) : batchDiff.slice(0, 6000);
|
|
1326
|
+
const batchNum = Math.floor(i / batchSize) + 1;
|
|
1327
|
+
const totalBatches = Math.ceil(files.length / batchSize);
|
|
1328
|
+
const userMessage = `Group these changed files into logical atomic commits:
|
|
1329
|
+
|
|
1330
|
+
Files:
|
|
1331
|
+
${batchFiles.join(`
|
|
1332
|
+
`)}
|
|
1333
|
+
|
|
1334
|
+
Diffs:
|
|
1335
|
+
${batchDiffContent}
|
|
1336
|
+
|
|
1337
|
+
NOTE: Processing batch ${batchNum}/${totalBatches} of a large changeset. Group only the files listed above.`;
|
|
1338
|
+
try {
|
|
1339
|
+
const result = await callCopilot(getGroupingSystemPrompt(convention), userMessage, model, COPILOT_LONG_TIMEOUT_MS);
|
|
1340
|
+
if (!result)
|
|
1341
|
+
continue;
|
|
1342
|
+
const cleaned = extractJson(result);
|
|
1343
|
+
const parsed = JSON.parse(cleaned);
|
|
1344
|
+
if (Array.isArray(parsed)) {
|
|
1345
|
+
for (const group of parsed) {
|
|
1346
|
+
if (Array.isArray(group.files) && typeof group.message === "string") {
|
|
1347
|
+
const batchFileSet = new Set(batchFiles);
|
|
1348
|
+
const filteredFiles = group.files.filter((f) => batchFileSet.has(f));
|
|
1349
|
+
if (filteredFiles.length > 0) {
|
|
1350
|
+
allGroups.push({ ...group, files: filteredFiles });
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
} catch {}
|
|
1356
|
+
}
|
|
1357
|
+
const groupedFiles = new Set(allGroups.flatMap((g) => g.files));
|
|
1358
|
+
const ungrouped = files.filter((f) => !groupedFiles.has(f));
|
|
1359
|
+
if (ungrouped.length > 0) {
|
|
1360
|
+
allGroups.push({
|
|
1361
|
+
files: ungrouped,
|
|
1362
|
+
message: `chore: update ${ungrouped.length} remaining file${ungrouped.length !== 1 ? "s" : ""}`
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
if (allGroups.length === 0) {
|
|
1366
|
+
throw new Error("AI could not group any files even with batch processing");
|
|
1367
|
+
}
|
|
1368
|
+
return allGroups;
|
|
1369
|
+
}
|
|
1144
1370
|
async function regenerateAllGroupMessages(groups, diffs, model, convention = "clean-commit") {
|
|
1371
|
+
const totalFiles = groups.reduce((sum, g) => sum + g.files.length, 0);
|
|
1372
|
+
const isLarge = totalFiles >= BATCH_CONFIG.LARGE_CHANGESET_THRESHOLD;
|
|
1373
|
+
const diffContent = isLarge ? createCompactDiff(groups.flatMap((g) => g.files), diffs) : diffs.slice(0, 6000);
|
|
1145
1374
|
const groupSummary = groups.map((g, i) => `Group ${i + 1}: [${g.files.join(", ")}]`).join(`
|
|
1146
1375
|
`);
|
|
1147
1376
|
const userMessage = `Regenerate ONLY the commit messages for these pre-defined file groups. Do NOT change the file groupings.
|
|
@@ -1149,8 +1378,8 @@ async function regenerateAllGroupMessages(groups, diffs, model, convention = "cl
|
|
|
1149
1378
|
Groups:
|
|
1150
1379
|
${groupSummary}
|
|
1151
1380
|
|
|
1152
|
-
Diffs
|
|
1153
|
-
${
|
|
1381
|
+
Diffs:
|
|
1382
|
+
${diffContent}`;
|
|
1154
1383
|
const result = await callCopilot(getGroupingSystemPrompt(convention), userMessage, model, COPILOT_LONG_TIMEOUT_MS);
|
|
1155
1384
|
if (!result)
|
|
1156
1385
|
return groups;
|
|
@@ -1169,12 +1398,14 @@ ${diffs.slice(0, 6000)}`;
|
|
|
1169
1398
|
}
|
|
1170
1399
|
async function regenerateGroupMessage(files, diffs, model, convention = "clean-commit") {
|
|
1171
1400
|
try {
|
|
1401
|
+
const isLarge = files.length >= BATCH_CONFIG.LARGE_CHANGESET_THRESHOLD;
|
|
1402
|
+
const diffContent = isLarge ? createCompactDiff(files, diffs) : diffs.slice(0, 4000);
|
|
1172
1403
|
const userMessage = `Generate a single commit message for these files:
|
|
1173
1404
|
|
|
1174
1405
|
Files: ${files.join(", ")}
|
|
1175
1406
|
|
|
1176
1407
|
Diff:
|
|
1177
|
-
${
|
|
1408
|
+
${diffContent}`;
|
|
1178
1409
|
const result = await callCopilot(getCommitSystemPrompt(convention), userMessage, model);
|
|
1179
1410
|
return result?.trim() ?? null;
|
|
1180
1411
|
} catch {
|
|
@@ -1732,7 +1963,8 @@ ${pc6.bold("Changed files:")}`);
|
|
|
1732
1963
|
warn(`AI unavailable: ${copilotError}`);
|
|
1733
1964
|
warn("Falling back to manual commit message entry.");
|
|
1734
1965
|
} else {
|
|
1735
|
-
const
|
|
1966
|
+
const spinnerMsg = stagedFiles.length >= BATCH_CONFIG.LARGE_CHANGESET_THRESHOLD ? `Generating commit message with AI (${stagedFiles.length} files — using optimized batching)...` : "Generating commit message with AI...";
|
|
1967
|
+
const spinner = createSpinner(spinnerMsg);
|
|
1736
1968
|
commitMessage = await generateCommitMessage(diff, stagedFiles, args.model, config.commitConvention);
|
|
1737
1969
|
if (commitMessage) {
|
|
1738
1970
|
spinner.success("AI commit message generated.");
|
|
@@ -1823,7 +2055,7 @@ ${pc6.bold("Changed files:")}`);
|
|
|
1823
2055
|
for (const f of changedFiles) {
|
|
1824
2056
|
console.log(` ${pc6.dim("•")} ${f}`);
|
|
1825
2057
|
}
|
|
1826
|
-
const spinner = createSpinner(`Asking AI to group ${changedFiles.length} file(s) into logical commits...`);
|
|
2058
|
+
const spinner = createSpinner(changedFiles.length >= BATCH_CONFIG.LARGE_CHANGESET_THRESHOLD ? `Asking AI to group ${changedFiles.length} file(s) into logical commits (using optimized batching)...` : `Asking AI to group ${changedFiles.length} file(s) into logical commits...`);
|
|
1827
2059
|
const diffs = await getFullDiffForFiles(changedFiles);
|
|
1828
2060
|
if (!diffs.trim()) {
|
|
1829
2061
|
spinner.stop();
|
|
@@ -2001,8 +2233,8 @@ import pc7 from "picocolors";
|
|
|
2001
2233
|
// package.json
|
|
2002
2234
|
var package_default = {
|
|
2003
2235
|
name: "contribute-now",
|
|
2004
|
-
version: "0.4.
|
|
2005
|
-
description: "
|
|
2236
|
+
version: "0.4.1-dev.6ee6f2c",
|
|
2237
|
+
description: "Developer CLI that automates git workflows — branching, syncing, committing, and PRs — with multi-workflow and commit convention support.",
|
|
2006
2238
|
type: "module",
|
|
2007
2239
|
bin: {
|
|
2008
2240
|
contrib: "dist/index.js",
|
|
@@ -2019,9 +2251,10 @@ var package_default = {
|
|
|
2019
2251
|
lint: "biome check .",
|
|
2020
2252
|
"lint:fix": "biome check --write .",
|
|
2021
2253
|
format: "biome format --write .",
|
|
2022
|
-
"
|
|
2023
|
-
"
|
|
2024
|
-
"
|
|
2254
|
+
"landing:install": "bun install --cwd landing",
|
|
2255
|
+
"landing:dev": "bun run --cwd landing dev",
|
|
2256
|
+
"landing:build": "bun run --cwd landing build",
|
|
2257
|
+
"landing:preview": "bun run --cwd landing preview"
|
|
2025
2258
|
},
|
|
2026
2259
|
engines: {
|
|
2027
2260
|
node: ">=18",
|
|
@@ -2519,7 +2752,19 @@ var log_default = defineCommand6({
|
|
|
2519
2752
|
all: {
|
|
2520
2753
|
type: "boolean",
|
|
2521
2754
|
alias: "a",
|
|
2522
|
-
description: "Show all branches
|
|
2755
|
+
description: "Show commits from all branches",
|
|
2756
|
+
default: false
|
|
2757
|
+
},
|
|
2758
|
+
remote: {
|
|
2759
|
+
type: "boolean",
|
|
2760
|
+
alias: "r",
|
|
2761
|
+
description: "Show only remote commits not yet pulled locally",
|
|
2762
|
+
default: false
|
|
2763
|
+
},
|
|
2764
|
+
full: {
|
|
2765
|
+
type: "boolean",
|
|
2766
|
+
alias: "f",
|
|
2767
|
+
description: "Show full commit history for the current branch",
|
|
2523
2768
|
default: false
|
|
2524
2769
|
},
|
|
2525
2770
|
graph: {
|
|
@@ -2541,44 +2786,197 @@ var log_default = defineCommand6({
|
|
|
2541
2786
|
}
|
|
2542
2787
|
const config = readConfig();
|
|
2543
2788
|
const count = args.count ? Number.parseInt(args.count, 10) : 20;
|
|
2544
|
-
const showAll = args.all;
|
|
2545
2789
|
const showGraph = args.graph;
|
|
2546
2790
|
const targetBranch = args.branch;
|
|
2791
|
+
let mode = "local";
|
|
2792
|
+
if (args.all)
|
|
2793
|
+
mode = "all";
|
|
2794
|
+
else if (args.remote)
|
|
2795
|
+
mode = "remote";
|
|
2796
|
+
else if (args.full || targetBranch)
|
|
2797
|
+
mode = "full";
|
|
2547
2798
|
const protectedBranches = config ? getProtectedBranches(config) : ["main", "master"];
|
|
2548
2799
|
const currentBranch = await getCurrentBranch();
|
|
2800
|
+
const upstream = await getUpstreamRef();
|
|
2801
|
+
let compareRef = upstream;
|
|
2802
|
+
let usingFallback = false;
|
|
2803
|
+
if (!compareRef) {
|
|
2804
|
+
const fallback = await resolveBaseBranchRef(config);
|
|
2805
|
+
if (fallback) {
|
|
2806
|
+
compareRef = fallback;
|
|
2807
|
+
usingFallback = true;
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2549
2810
|
heading("\uD83D\uDCDC commit log");
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
if (
|
|
2553
|
-
console.log(
|
|
2811
|
+
printModeHeader(mode, currentBranch, compareRef, usingFallback);
|
|
2812
|
+
if (mode === "local" || mode === "remote") {
|
|
2813
|
+
if (!compareRef) {
|
|
2814
|
+
console.log();
|
|
2815
|
+
console.log(pc9.yellow(" ⚠ Could not determine a comparison branch."));
|
|
2816
|
+
console.log(pc9.dim(" No upstream tracking set and no remote base branch found."));
|
|
2817
|
+
console.log(pc9.dim(` Use ${pc9.bold("contrib log --full")} to see the full commit history instead.`));
|
|
2554
2818
|
console.log();
|
|
2819
|
+
printGuidance();
|
|
2555
2820
|
return;
|
|
2556
2821
|
}
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2822
|
+
const hasCommits = await renderScopedLog({ mode, count, upstream: compareRef, showGraph, protectedBranches, currentBranch });
|
|
2823
|
+
if (!hasCommits) {
|
|
2824
|
+
printGuidance();
|
|
2825
|
+
return;
|
|
2560
2826
|
}
|
|
2561
2827
|
} else {
|
|
2562
|
-
const
|
|
2563
|
-
if (
|
|
2564
|
-
|
|
2565
|
-
console.log();
|
|
2828
|
+
const hasCommits = await renderFullLog({ count, all: mode === "all", showGraph, targetBranch, protectedBranches, currentBranch });
|
|
2829
|
+
if (!hasCommits) {
|
|
2830
|
+
printGuidance();
|
|
2566
2831
|
return;
|
|
2567
2832
|
}
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2833
|
+
}
|
|
2834
|
+
printFooter(mode, count, targetBranch);
|
|
2835
|
+
printGuidance();
|
|
2836
|
+
}
|
|
2837
|
+
});
|
|
2838
|
+
async function resolveBaseBranchRef(config) {
|
|
2839
|
+
if (!config) {
|
|
2840
|
+
for (const candidate2 of ["origin/main", "origin/master"]) {
|
|
2841
|
+
if (await branchExists(candidate2))
|
|
2842
|
+
return candidate2;
|
|
2843
|
+
}
|
|
2844
|
+
return null;
|
|
2845
|
+
}
|
|
2846
|
+
const baseBranch = getBaseBranch(config);
|
|
2847
|
+
const remote = config.origin ?? "origin";
|
|
2848
|
+
const candidate = `${remote}/${baseBranch}`;
|
|
2849
|
+
if (await branchExists(candidate))
|
|
2850
|
+
return candidate;
|
|
2851
|
+
for (const fallback of ["origin/main", "origin/master"]) {
|
|
2852
|
+
if (fallback !== candidate && await branchExists(fallback))
|
|
2853
|
+
return fallback;
|
|
2854
|
+
}
|
|
2855
|
+
return null;
|
|
2856
|
+
}
|
|
2857
|
+
function printModeHeader(mode, currentBranch, compareRef, usingFallback = false) {
|
|
2858
|
+
const branch = currentBranch ?? "HEAD";
|
|
2859
|
+
const fallbackNote = usingFallback ? pc9.yellow(" (no upstream — comparing against base branch)") : "";
|
|
2860
|
+
console.log();
|
|
2861
|
+
switch (mode) {
|
|
2862
|
+
case "local":
|
|
2863
|
+
console.log(pc9.dim(` mode: ${pc9.bold("local")} — unpushed commits on ${pc9.bold(branch)}`) + fallbackNote);
|
|
2864
|
+
if (compareRef) {
|
|
2865
|
+
console.log(pc9.dim(` comparing: ${pc9.bold(compareRef)} ➜ ${pc9.bold("HEAD")}`));
|
|
2574
2866
|
}
|
|
2867
|
+
break;
|
|
2868
|
+
case "remote":
|
|
2869
|
+
console.log(pc9.dim(` mode: ${pc9.bold("remote")} — commits on remote not yet pulled into ${pc9.bold(branch)}`) + fallbackNote);
|
|
2870
|
+
if (compareRef) {
|
|
2871
|
+
console.log(pc9.dim(` comparing: ${pc9.bold("HEAD")} ➜ ${pc9.bold(compareRef)}`));
|
|
2872
|
+
}
|
|
2873
|
+
break;
|
|
2874
|
+
case "full":
|
|
2875
|
+
console.log(pc9.dim(` mode: ${pc9.bold("full")} — complete commit history for ${pc9.bold(branch)}`));
|
|
2876
|
+
break;
|
|
2877
|
+
case "all":
|
|
2878
|
+
console.log(pc9.dim(` mode: ${pc9.bold("all")} — commits across all branches`));
|
|
2879
|
+
break;
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
async function renderScopedLog(options) {
|
|
2883
|
+
const { mode, count, upstream, showGraph, protectedBranches, currentBranch } = options;
|
|
2884
|
+
if (showGraph) {
|
|
2885
|
+
const graphFn = mode === "local" ? getLocalCommitsGraph : getRemoteOnlyCommitsGraph;
|
|
2886
|
+
const lines = await graphFn({ count, upstream });
|
|
2887
|
+
if (lines.length === 0) {
|
|
2888
|
+
printEmptyState(mode);
|
|
2889
|
+
return false;
|
|
2575
2890
|
}
|
|
2576
2891
|
console.log();
|
|
2577
|
-
|
|
2578
|
-
|
|
2892
|
+
for (const line of lines) {
|
|
2893
|
+
console.log(` ${colorizeGraphLine(line, protectedBranches, currentBranch)}`);
|
|
2894
|
+
}
|
|
2895
|
+
} else {
|
|
2896
|
+
const entryFn = mode === "local" ? getLocalCommitsEntries : getRemoteOnlyCommitsEntries;
|
|
2897
|
+
const entries = await entryFn({ count, upstream });
|
|
2898
|
+
if (entries.length === 0) {
|
|
2899
|
+
printEmptyState(mode);
|
|
2900
|
+
return false;
|
|
2901
|
+
}
|
|
2579
2902
|
console.log();
|
|
2903
|
+
for (const entry of entries) {
|
|
2904
|
+
const hashStr = pc9.yellow(entry.hash);
|
|
2905
|
+
const refsStr = entry.refs ? ` ${colorizeRefs(entry.refs, protectedBranches, currentBranch)}` : "";
|
|
2906
|
+
const subjectStr = colorizeSubject(entry.subject);
|
|
2907
|
+
console.log(` ${hashStr}${refsStr} ${subjectStr}`);
|
|
2908
|
+
}
|
|
2580
2909
|
}
|
|
2581
|
-
|
|
2910
|
+
return true;
|
|
2911
|
+
}
|
|
2912
|
+
function printEmptyState(mode) {
|
|
2913
|
+
console.log();
|
|
2914
|
+
if (mode === "local") {
|
|
2915
|
+
console.log(pc9.dim(" No local unpushed commits — you're up to date with remote!"));
|
|
2916
|
+
} else {
|
|
2917
|
+
console.log(pc9.dim(" No remote-only commits — your local branch is up to date!"));
|
|
2918
|
+
}
|
|
2919
|
+
console.log();
|
|
2920
|
+
}
|
|
2921
|
+
async function renderFullLog(options) {
|
|
2922
|
+
const { count, all, showGraph, targetBranch, protectedBranches, currentBranch } = options;
|
|
2923
|
+
if (showGraph) {
|
|
2924
|
+
const lines = await getLogGraph({ count, all, branch: targetBranch });
|
|
2925
|
+
if (lines.length === 0) {
|
|
2926
|
+
console.log(pc9.dim(" No commits found."));
|
|
2927
|
+
console.log();
|
|
2928
|
+
return false;
|
|
2929
|
+
}
|
|
2930
|
+
console.log();
|
|
2931
|
+
for (const line of lines) {
|
|
2932
|
+
console.log(` ${colorizeGraphLine(line, protectedBranches, currentBranch)}`);
|
|
2933
|
+
}
|
|
2934
|
+
} else {
|
|
2935
|
+
const entries = await getLogEntries({ count, all, branch: targetBranch });
|
|
2936
|
+
if (entries.length === 0) {
|
|
2937
|
+
console.log(pc9.dim(" No commits found."));
|
|
2938
|
+
console.log();
|
|
2939
|
+
return false;
|
|
2940
|
+
}
|
|
2941
|
+
console.log();
|
|
2942
|
+
for (const entry of entries) {
|
|
2943
|
+
const hashStr = pc9.yellow(entry.hash);
|
|
2944
|
+
const refsStr = entry.refs ? ` ${colorizeRefs(entry.refs, protectedBranches, currentBranch)}` : "";
|
|
2945
|
+
const subjectStr = colorizeSubject(entry.subject);
|
|
2946
|
+
console.log(` ${hashStr}${refsStr} ${subjectStr}`);
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
return true;
|
|
2950
|
+
}
|
|
2951
|
+
function printFooter(mode, count, targetBranch) {
|
|
2952
|
+
console.log();
|
|
2953
|
+
switch (mode) {
|
|
2954
|
+
case "local":
|
|
2955
|
+
console.log(pc9.dim(` Showing up to ${count} unpushed commits`));
|
|
2956
|
+
break;
|
|
2957
|
+
case "remote":
|
|
2958
|
+
console.log(pc9.dim(` Showing up to ${count} remote-only commits`));
|
|
2959
|
+
break;
|
|
2960
|
+
case "full":
|
|
2961
|
+
console.log(pc9.dim(` Showing ${count} most recent commits${targetBranch ? ` (${targetBranch})` : ""}`));
|
|
2962
|
+
break;
|
|
2963
|
+
case "all":
|
|
2964
|
+
console.log(pc9.dim(` Showing ${count} most recent commits (all branches)`));
|
|
2965
|
+
break;
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
function printGuidance() {
|
|
2969
|
+
console.log();
|
|
2970
|
+
console.log(pc9.dim(" ─── quick guide ───"));
|
|
2971
|
+
console.log(pc9.dim(` ${pc9.bold("contrib log")} local unpushed commits (default)`));
|
|
2972
|
+
console.log(pc9.dim(` ${pc9.bold("contrib log --remote")} commits on remote not yet pulled`));
|
|
2973
|
+
console.log(pc9.dim(` ${pc9.bold("contrib log --full")} full history for the current branch`));
|
|
2974
|
+
console.log(pc9.dim(` ${pc9.bold("contrib log --all")} commits across all branches`));
|
|
2975
|
+
console.log(pc9.dim(` ${pc9.bold("contrib log -n 50")} change the commit limit (default: 20)`));
|
|
2976
|
+
console.log(pc9.dim(` ${pc9.bold("contrib log -b dev")} view log for a specific branch`));
|
|
2977
|
+
console.log(pc9.dim(` ${pc9.bold("contrib log --no-graph")} flat list without graph lines`));
|
|
2978
|
+
console.log();
|
|
2979
|
+
}
|
|
2582
2980
|
function colorizeGraphLine(line, protectedBranches, currentBranch) {
|
|
2583
2981
|
const match = line.match(/^([|/\\*\s_.-]*)([a-f0-9]{7,12})(\s+\(([^)]+)\))?\s*(.*)/);
|
|
2584
2982
|
if (!match) {
|
|
@@ -2660,6 +3058,43 @@ function colorizeSubject(subject) {
|
|
|
2660
3058
|
// src/commands/setup.ts
|
|
2661
3059
|
import { defineCommand as defineCommand7 } from "citty";
|
|
2662
3060
|
import pc10 from "picocolors";
|
|
3061
|
+
async function shouldContinueSetupWithExistingConfig(options) {
|
|
3062
|
+
const {
|
|
3063
|
+
existingConfig,
|
|
3064
|
+
hasConfigFile,
|
|
3065
|
+
confirm: confirm2,
|
|
3066
|
+
ensureIgnored,
|
|
3067
|
+
onInfo,
|
|
3068
|
+
onWarn,
|
|
3069
|
+
onSuccess,
|
|
3070
|
+
summary
|
|
3071
|
+
} = options;
|
|
3072
|
+
if (existingConfig) {
|
|
3073
|
+
onInfo("Existing .contributerc.json detected:");
|
|
3074
|
+
summary(existingConfig);
|
|
3075
|
+
const shouldContinue = await confirm2("Continue setup and overwrite existing config?");
|
|
3076
|
+
if (!shouldContinue) {
|
|
3077
|
+
if (ensureIgnored()) {
|
|
3078
|
+
onInfo("Added .contributerc.json to .gitignore to avoid committing personal config.");
|
|
3079
|
+
}
|
|
3080
|
+
onSuccess("Keeping existing setup.");
|
|
3081
|
+
return false;
|
|
3082
|
+
}
|
|
3083
|
+
return true;
|
|
3084
|
+
}
|
|
3085
|
+
if (hasConfigFile) {
|
|
3086
|
+
onWarn("Found .contributerc.json but it appears invalid.");
|
|
3087
|
+
const shouldContinue = await confirm2("Continue setup and overwrite invalid config?");
|
|
3088
|
+
if (!shouldContinue) {
|
|
3089
|
+
if (ensureIgnored()) {
|
|
3090
|
+
onInfo("Added .contributerc.json to .gitignore to avoid committing personal config.");
|
|
3091
|
+
}
|
|
3092
|
+
onInfo("Keeping existing file. Run setup again when ready to repair it.");
|
|
3093
|
+
return false;
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
return true;
|
|
3097
|
+
}
|
|
2663
3098
|
var setup_default = defineCommand7({
|
|
2664
3099
|
meta: {
|
|
2665
3100
|
name: "setup",
|
|
@@ -2671,6 +3106,20 @@ var setup_default = defineCommand7({
|
|
|
2671
3106
|
process.exit(1);
|
|
2672
3107
|
}
|
|
2673
3108
|
heading("\uD83D\uDD27 contribute-now setup");
|
|
3109
|
+
const existingConfig = readConfig();
|
|
3110
|
+
const shouldContinue = await shouldContinueSetupWithExistingConfig({
|
|
3111
|
+
existingConfig,
|
|
3112
|
+
hasConfigFile: configExists(),
|
|
3113
|
+
confirm: confirmPrompt,
|
|
3114
|
+
ensureIgnored: ensureGitignored,
|
|
3115
|
+
onInfo: info,
|
|
3116
|
+
onWarn: warn,
|
|
3117
|
+
onSuccess: success,
|
|
3118
|
+
summary: logConfigSummary
|
|
3119
|
+
});
|
|
3120
|
+
if (!shouldContinue) {
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
2674
3123
|
const workflowChoice = await selectPrompt("Which git workflow does this project use?", [
|
|
2675
3124
|
"Clean Flow — main + dev, squash features into dev, merge dev into main (recommended)",
|
|
2676
3125
|
"GitHub Flow — main + feature branches, squash/merge into main",
|
|
@@ -2700,31 +3149,42 @@ var setup_default = defineCommand7({
|
|
|
2700
3149
|
info(`Found remotes: ${remotes.join(", ")}`);
|
|
2701
3150
|
let detectedRole = null;
|
|
2702
3151
|
let detectionSource = "";
|
|
2703
|
-
const
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
3152
|
+
const roleSpinner = createSpinner("Detecting your role...");
|
|
3153
|
+
try {
|
|
3154
|
+
roleSpinner.update("Checking GitHub CLI and auth...");
|
|
3155
|
+
const ghInstalled = await checkGhInstalled();
|
|
3156
|
+
if (ghInstalled && await checkGhAuth()) {
|
|
3157
|
+
roleSpinner.update("Inspecting repository relationship (fork/permissions)...");
|
|
3158
|
+
const isFork = await isRepoFork();
|
|
3159
|
+
if (isFork === true) {
|
|
3160
|
+
detectedRole = "contributor";
|
|
3161
|
+
detectionSource = "gh CLI (fork detected)";
|
|
3162
|
+
} else if (isFork === false) {
|
|
3163
|
+
const repoInfo = await getCurrentRepoInfo();
|
|
3164
|
+
if (repoInfo) {
|
|
3165
|
+
const perms = await checkRepoPermissions(repoInfo.owner, repoInfo.repo);
|
|
3166
|
+
if (perms?.admin || perms?.push) {
|
|
3167
|
+
detectedRole = "maintainer";
|
|
3168
|
+
detectionSource = "gh CLI (admin/push permissions)";
|
|
3169
|
+
}
|
|
2716
3170
|
}
|
|
2717
3171
|
}
|
|
2718
3172
|
}
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
3173
|
+
if (detectedRole === null) {
|
|
3174
|
+
roleSpinner.update("Analyzing git remotes...");
|
|
3175
|
+
if (remotes.includes("upstream")) {
|
|
3176
|
+
detectedRole = "contributor";
|
|
3177
|
+
detectionSource = "heuristic (upstream remote exists)";
|
|
3178
|
+
} else if (remotes.includes("origin") && remotes.length === 1) {
|
|
3179
|
+
detectedRole = "maintainer";
|
|
3180
|
+
detectionSource = "heuristic (only origin remote)";
|
|
3181
|
+
}
|
|
2727
3182
|
}
|
|
3183
|
+
roleSpinner.success("Role detection complete.");
|
|
3184
|
+
} catch {
|
|
3185
|
+
roleSpinner.fail("Role detection failed; falling back to manual selection.");
|
|
3186
|
+
detectedRole = null;
|
|
3187
|
+
detectionSource = "";
|
|
2728
3188
|
}
|
|
2729
3189
|
if (detectedRole === null) {
|
|
2730
3190
|
const roleChoice = await selectPrompt("What is your role in this project?", [
|
|
@@ -2742,16 +3202,20 @@ var setup_default = defineCommand7({
|
|
|
2742
3202
|
}
|
|
2743
3203
|
}
|
|
2744
3204
|
const defaultConfig = getDefaultConfig();
|
|
2745
|
-
|
|
3205
|
+
info(pc10.dim("Tip: press Enter to keep the default branch name shown in each prompt."));
|
|
3206
|
+
const mainBranchDefault = defaultConfig.mainBranch;
|
|
3207
|
+
const mainBranch = await inputPrompt(`Main branch name (default: ${mainBranchDefault} — press Enter to keep)`, mainBranchDefault);
|
|
2746
3208
|
let devBranch;
|
|
2747
3209
|
if (hasDevBranch(workflow)) {
|
|
2748
3210
|
const defaultDev = workflow === "git-flow" ? "develop" : "dev";
|
|
2749
|
-
devBranch = await inputPrompt(
|
|
3211
|
+
devBranch = await inputPrompt(`Dev/develop branch name (default: ${defaultDev} — press Enter to keep)`, defaultDev);
|
|
2750
3212
|
}
|
|
2751
|
-
const
|
|
3213
|
+
const originRemoteDefault = defaultConfig.origin;
|
|
3214
|
+
const originRemote = await inputPrompt(`Origin remote name (default: ${originRemoteDefault} — press Enter to keep)`, originRemoteDefault);
|
|
2752
3215
|
let upstreamRemote = defaultConfig.upstream;
|
|
2753
3216
|
if (detectedRole === "contributor") {
|
|
2754
|
-
|
|
3217
|
+
const upstreamRemoteDefault = defaultConfig.upstream;
|
|
3218
|
+
upstreamRemote = await inputPrompt(`Upstream remote name (default: ${upstreamRemoteDefault} — press Enter to keep)`, upstreamRemoteDefault);
|
|
2755
3219
|
if (!remotes.includes(upstreamRemote)) {
|
|
2756
3220
|
warn(`Remote "${upstreamRemote}" not found.`);
|
|
2757
3221
|
const originUrl = await getRemoteUrl(originRemote);
|
|
@@ -2799,9 +3263,8 @@ var setup_default = defineCommand7({
|
|
|
2799
3263
|
warn("Config was saved — verify the branch name and re-run setup if needed.");
|
|
2800
3264
|
}
|
|
2801
3265
|
}
|
|
2802
|
-
if (
|
|
2803
|
-
|
|
2804
|
-
warn(' echo ".contributerc.json" >> .gitignore');
|
|
3266
|
+
if (ensureGitignored()) {
|
|
3267
|
+
info("Added .contributerc.json to .gitignore to avoid committing personal config.");
|
|
2805
3268
|
}
|
|
2806
3269
|
console.log();
|
|
2807
3270
|
info(`Workflow: ${pc10.bold(WORKFLOW_DESCRIPTIONS[config.workflow])}`);
|
|
@@ -2815,6 +3278,17 @@ var setup_default = defineCommand7({
|
|
|
2815
3278
|
info(`Origin: ${pc10.bold(config.origin)}${config.role === "contributor" ? ` | Upstream: ${pc10.bold(config.upstream)}` : ""}`);
|
|
2816
3279
|
}
|
|
2817
3280
|
});
|
|
3281
|
+
function logConfigSummary(config) {
|
|
3282
|
+
info(`Workflow: ${pc10.bold(WORKFLOW_DESCRIPTIONS[config.workflow])}`);
|
|
3283
|
+
info(`Convention: ${pc10.bold(CONVENTION_DESCRIPTIONS[config.commitConvention])}`);
|
|
3284
|
+
info(`Role: ${pc10.bold(config.role)}`);
|
|
3285
|
+
if (config.devBranch) {
|
|
3286
|
+
info(`Main: ${pc10.bold(config.mainBranch)} | Dev: ${pc10.bold(config.devBranch)}`);
|
|
3287
|
+
} else {
|
|
3288
|
+
info(`Main: ${pc10.bold(config.mainBranch)}`);
|
|
3289
|
+
}
|
|
3290
|
+
info(`Origin: ${pc10.bold(config.origin)}${config.role === "contributor" ? ` | Upstream: ${pc10.bold(config.upstream)}` : ""}`);
|
|
3291
|
+
}
|
|
2818
3292
|
|
|
2819
3293
|
// src/commands/start.ts
|
|
2820
3294
|
import { defineCommand as defineCommand8 } from "citty";
|
|
@@ -3343,6 +3817,25 @@ var submit_default = defineCommand10({
|
|
|
3343
3817
|
return;
|
|
3344
3818
|
}
|
|
3345
3819
|
}
|
|
3820
|
+
if (ghInstalled && ghAuthed) {
|
|
3821
|
+
const existingPR = await getPRForBranch(currentBranch);
|
|
3822
|
+
if (existingPR) {
|
|
3823
|
+
info(`Pushing ${pc13.bold(currentBranch)} to ${origin}...`);
|
|
3824
|
+
const pushResult2 = await pushSetUpstream(origin, currentBranch);
|
|
3825
|
+
if (pushResult2.exitCode !== 0) {
|
|
3826
|
+
error(`Failed to push: ${pushResult2.stderr}`);
|
|
3827
|
+
if (pushResult2.stderr.includes("rejected") || pushResult2.stderr.includes("non-fast-forward")) {
|
|
3828
|
+
warn("The remote branch has diverged. Try:");
|
|
3829
|
+
info(` git pull --rebase ${origin} ${currentBranch}`);
|
|
3830
|
+
info(" Then run `contrib submit` again.");
|
|
3831
|
+
}
|
|
3832
|
+
process.exit(1);
|
|
3833
|
+
}
|
|
3834
|
+
success(`Pushed changes to existing PR #${existingPR.number}: ${pc13.bold(existingPR.title)}`);
|
|
3835
|
+
console.log(` ${pc13.cyan(existingPR.url)}`);
|
|
3836
|
+
return;
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3346
3839
|
let prTitle = null;
|
|
3347
3840
|
let prBody = null;
|
|
3348
3841
|
async function tryGenerateAI() {
|
|
@@ -3476,12 +3969,6 @@ ${pc13.dim("AI body preview:")}`);
|
|
|
3476
3969
|
}
|
|
3477
3970
|
return;
|
|
3478
3971
|
}
|
|
3479
|
-
const existingPR = await getPRForBranch(currentBranch);
|
|
3480
|
-
if (existingPR) {
|
|
3481
|
-
success(`Pushed changes to existing PR #${existingPR.number}: ${pc13.bold(existingPR.title)}`);
|
|
3482
|
-
console.log(` ${pc13.cyan(existingPR.url)}`);
|
|
3483
|
-
return;
|
|
3484
|
-
}
|
|
3485
3972
|
if (submitAction === "fill") {
|
|
3486
3973
|
const fillResult = await createPRFill(baseBranch, args.draft);
|
|
3487
3974
|
if (fillResult.exitCode !== 0) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "contribute-now",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.1-dev.6ee6f2c",
|
|
4
|
+
"description": "Developer CLI that automates git workflows — branching, syncing, committing, and PRs — with multi-workflow and commit convention support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"contrib": "dist/index.js",
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
"lint": "biome check .",
|
|
19
19
|
"lint:fix": "biome check --write .",
|
|
20
20
|
"format": "biome format --write .",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
21
|
+
"landing:install": "bun install --cwd landing",
|
|
22
|
+
"landing:dev": "bun run --cwd landing dev",
|
|
23
|
+
"landing:build": "bun run --cwd landing build",
|
|
24
|
+
"landing:preview": "bun run --cwd landing preview"
|
|
24
25
|
},
|
|
25
26
|
"engines": {
|
|
26
27
|
"node": ">=18",
|