Skip to content

Commit 9347349

Browse files
refactor(gitlab): compute ranged comment line codes in one traced step
AI-assisted; verified with the tests and tools listed above.
1 parent a3bb405 commit 9347349

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -730,14 +730,14 @@ function gitLabLineRangeEnd(
730730
};
731731
}
732732

733-
const gitLabFileHash = Effect.fnUntraced(function* (path: string) {
734-
const digest = yield* Digest.Digest;
735-
return yield* digest.digestHex(Digest.sha1, new TextEncoder().encode(path));
736-
}, Effect.provide(Digest.layerWebCrypto));
737-
738-
function gitLabLineRange(fileHash: string, patch: string, comment: PullRequestReviewCommentDraft) {
733+
const gitLabLineRange = Effect.fn("GitLabPullRequestCli.lineRange")(function* (
734+
patch: string,
735+
comment: PullRequestReviewCommentDraft,
736+
) {
739737
const start = comment.startPosition;
740738
if (start === undefined) return {};
739+
const digest = yield* Digest.Digest;
740+
const fileHash = yield* digest.digestHex(Digest.sha1, new TextEncoder().encode(comment.path));
741741
const header = gitLabDiffHeader(comment.oldPath ?? comment.path, comment.path);
742742
const first = gitLabLineRangeEnd(fileHash, start, gitLabLineCounters(patch, header, start));
743743
const last = gitLabLineRangeEnd(
@@ -746,7 +746,7 @@ function gitLabLineRange(fileHash: string, patch: string, comment: PullRequestRe
746746
gitLabLineCounters(patch, header, comment.position),
747747
);
748748
return first.line_code === last.line_code ? {} : { line_range: { start: first, end: last } };
749-
}
749+
}, Effect.provide(Digest.layerWebCrypto));
750750

751751
function stateParam(state: PullRequestListState): string {
752752
return state === "open" ? "opened" : state;
@@ -2697,11 +2697,8 @@ export const make = Effect.gen(function* () {
26972697
yield* Effect.forEach(
26982698
input.comments,
26992699
(comment) =>
2700-
(comment.startPosition === undefined
2701-
? Effect.succeed("")
2702-
: gitLabFileHash(comment.path)
2703-
).pipe(
2704-
Effect.flatMap((fileHash) =>
2700+
gitLabLineRange(patch, comment).pipe(
2701+
Effect.flatMap((lineRange) =>
27052702
api({
27062703
cwd: input.cwd,
27072704
host: input.host,
@@ -2720,7 +2717,7 @@ export const make = Effect.gen(function* () {
27202717
old_path: comment.oldPath ?? comment.path,
27212718
new_path: comment.path,
27222719
...gitLabReviewPositionLines(comment.position),
2723-
...gitLabLineRange(fileHash, patch, comment),
2720+
...lineRange,
27242721
},
27252722
}),
27262723
}),

0 commit comments

Comments
 (0)