Skip to content
Merged
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
19 changes: 11 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62018,6 +62018,10 @@ const hasDixChanges = (diff) => {
if (!baseMatch || !prMatch) return true;
return baseMatch[1].trim() !== prMatch[1].trim();
};
const hasPackageChanges = (diff) => {
if (!diff || diff.trim() === "") return false;
return diff.split(/\r?\n/).length > 5;
};
var NIX_DIFF_ACTION_MARKER_BASE = "<!-- nix-diff-action";
var getNixDiffActionMarker = (displayName) => displayName ? `${NIX_DIFF_ACTION_MARKER_BASE}:${displayName} -->` : `${NIX_DIFF_ACTION_MARKER_BASE} -->`;
var MAX_COMMENT_LENGTH = 6e4;
Expand All @@ -62043,12 +62047,11 @@ const checkIfAnyDiffTruncated = (results) => {
return results.some((r$1) => r$1.diff.length > maxLength);
};
const formatAggregatedComment = (results, headSha, options) => {
const visibleResults = results.filter((r$1) => hasDixChanges(r$1.diff));
const maxDiffLength = calculateMaxDiffPerAttribute(visibleResults.length);
return `${visibleResults.length === 1 ? getNixDiffActionMarker(visibleResults[0].displayName) : getNixDiffActionMarker()}
const maxDiffLength = calculateMaxDiffPerAttribute(results.length);
return `${results.length === 1 ? getNixDiffActionMarker(results[0].displayName) : getNixDiffActionMarker()}
## Nix Diff

${visibleResults.map((result) => {
${results.map((result) => {
const { truncated, text } = truncateDiff(result.diff || "No differences found", maxDiffLength);
const artifactHint = truncated && options?.runId && options?.repoUrl ? `\n\n> **Note**: Diff was truncated. [View full diff in artifacts](${options.repoUrl}/actions/runs/${options.runId})` : "";
return `<details>
Expand Down Expand Up @@ -62131,10 +62134,10 @@ var GitHubService = class extends Service()("GitHubService", { succeed: {
}),
createOctokit: (token) => import_github.getOctokit(token),
postAggregatedComment: (octokit, context$2, pr, results, options, formatOptions) => gen(function* () {
const hasChanges = results.some((r$1) => hasDixChanges(r$1.diff));
const commentBody = formatAggregatedComment(results, pr.head.sha, formatOptions);
const displayName = results.length === 1 ? results[0].displayName : void 0;
if (options.skipNoChange && !hasChanges) return yield* logInfo("No differences found. Skipping comment (skip-no-change is enabled).");
const visibleResults = results.filter((r$1) => hasDixChanges(r$1.diff) && hasPackageChanges(r$1.diff));
if (options.skipNoChange && visibleResults.length === 0) return yield* logInfo("No meaningful differences found. Skipping comment (skip-no-change is enabled).");
const commentBody = formatAggregatedComment(visibleResults, pr.head.sha, formatOptions);
const displayName = visibleResults.length === 1 ? visibleResults[0].displayName : void 0;
if (options.commentStrategy === "update") return yield* match$2(yield* findExistingNixDiffComment(octokit, context$2, pr.number, displayName), {
onNone: () => gen(function* () {
yield* createComment(octokit, context$2, pr.number, commentBody);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

37 changes: 36 additions & 1 deletion src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseCommentStrategy, parseAttributes, validateDirectory } from "./prog
import { processDiffResults } from "./programs/full.js";
import { GitService, sanitizeBranchName } from "./services/git.js";
import { NixService } from "./services/nix.js";
import { hasDixChanges } from "./services/utils.js";
import { hasDixChanges, hasPackageChanges } from "./services/utils.js";
import { createArtifactName } from "./services/artifact.js";

describe("parseAttributes", () => {
Expand Down Expand Up @@ -686,3 +686,38 @@ DIFF: 0 bytes`;
expect(hasDixChanges(diff)).toBe(false);
});
});

describe("hasPackageChanges", () => {
test("returns false for undefined", () => {
expect(hasPackageChanges(undefined)).toBe(false);
});

test("returns false for empty string", () => {
expect(hasPackageChanges("")).toBe(false);
});

test("returns false for whitespace only", () => {
expect(hasPackageChanges(" \n ")).toBe(false);
});

test("returns true when package section is present", () => {
const diff = `<<< /nix/store/c7hi9s9k8p4gpa941c7z7qzh604dhgwp-nixos-system-lxc-share-lxc-proxmox-26.05.20251225.3e2499d.drv
>>> /nix/store/77k3zm8172bg5kq3chkpg4hqm9yzcm4k-nixos-system-lxc-share-lxc-proxmox-26.05.20251225.3e2499d.drv

ADDED
[A.] hello 2.12.2.drv, 2.12.2.tar.gz.drv

SIZE: 18.8 MiB -> 18.8 MiB
DIFF: 5.48 KiB`;
expect(hasPackageChanges(diff)).toBe(true);
});

test("returns false when no package section is present", () => {
const diff = `<<< /nix/store/qhhdx5khfpa07zc1lwfxcbrhn4r2g9xm-darwin-system-26.05.c2b3620.drv
>>> /nix/store/b3g2v8jf13307zkcmip1w6wdxwhhijrp-darwin-system-26.05.c2b3620.drv

SIZE: 260 MiB -> 260 MiB
DIFF: 32 bytes`;
expect(hasPackageChanges(diff)).toBe(false);
});
});
27 changes: 14 additions & 13 deletions src/services/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Effect, Option } from "effect";
import { NotPullRequestContextError, GitHubApiError } from "../errors.js";
import type { GitHubContext, Octokit, PullRequestPayload, CommentOptions } from "../types.js";
import type { DiffResult } from "../schemas.js";
import { hasDixChanges } from "./utils.js";
import { hasDixChanges, hasPackageChanges } from "./utils.js";

const NIX_DIFF_ACTION_MARKER_BASE = "<!-- nix-diff-action";

Expand Down Expand Up @@ -70,16 +70,15 @@ export const formatAggregatedComment = (
headSha: string,
options?: FormatCommentOptions,
): string => {
const visibleResults = results.filter((r) => hasDixChanges(r.diff));
const maxDiffLength = calculateMaxDiffPerAttribute(visibleResults.length);
const maxDiffLength = calculateMaxDiffPerAttribute(results.length);
// Single attribute: displayName-specific marker for matrix + update strategy
// Multiple attributes: generic marker (results order may vary in comment-only mode)
const marker =
visibleResults.length === 1
? getNixDiffActionMarker(visibleResults[0].displayName)
results.length === 1
? getNixDiffActionMarker(results[0].displayName)
: getNixDiffActionMarker();

const sections = visibleResults
const sections = results
.map((result) => {
const { truncated, text } = truncateDiff(
result.diff || "No differences found",
Expand Down Expand Up @@ -269,17 +268,19 @@ export class GitHubService extends Effect.Service<GitHubService>()("GitHubServic
formatOptions?: FormatCommentOptions,
): Effect.Effect<void, GitHubApiError> =>
Effect.gen(function* () {
const hasChanges = results.some((r) => hasDixChanges(r.diff));
const commentBody = formatAggregatedComment(results, pr.head.sha, formatOptions);
// Use displayName-specific marker for single attribute
const displayName = results.length === 1 ? results[0].displayName : undefined;

if (options.skipNoChange && !hasChanges) {
const visibleResults = results.filter(
(r) => hasDixChanges(r.diff) && hasPackageChanges(r.diff),
);
if (options.skipNoChange && visibleResults.length === 0) {
return yield* Effect.logInfo(
"No differences found. Skipping comment (skip-no-change is enabled).",
"No meaningful differences found. Skipping comment (skip-no-change is enabled).",
);
}

const commentBody = formatAggregatedComment(visibleResults, pr.head.sha, formatOptions);
// Use displayName-specific marker for single attribute
const displayName = visibleResults.length === 1 ? visibleResults[0].displayName : undefined;

if (options.commentStrategy === "update") {
const existing = yield* findExistingNixDiffComment(
octokit,
Expand Down
9 changes: 9 additions & 0 deletions src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export const hasDixChanges = (diff: string | undefined): boolean => {
return baseMatch[1].trim() !== prMatch[1].trim();
};

// Detect if dix output includes any package section content
export const hasPackageChanges = (diff: string | undefined): boolean => {
if (!diff || diff.trim() === "") return false;

const lines = diff.split(/\r?\n/);

return lines.length > 5;
};

// Git utilities
export { sanitizeBranchName } from "./git.js";

Expand Down