Skip to content

Commit a4cf3c1

Browse files
xesrevinuGit Agent
andcommitted
feat(services): add normalizePlannedGroups
- Introduced normalizePlannedGroups to compute grouped commits - Updated usage to pass stagedFiles and adjust passthrough logic - Refined hasUnscopedGroups type check for null title added a new function to normalize planned commit groups considering staged files, updated the flow to use it, and refined the unscoped group check for robustness Co-Authored-By: Git Agent <noreply@git-agent.dev>
1 parent 5c5dd84 commit a4cf3c1

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

src/services/commit-service.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,42 @@ const filterPlanFiles = (
9898
}))
9999
.filter((group) => group.files.length > 0);
100100

101-
const appendPassthroughFiles = (
101+
export const normalizePlannedGroups = (
102102
groups: Array<CommitGroup>,
103103
allowed: ReadonlySet<string>,
104+
stagedFiles: ReadonlyArray<string> = [],
104105
): Array<CommitGroup> => {
105-
if (groups.length === 0) {
106-
return groups;
107-
}
108106
const inPlan = new Set(groups.flatMap((group) => group.files));
109107
const passthrough = [...allowed].filter((file) => !inPlan.has(file)).sort();
110-
if (passthrough.length === 0) {
111-
return groups;
112-
}
113-
const [first, ...rest] = groups;
114-
if (first == null) {
115-
return groups;
108+
const staged = stagedFiles.filter((file) => allowed.has(file));
109+
const stagedSet = new Set(staged);
110+
const [first = { files: [], message: undefined }, ...rest] = groups;
111+
const firstFiles = [
112+
...staged,
113+
...first.files.filter((file) => !stagedSet.has(file)),
114+
...passthrough.filter((file) => !stagedSet.has(file)),
115+
];
116+
117+
if (firstFiles.length === 0) {
118+
return [];
116119
}
120+
117121
return [
118122
{
119123
...first,
120-
files: [...first.files, ...passthrough],
124+
files: firstFiles,
121125
},
122-
...rest,
126+
...rest
127+
.map((group) => ({
128+
...group,
129+
files: group.files.filter((file) => !stagedSet.has(file)),
130+
}))
131+
.filter((group) => group.files.length > 0),
123132
];
124133
};
125134

126135
const hasUnscopedGroups = (groups: ReadonlyArray<CommitGroup>): boolean =>
127-
groups.some((group) => (group.message?.title ?? "").includes("(") === false);
136+
groups.some((group) => group.message != null && group.message.title.includes("(") === false);
128137

129138
const commitStepLabel = (completed: number, queued: number): string => `${completed + 1}/${queued}`;
130139

@@ -226,7 +235,7 @@ const planGroups = Effect.fn(function* (
226235
});
227236
const allowed = new Set(allFiles);
228237
const filtered = filterPlanFiles(plan.groups, allowed);
229-
return appendPassthroughFiles(filtered, allowed).slice(0, maxCommitGroups);
238+
return normalizePlannedGroups(filtered, allowed, stagedFiles).slice(0, maxCommitGroups);
230239
});
231240

232241
class RetryableHookRejectionError extends Schema.TaggedErrorClass<RetryableHookRejectionError>()(

0 commit comments

Comments
 (0)