Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/server/src/pullRequest/GiteaConversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("GiteaConversation", () => {
it("addresses ordinary and inline review remarks through the same issue-comment record", () => {
expect(editableCommentId("issue:12")).toBe("12");
expect(editableCommentId("review-comment:34")).toBe("34");
expect(reactionTarget("review:56")).toBeNull();
expect(reactionTarget("review:56")).toEqual({ kind: "review", id: "56" });
});

it("distinguishes a pull request description from a comment and rejects malformed ids", () => {
Expand Down
12 changes: 8 additions & 4 deletions apps/server/src/pullRequest/GiteaConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const RawGiteaReaction = Schema.Struct({

export type GiteaConversationReactionTarget =
| { readonly kind: "pull-request" }
| { readonly kind: "comment"; readonly id: string };
| { readonly kind: "comment"; readonly id: string }
| { readonly kind: "review"; readonly id: string };

const reactionContent = new Map<string, PullRequestReactionContent>([
["+1", "thumbs-up"],
Expand All @@ -38,14 +39,17 @@ function commentId(subjectId: string): string | null {

/**
* Gitea stores inline review remarks as issue comments. Review summaries use a separate Review
* record, for which v1.27.3 intentionally exposes neither an edit nor a reaction endpoint.
* record, which the companion server extension exposes through a separate route.
*/
export function reactionTarget(
subjectId: string | undefined,
): GiteaConversationReactionTarget | null {
if (subjectId === undefined) return { kind: "pull-request" };
const id = commentId(subjectId);
return id === null ? null : { kind: "comment", id };
const [kind, reviewId] = subjectId.split(":", 2);
if (kind === "review" && reviewId && /^\d+$/.test(reviewId))
return { kind: "review", id: reviewId };
const comment = commentId(subjectId);
return comment === null ? null : { kind: "comment", id: comment };
}

/** Returns the native issue-comment ID for both ordinary and inline-review remarks. */
Expand Down
31 changes: 31 additions & 0 deletions apps/server/src/pullRequest/GiteaForkCapabilities.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, expect, it } from "@effect/vitest";
import type { PullRequestCapabilities } from "@t3tools/contracts";

import { giteaForkCapabilities } from "./GiteaForkCapabilities.ts";

const base: PullRequestCapabilities = {
diff: true,
comment: true,
actions: [],
mergeMethods: [],
search: false,
reactions: false,
reactionSubjects: {
changeRequest: true,
issueComment: true,
reviewComment: true,
review: false,
},
review: { inlineComment: true, reply: true, resolve: true, verdicts: [] },
reviewers: { request: true, listCandidates: true },
};

describe("GiteaForkCapabilities", () => {
it("enables review-summary reactions only for an advertising server", () => {
expect(giteaForkCapabilities(base, []).reactionSubjects?.review).toBe(false);
expect(giteaForkCapabilities(base, ["pull-review-reactions"]).reactionSubjects?.review).toBe(
true,
);
expect(base.reactionSubjects?.review).toBe(false);
});
});
15 changes: 15 additions & 0 deletions apps/server/src/pullRequest/GiteaForkCapabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { PullRequestCapabilities } from "@t3tools/contracts";

/** Capabilities added by the companion Gitea API extension, discovered lazily per server. */
export function giteaForkCapabilities(
base: PullRequestCapabilities,
features: ReadonlyArray<string>,
): PullRequestCapabilities {
return features.includes("pull-review-reactions")
? { ...base, reactionSubjects: { ...base.reactionSubjects!, review: true } }
: base;
}

export function giteaHasFeature(features: ReadonlyArray<string>, feature: string): boolean {
return features.includes(feature);
}
Loading