git-it-done 1.0.1 → 1.1.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/LICENSE +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -29
- package/dist/index.js.map +1 -1
- package/dist/utils/checkGitStatus.d.ts +1 -1
- package/dist/utils/checkGitStatus.js +40 -26
- package/dist/utils/checkGitStatus.js.map +1 -1
- package/dist/utils/commitMessage.d.ts +1 -1
- package/dist/utils/commitMessage.js +17 -23
- package/dist/utils/commitMessage.js.map +1 -1
- package/dist/utils/diffSignals.d.ts +22 -0
- package/dist/utils/diffSignals.js +75 -0
- package/dist/utils/diffSignals.js.map +1 -0
- package/dist/utils/displayStatus.d.ts +1 -1
- package/dist/utils/displayStatus.js +10 -16
- package/dist/utils/displayStatus.js.map +1 -1
- package/dist/utils/fileStaging.d.ts +1 -1
- package/dist/utils/fileStaging.js +84 -44
- package/dist/utils/fileStaging.js.map +1 -1
- package/dist/utils/formatFileStatus.js +14 -14
- package/dist/utils/formatFileStatus.js.map +1 -1
- package/dist/utils/generateCommitMessage.d.ts +13 -1
- package/dist/utils/generateCommitMessage.js +179 -90
- package/dist/utils/generateCommitMessage.js.map +1 -1
- package/dist/utils/getFileChanges.d.ts +15 -1
- package/dist/utils/getFileChanges.js +60 -22
- package/dist/utils/getFileChanges.js.map +1 -1
- package/dist/utils/gitCommand.d.ts +27 -1
- package/dist/utils/gitCommand.js +53 -13
- package/dist/utils/gitCommand.js.map +1 -1
- package/dist/utils/performCommit.js +39 -50
- package/dist/utils/performCommit.js.map +1 -1
- package/dist/utils/process_interruption.js +23 -17
- package/dist/utils/process_interruption.js.map +1 -1
- package/dist/utils/push_to_remote.js +56 -46
- package/dist/utils/push_to_remote.js.map +1 -1
- package/dist/utils/repoRoot.d.ts +6 -0
- package/dist/utils/repoRoot.js +10 -0
- package/dist/utils/repoRoot.js.map +1 -0
- package/dist/utils/types/types.d.ts +11 -1
- package/dist/utils/types/types.js +1 -2
- package/package.json +39 -8
- package/readme.md +298 -9
- package/dist/utils/isGitrepo.d.ts +0 -1
- package/dist/utils/isGitrepo.js +0 -9
- package/dist/utils/isGitrepo.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,25 +7,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const gitCommand_1 = require("./gitCommand");
|
|
19
|
-
const getFileChanges_1 = require("./getFileChanges");
|
|
20
|
-
const formatFileStatus_1 = require("./formatFileStatus");
|
|
21
|
-
function handleFileStaging(changes) {
|
|
10
|
+
import { select, multiselect, spinner, cancel, isCancel } from '@clack/prompts';
|
|
11
|
+
import chalk from 'chalk';
|
|
12
|
+
import { gitCommand, gitErrorText } from './gitCommand.js';
|
|
13
|
+
import { getChanges } from './getFileChanges.js';
|
|
14
|
+
import { getRepoRoot } from './repoRoot.js';
|
|
15
|
+
import { formatFileStatus } from './formatFileStatus.js';
|
|
16
|
+
export function handleFileStaging(changes) {
|
|
22
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
let
|
|
24
|
-
//
|
|
25
|
-
if (
|
|
26
|
-
|
|
18
|
+
let current = changes;
|
|
19
|
+
// Never silently adopt a pre-existing index — show it and ask.
|
|
20
|
+
if (current.staged.length > 0) {
|
|
21
|
+
const decision = yield confirmExistingIndex(current.staged);
|
|
22
|
+
if (decision === 'keep') {
|
|
23
|
+
return current.staged;
|
|
24
|
+
}
|
|
25
|
+
resetIndex();
|
|
26
|
+
current = getChanges();
|
|
27
|
+
if (current.unstaged.length === 0 && current.untracked.length === 0) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
|
-
|
|
29
|
-
const stageOption = yield (0, prompts_1.select)({
|
|
31
|
+
const stageOption = yield select({
|
|
30
32
|
message: 'No files are staged. What would you like to do?',
|
|
31
33
|
options: [
|
|
32
34
|
{ value: 'all', label: 'Stage all changes' },
|
|
@@ -34,65 +36,103 @@ function handleFileStaging(changes) {
|
|
|
34
36
|
{ value: 'cancel', label: 'Cancel' }
|
|
35
37
|
]
|
|
36
38
|
});
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
+
if (isCancel(stageOption) || stageOption === 'cancel') {
|
|
40
|
+
cancel('Operation cancelled');
|
|
39
41
|
process.exit(0);
|
|
40
42
|
}
|
|
41
43
|
if (stageOption === 'all') {
|
|
42
|
-
|
|
44
|
+
return yield stageAllFiles();
|
|
45
|
+
}
|
|
46
|
+
if (stageOption === 'select') {
|
|
47
|
+
return yield stageSelectedFiles(current);
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
return current.staged;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function confirmExistingIndex(staged) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
console.log(chalk.bold('\n📦 Already staged (from a previous session or manual `git add`):'));
|
|
55
|
+
staged.forEach(({ status, file, from }) => console.log(` ${formatFileStatus(status)} ${from ? `${from} → ${file}` : file}`));
|
|
56
|
+
const decision = yield select({
|
|
57
|
+
message: `${staged.length} file(s) are already staged. What would you like to do?`,
|
|
58
|
+
options: [
|
|
59
|
+
{ value: 'keep', label: 'Commit these staged files' },
|
|
60
|
+
{ value: 'reset', label: 'Unstage everything and choose again' },
|
|
61
|
+
{ value: 'cancel', label: 'Cancel' }
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
if (isCancel(decision) || decision === 'cancel') {
|
|
65
|
+
cancel('Operation cancelled');
|
|
66
|
+
process.exit(0);
|
|
46
67
|
}
|
|
47
|
-
return
|
|
68
|
+
return decision;
|
|
48
69
|
});
|
|
49
70
|
}
|
|
71
|
+
function resetIndex() {
|
|
72
|
+
const s = spinner();
|
|
73
|
+
s.start('Unstaging files...');
|
|
74
|
+
let result = gitCommand(['reset', '--quiet', '--', ':/']);
|
|
75
|
+
// An unborn branch has no HEAD to reset against; drop the paths from the index.
|
|
76
|
+
if (!result.ok) {
|
|
77
|
+
result = gitCommand(['rm', '--cached', '-r', '-f', '--quiet', '--', ':/']);
|
|
78
|
+
}
|
|
79
|
+
if (!result.ok) {
|
|
80
|
+
s.stop('❌ Failed to unstage files');
|
|
81
|
+
console.log(chalk.red(gitErrorText(result)));
|
|
82
|
+
cancel('Failed to unstage files');
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
s.stop('Index cleared');
|
|
86
|
+
}
|
|
50
87
|
function stageAllFiles() {
|
|
51
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const s =
|
|
89
|
+
const s = spinner();
|
|
53
90
|
s.start('Staging all files...');
|
|
54
|
-
|
|
55
|
-
|
|
91
|
+
// `:/` makes this repo-root-relative, so the staged set matches the status
|
|
92
|
+
// display even when the tool is run from a subdirectory.
|
|
93
|
+
const result = gitCommand(['add', '-A', '--', ':/']);
|
|
94
|
+
if (!result.ok) {
|
|
56
95
|
s.stop('❌ Failed to stage files');
|
|
57
|
-
(
|
|
96
|
+
console.log(chalk.red(gitErrorText(result)));
|
|
97
|
+
cancel('Failed to stage files');
|
|
58
98
|
process.exit(1);
|
|
59
99
|
}
|
|
60
100
|
s.stop('All files staged');
|
|
61
|
-
return
|
|
101
|
+
return getChanges().staged;
|
|
62
102
|
});
|
|
63
103
|
}
|
|
64
104
|
function stageSelectedFiles(changes) {
|
|
65
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
106
|
const unstaged = [...changes.unstaged, ...changes.untracked];
|
|
67
|
-
const selectedFiles = yield
|
|
107
|
+
const selectedFiles = yield multiselect({
|
|
68
108
|
message: 'Select files to stage:',
|
|
69
|
-
options: unstaged.map(({ status, file }) => ({
|
|
109
|
+
options: unstaged.map(({ status, file, from }) => ({
|
|
70
110
|
value: file,
|
|
71
|
-
label: `${
|
|
111
|
+
label: `${formatFileStatus(status)} ${from ? `${from} → ${file}` : file}`
|
|
72
112
|
})),
|
|
73
113
|
required: true
|
|
74
114
|
});
|
|
75
|
-
if (
|
|
76
|
-
|
|
115
|
+
if (isCancel(selectedFiles)) {
|
|
116
|
+
cancel('Operation cancelled');
|
|
77
117
|
process.exit(0);
|
|
78
118
|
}
|
|
79
|
-
const
|
|
119
|
+
const files = selectedFiles;
|
|
120
|
+
const s = spinner();
|
|
80
121
|
s.start('Staging selected files...');
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
122
|
+
// Paths are repo-root-relative, so run from the repo root; `--literal-pathspecs`
|
|
123
|
+
// stops names containing `*`, `[` or a leading `:` being read as pathspec magic.
|
|
124
|
+
const repoRoot = getRepoRoot();
|
|
125
|
+
const result = gitCommand(['--literal-pathspecs', 'add', '--', ...files], {
|
|
126
|
+
cwd: repoRoot !== null && repoRoot !== void 0 ? repoRoot : undefined
|
|
87
127
|
});
|
|
88
|
-
if (
|
|
128
|
+
if (!result.ok) {
|
|
89
129
|
s.stop('❌ Some files failed to stage');
|
|
90
|
-
console.log(
|
|
130
|
+
console.log(chalk.red(gitErrorText(result)));
|
|
91
131
|
}
|
|
92
132
|
else {
|
|
93
133
|
s.stop('Files staged');
|
|
94
134
|
}
|
|
95
|
-
return
|
|
135
|
+
return getChanges().staged;
|
|
96
136
|
});
|
|
97
137
|
}
|
|
98
138
|
//# sourceMappingURL=fileStaging.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileStaging.js","sourceRoot":"","sources":["../../src/utils/fileStaging.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fileStaging.js","sourceRoot":"","sources":["../../src/utils/fileStaging.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,MAAM,UAAgB,iBAAiB,CAAC,OAAmB;;QACzD,IAAI,OAAO,GAAG,OAAO,CAAC;QAEtB,+DAA+D;QAC/D,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAE5D,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;gBACxB,OAAO,OAAO,CAAC,MAAM,CAAC;YACxB,CAAC;YAED,UAAU,EAAE,CAAC;YACb,OAAO,GAAG,UAAU,EAAE,CAAC;YAEvB,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpE,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC;YAC/B,OAAO,EAAE,iDAAiD;YAC1D,OAAO,EAAE;gBACP,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE;gBAC5C,EAAE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CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAErC,iFAAiF;QACjF,iFAAiF;QACjF,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,qBAAqB,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,EAAE;YACxE,GAAG,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,SAAS;SAC3B,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YACvC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACzB,CAAC;QAED,OAAO,UAAU,EAAE,CAAC,MAAM,CAAC;IAC7B,CAAC;CAAA"}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.formatFileStatus = formatFileStatus;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
function formatFileStatus(status) {
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export function formatFileStatus(status) {
|
|
9
3
|
switch (status) {
|
|
10
4
|
case 'A':
|
|
11
|
-
return
|
|
5
|
+
return chalk.green('+ added');
|
|
12
6
|
case 'M':
|
|
13
|
-
return
|
|
7
|
+
return chalk.yellow('~ modified');
|
|
14
8
|
case 'D':
|
|
15
|
-
return
|
|
9
|
+
return chalk.red('- deleted');
|
|
16
10
|
case 'R':
|
|
17
|
-
return
|
|
11
|
+
return chalk.blue('→ renamed');
|
|
12
|
+
case 'C':
|
|
13
|
+
return chalk.blue('⧉ copied');
|
|
14
|
+
case 'T':
|
|
15
|
+
return chalk.magenta('± typechange');
|
|
16
|
+
case 'U':
|
|
17
|
+
return chalk.red('! unmerged');
|
|
18
18
|
case '??':
|
|
19
|
-
return
|
|
19
|
+
return chalk.cyan('? untracked');
|
|
20
20
|
default:
|
|
21
|
-
return
|
|
21
|
+
return chalk.gray(status);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=formatFileStatus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatFileStatus.js","sourceRoot":"","sources":["../../src/utils/formatFileStatus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatFileStatus.js","sourceRoot":"","sources":["../../src/utils/formatFileStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,GAAG;YACN,OAAO,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAChC,KAAK,GAAG;YACN,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACpC,KAAK,GAAG;YACN,OAAO,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAChC,KAAK,GAAG;YACN,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACjC,KAAK,GAAG;YACN,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAChC,KAAK,GAAG;YACN,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACvC,KAAK,GAAG;YACN,OAAO,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACjC,KAAK,IAAI;YACP,OAAO,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACnC;YACE,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC"}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DiffSignals } from './diffSignals.js';
|
|
2
|
+
import { FileChange } from './types/types.js';
|
|
3
|
+
export type FileCategory = 'deps' | 'test' | 'docs' | 'config' | 'style' | 'source';
|
|
4
|
+
export declare function categorizeFile(file: string): FileCategory;
|
|
5
|
+
/** The category the majority of the changed files belong to. */
|
|
6
|
+
export declare function dominantCategory(files: FileChange[]): FileCategory;
|
|
7
|
+
/**
|
|
8
|
+
* Most common directory across the changed files. `packages/x/...` and
|
|
9
|
+
* `apps/x/...` resolve to `x` so a monorepo commit is not scoped `packages`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function deriveScope(files: FileChange[]): string;
|
|
12
|
+
/** Pure, testable core: no git access, all inputs explicit. */
|
|
13
|
+
export declare function buildCommitMessage(files: FileChange[], signals?: DiffSignals | null): string;
|
|
2
14
|
export declare function generateCommitMessage(files: FileChange[]): string;
|
|
@@ -1,111 +1,200 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { readStagedDiffSignals } from './diffSignals.js';
|
|
4
|
+
/** Checked in this order, so the more specific category always wins a tie. */
|
|
5
|
+
const CATEGORY_ORDER = ['deps', 'test', 'docs', 'config', 'style', 'source'];
|
|
6
|
+
const DEPS_FILE = /^(package(-lock)?\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb?|requirements(-[\w.]+)?\.txt|Pipfile(\.lock)?|poetry\.lock|Gemfile(\.lock)?|go\.(mod|sum)|Cargo\.(toml|lock)|composer\.(json|lock))$/i;
|
|
7
|
+
const TEST_DIR = /(^|\/)(tests?|__tests__|__mocks__|spec|e2e|cypress)\//i;
|
|
8
|
+
const TEST_FILE = /(\.(test|spec)\.[cm]?[jt]sx?|_test\.(go|py|rb)|^test_[^/]+\.py)$/i;
|
|
9
|
+
const DOCS_DIR = /(^|\/)docs?\//i;
|
|
10
|
+
const DOCS_FILE = /(\.(md|mdx|rst|adoc)|^(readme|changelog|contributing|authors|license)(\.[a-z]+)?)$/i;
|
|
11
|
+
const STYLE_FILE = /\.(css|scss|sass|less|styl)$/i;
|
|
12
|
+
/** Real configuration files — not "anything ending in .json". */
|
|
13
|
+
const CONFIG_FILE = /^(tsconfig(\.[\w-]+)?\.json|jsconfig\.json|\.editorconfig|\.gitignore|\.gitattributes|\.npmrc|\.npmignore|\.nvmrc|\.node-version|\.eslintrc(\.[\w-]+)?|\.eslintignore|\.prettierrc(\.[\w-]+)?|\.prettierignore|\.babelrc(\.[\w-]+)?|\.dockerignore|\.env(\.[\w-]+)?|Dockerfile(\.[\w-]+)?|docker-compose(\.[\w-]+)?\.ya?ml|Makefile|renovate\.json|netlify\.toml|vercel\.json)$/i;
|
|
14
|
+
const CONFIG_SUFFIX = /\.config\.([cm]?[jt]s|json|ya?ml|toml)$/i;
|
|
15
|
+
const CONFIG_DIR = /^\.(github|circleci|vscode|husky|idea)\//i;
|
|
16
|
+
/** Monorepo container directories whose child directory is the useful scope. */
|
|
17
|
+
const CONTAINER_DIRS = new Set(['packages', 'apps', 'libs', 'services', 'crates', 'modules']);
|
|
18
|
+
export function categorizeFile(file) {
|
|
19
|
+
var _a;
|
|
20
|
+
const base = (_a = file.split('/').pop()) !== null && _a !== void 0 ? _a : file;
|
|
21
|
+
if (DEPS_FILE.test(base))
|
|
22
|
+
return 'deps';
|
|
23
|
+
if (TEST_DIR.test(file) || TEST_FILE.test(base))
|
|
24
|
+
return 'test';
|
|
25
|
+
if (DOCS_DIR.test(file) || DOCS_FILE.test(base))
|
|
26
|
+
return 'docs';
|
|
27
|
+
if (CONFIG_FILE.test(base) || CONFIG_SUFFIX.test(base) || CONFIG_DIR.test(file))
|
|
28
|
+
return 'config';
|
|
29
|
+
if (STYLE_FILE.test(base))
|
|
30
|
+
return 'style';
|
|
31
|
+
return 'source';
|
|
32
|
+
}
|
|
33
|
+
/** The category the majority of the changed files belong to. */
|
|
34
|
+
export function dominantCategory(files) {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const counts = new Map();
|
|
37
|
+
for (const { file } of files) {
|
|
38
|
+
const category = categorizeFile(file);
|
|
39
|
+
counts.set(category, ((_a = counts.get(category)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
40
|
+
}
|
|
41
|
+
let winner = 'source';
|
|
42
|
+
let best = 0;
|
|
43
|
+
for (const category of CATEGORY_ORDER) {
|
|
44
|
+
const count = (_b = counts.get(category)) !== null && _b !== void 0 ? _b : 0;
|
|
45
|
+
if (count > best) {
|
|
46
|
+
winner = category;
|
|
47
|
+
best = count;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return winner;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Most common directory across the changed files. `packages/x/...` and
|
|
54
|
+
* `apps/x/...` resolve to `x` so a monorepo commit is not scoped `packages`.
|
|
55
|
+
*/
|
|
56
|
+
export function deriveScope(files) {
|
|
57
|
+
var _a;
|
|
58
|
+
const counts = new Map();
|
|
59
|
+
for (const { file } of files) {
|
|
60
|
+
const segments = file.split('/').filter(Boolean);
|
|
61
|
+
if (segments.length < 2)
|
|
62
|
+
continue;
|
|
63
|
+
let scope = segments[0];
|
|
64
|
+
if (CONTAINER_DIRS.has(scope.toLowerCase()) && segments.length > 2) {
|
|
65
|
+
scope = segments[1];
|
|
66
|
+
}
|
|
67
|
+
scope = scope.replace(/[()\s]/g, '');
|
|
68
|
+
if (!scope)
|
|
69
|
+
continue;
|
|
70
|
+
counts.set(scope, ((_a = counts.get(scope)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
71
|
+
}
|
|
72
|
+
let winner = '';
|
|
73
|
+
let best = 0;
|
|
74
|
+
for (const [scope, count] of counts) {
|
|
75
|
+
if (count > best) {
|
|
76
|
+
winner = scope;
|
|
77
|
+
best = count;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return winner;
|
|
81
|
+
}
|
|
82
|
+
function countOperations(files) {
|
|
13
83
|
const operations = { added: 0, modified: 0, deleted: 0, renamed: 0 };
|
|
14
|
-
|
|
15
|
-
// Analyze files
|
|
16
|
-
for (const { status, file } of files) {
|
|
17
|
-
const ext = path_1.default.extname(file);
|
|
18
|
-
fileTypes.set(ext, (fileTypes.get(ext) || 0) + 1);
|
|
84
|
+
for (const { status } of files) {
|
|
19
85
|
switch (status) {
|
|
20
86
|
case 'A':
|
|
87
|
+
case '??':
|
|
21
88
|
operations.added++;
|
|
22
89
|
break;
|
|
23
90
|
case 'M':
|
|
91
|
+
case 'T':
|
|
24
92
|
operations.modified++;
|
|
25
93
|
break;
|
|
26
94
|
case 'D':
|
|
27
95
|
operations.deleted++;
|
|
28
96
|
break;
|
|
29
97
|
case 'R':
|
|
98
|
+
case 'C':
|
|
30
99
|
operations.renamed++;
|
|
31
100
|
break;
|
|
32
101
|
}
|
|
33
|
-
// Determine scope from top-level directory
|
|
34
|
-
if (!scope) {
|
|
35
|
-
const dir = file.split('/')[0];
|
|
36
|
-
if (dir && dir !== file) {
|
|
37
|
-
scope = dir;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
102
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type
|
|
69
|
-
description = 'update styles';
|
|
70
|
-
}
|
|
71
|
-
else if (operations.added > 0 && operations.modified === 0 && operations.deleted === 0) {
|
|
72
|
-
type = 'feat';
|
|
73
|
-
description = operations.added === 1
|
|
74
|
-
? `add ${path_1.default.basename(((_a = files.find(f => f.status === 'A')) === null || _a === void 0 ? void 0 : _a.file) || '')}`
|
|
75
|
-
: 'add new files';
|
|
76
|
-
}
|
|
77
|
-
else if (operations.deleted > 0 && operations.added === 0 && operations.modified === 0) {
|
|
78
|
-
type = 'remove';
|
|
79
|
-
description = operations.deleted === 1
|
|
80
|
-
? `remove ${path_1.default.basename(((_b = files.find(f => f.status === 'D')) === null || _b === void 0 ? void 0 : _b.file) || '')}`
|
|
81
|
-
: 'remove files';
|
|
82
|
-
}
|
|
83
|
-
else if (operations.modified > 0) {
|
|
84
|
-
type = 'fix';
|
|
85
|
-
description = operations.modified === 1 && operations.added === 0 && operations.deleted === 0
|
|
86
|
-
? `update ${path_1.default.basename(((_c = files.find(f => f.status === 'M')) === null || _c === void 0 ? void 0 : _c.file) || '')}`
|
|
87
|
-
: 'update and improve code';
|
|
88
|
-
}
|
|
89
|
-
// Refine with diff content
|
|
90
|
-
try {
|
|
91
|
-
const diff = (0, gitCommand_1.gitCommand)('diff --cached') || '';
|
|
92
|
-
if (/bug|fix|error|issue/i.test(diff)) {
|
|
93
|
-
type = 'fix';
|
|
94
|
-
description = 'resolve issues and bugs';
|
|
95
|
-
}
|
|
96
|
-
else if (/refactor|restructure/i.test(diff)) {
|
|
97
|
-
type = 'refactor';
|
|
98
|
-
description = 'refactor code structure';
|
|
99
|
-
}
|
|
100
|
-
else if (/function|def|class|interface/i.test(diff) && type === 'fix') {
|
|
101
|
-
type = 'feat';
|
|
102
|
-
description = 'implement new functionality';
|
|
103
|
-
}
|
|
103
|
+
return operations;
|
|
104
|
+
}
|
|
105
|
+
function firstNameWithStatus(files, statuses) {
|
|
106
|
+
const match = files.find(file => statuses.includes(file.status));
|
|
107
|
+
return match ? path.basename(match.file) : '';
|
|
108
|
+
}
|
|
109
|
+
function classifySource(files, operations) {
|
|
110
|
+
const { added, modified, deleted, renamed } = operations;
|
|
111
|
+
if (added > 0 && modified === 0 && deleted === 0 && renamed === 0) {
|
|
112
|
+
return {
|
|
113
|
+
type: 'feat',
|
|
114
|
+
description: added === 1 ? `add ${firstNameWithStatus(files, ['A', '??'])}` : `add ${added} new files`
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (deleted > 0 && added === 0 && modified === 0 && renamed === 0) {
|
|
118
|
+
return {
|
|
119
|
+
type: 'refactor',
|
|
120
|
+
description: deleted === 1 ? `remove ${firstNameWithStatus(files, ['D'])}` : `remove ${deleted} files`
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (renamed > 0 && added === 0 && modified === 0 && deleted === 0) {
|
|
124
|
+
return {
|
|
125
|
+
type: 'refactor',
|
|
126
|
+
description: renamed === 1 ? `rename ${firstNameWithStatus(files, ['R', 'C'])}` : `rename ${renamed} files`
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (added > 0 && added >= modified + deleted + renamed) {
|
|
130
|
+
return { type: 'feat', description: 'add new functionality' };
|
|
104
131
|
}
|
|
105
|
-
|
|
106
|
-
|
|
132
|
+
if (modified === 1 && added === 0 && deleted === 0 && renamed === 0) {
|
|
133
|
+
return { type: 'chore', description: `update ${firstNameWithStatus(files, ['M', 'T'])}` };
|
|
134
|
+
}
|
|
135
|
+
return { type: 'chore', description: 'update and improve code' };
|
|
136
|
+
}
|
|
137
|
+
function classifyByCategory(category, files, operations) {
|
|
138
|
+
switch (category) {
|
|
139
|
+
case 'deps':
|
|
140
|
+
// `deps` is not a Conventional Commits type; dependency bumps are `build`.
|
|
141
|
+
return { type: 'build', description: 'update dependencies' };
|
|
142
|
+
case 'test':
|
|
143
|
+
return {
|
|
144
|
+
type: 'test',
|
|
145
|
+
description: operations.modified === 0 && operations.added > 0 ? 'add tests' : 'update tests'
|
|
146
|
+
};
|
|
147
|
+
case 'docs':
|
|
148
|
+
return { type: 'docs', description: 'update documentation' };
|
|
149
|
+
case 'config':
|
|
150
|
+
// `config` is not a Conventional Commits type either.
|
|
151
|
+
return { type: 'chore', description: 'update configuration' };
|
|
152
|
+
case 'style':
|
|
153
|
+
return { type: 'style', description: 'update styles' };
|
|
154
|
+
default:
|
|
155
|
+
return classifySource(files, operations);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Diff hints only ever break a tie: they refine the vague `chore: update ...`
|
|
160
|
+
* fallback and are never allowed to override a confident classification such as
|
|
161
|
+
* "40 files were added" or "this commit only touches docs".
|
|
162
|
+
*/
|
|
163
|
+
function refine(base, signals) {
|
|
164
|
+
if (!signals || signals.oversized || base.type !== 'chore') {
|
|
165
|
+
return base;
|
|
107
166
|
}
|
|
167
|
+
if (signals.fixIntent) {
|
|
168
|
+
return { type: 'fix', description: 'correct faulty behavior' };
|
|
169
|
+
}
|
|
170
|
+
if (signals.newApi) {
|
|
171
|
+
return { type: 'feat', description: 'implement new functionality' };
|
|
172
|
+
}
|
|
173
|
+
if (signals.refactorIntent) {
|
|
174
|
+
return { type: 'refactor', description: 'restructure code' };
|
|
175
|
+
}
|
|
176
|
+
if (signals.conditionalChurn) {
|
|
177
|
+
return { type: 'fix', description: 'correct conditional handling' };
|
|
178
|
+
}
|
|
179
|
+
return base;
|
|
180
|
+
}
|
|
181
|
+
/** Pure, testable core: no git access, all inputs explicit. */
|
|
182
|
+
export function buildCommitMessage(files, signals = null) {
|
|
183
|
+
const operations = countOperations(files);
|
|
184
|
+
const category = dominantCategory(files);
|
|
185
|
+
const base = classifyByCategory(category, files, operations);
|
|
186
|
+
const { type, description } = category === 'source' ? refine(base, signals) : base;
|
|
187
|
+
// Renames-only commits used to produce an empty description ("chore(src): ").
|
|
188
|
+
const safeDescription = description.trim() || 'update files';
|
|
189
|
+
const scope = deriveScope(files);
|
|
108
190
|
const scopeStr = scope ? `(${scope})` : '';
|
|
109
|
-
return `${type}${scopeStr}: ${
|
|
191
|
+
return `${type}${scopeStr}: ${safeDescription}`;
|
|
192
|
+
}
|
|
193
|
+
export function generateCommitMessage(files) {
|
|
194
|
+
const signals = readStagedDiffSignals();
|
|
195
|
+
if (signals === null || signals === void 0 ? void 0 : signals.oversized) {
|
|
196
|
+
console.log(chalk.yellow('⚠️ Staged diff is too large to analyse — the message is based on file names only.'));
|
|
197
|
+
}
|
|
198
|
+
return buildCommitMessage(files, signals);
|
|
110
199
|
}
|
|
111
200
|
//# sourceMappingURL=generateCommitMessage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateCommitMessage.js","sourceRoot":"","sources":["../../src/utils/generateCommitMessage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateCommitMessage.js","sourceRoot":"","sources":["../../src/utils/generateCommitMessage.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAe,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAKtE,8EAA8E;AAC9E,MAAM,cAAc,GAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAE7F,MAAM,SAAS,GACb,0NAA0N,CAAC;AAE7N,MAAM,QAAQ,GAAG,wDAAwD,CAAC;AAC1E,MAAM,SAAS,GAAG,mEAAmE,CAAC;AAEtF,MAAM,QAAQ,GAAG,gBAAgB,CAAC;AAClC,MAAM,SAAS,GAAG,qFAAqF,CAAC;AAExG,MAAM,UAAU,GAAG,+BAA+B,CAAC;AAEnD,iEAAiE;AACjE,MAAM,WAAW,GACf,kXAAkX,CAAC;AACrX,MAAM,aAAa,GAAG,0CAA0C,CAAC;AACjE,MAAM,UAAU,GAAG,2CAA2C,CAAC;AAE/D,gFAAgF;AAChF,MAAM,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Q,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAE3C,OAAO,GAAG,IAAI,GAAG,QAAQ,KAAK,eAAe,EAAE,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAmB;IACvD,MAAM,OAAO,GAAG,qBAAqB,EAAE,CAAC;IAExC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,MAAM,CACV,oFAAoF,CACrF,CACF,CAAC;IACJ,CAAC;IAED,OAAO,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
import { GitChanges } from
|
|
1
|
+
import { FileChange, GitChanges } from './types/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse `git diff --name-status -z` output.
|
|
4
|
+
*
|
|
5
|
+
* With `-z` every field is its own NUL-terminated record:
|
|
6
|
+
* `M\0path\0` for ordinary changes
|
|
7
|
+
* `R100\0oldPath\0newPath\0` for renames (and `C###` for copies)
|
|
8
|
+
*
|
|
9
|
+
* The similarity score is stripped from the status and the destination path is
|
|
10
|
+
* used for renames/copies, so downstream code never sees `R100` or a bogus
|
|
11
|
+
* `old\tnew` path.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseNameStatusZ(output: string): FileChange[];
|
|
14
|
+
/** Parse a NUL-separated list of paths (e.g. `git ls-files -z`). */
|
|
15
|
+
export declare function parseNulList(output: string, status: string): FileChange[];
|
|
2
16
|
export declare function getChanges(): GitChanges;
|