Skip to content

Commit 73362b6

Browse files
committed
skip diffs with no package changes
1 parent a29c8c0 commit 73362b6

5 files changed

Lines changed: 71 additions & 23 deletions

File tree

dist/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62018,6 +62018,10 @@ const hasDixChanges = (diff) => {
6201862018
if (!baseMatch || !prMatch) return true;
6201962019
return baseMatch[1].trim() !== prMatch[1].trim();
6202062020
};
62021+
const hasPackageChanges = (diff) => {
62022+
if (!diff || diff.trim() === "") return false;
62023+
return diff.split(/\r?\n/).length > 5;
62024+
};
6202162025
var NIX_DIFF_ACTION_MARKER_BASE = "<!-- nix-diff-action";
6202262026
var getNixDiffActionMarker = (displayName) => displayName ? `${NIX_DIFF_ACTION_MARKER_BASE}:${displayName} -->` : `${NIX_DIFF_ACTION_MARKER_BASE} -->`;
6202362027
var MAX_COMMENT_LENGTH = 6e4;
@@ -62043,12 +62047,11 @@ const checkIfAnyDiffTruncated = (results) => {
6204362047
return results.some((r$1) => r$1.diff.length > maxLength);
6204462048
};
6204562049
const formatAggregatedComment = (results, headSha, options) => {
62046-
const visibleResults = results.filter((r$1) => hasDixChanges(r$1.diff));
62047-
const maxDiffLength = calculateMaxDiffPerAttribute(visibleResults.length);
62048-
return `${visibleResults.length === 1 ? getNixDiffActionMarker(visibleResults[0].displayName) : getNixDiffActionMarker()}
62050+
const maxDiffLength = calculateMaxDiffPerAttribute(results.length);
62051+
return `${results.length === 1 ? getNixDiffActionMarker(results[0].displayName) : getNixDiffActionMarker()}
6204962052
## Nix Diff
6205062053

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

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { parseCommentStrategy, parseAttributes, validateDirectory } from "./prog
55
import { processDiffResults } from "./programs/full.js";
66
import { GitService, sanitizeBranchName } from "./services/git.js";
77
import { NixService } from "./services/nix.js";
8-
import { hasDixChanges } from "./services/utils.js";
8+
import { hasDixChanges, hasPackageChanges } from "./services/utils.js";
99
import { createArtifactName } from "./services/artifact.js";
1010

1111
describe("parseAttributes", () => {
@@ -686,3 +686,38 @@ DIFF: 0 bytes`;
686686
expect(hasDixChanges(diff)).toBe(false);
687687
});
688688
});
689+
690+
describe("hasPackageChanges", () => {
691+
test("returns false for undefined", () => {
692+
expect(hasPackageChanges(undefined)).toBe(false);
693+
});
694+
695+
test("returns false for empty string", () => {
696+
expect(hasPackageChanges("")).toBe(false);
697+
});
698+
699+
test("returns false for whitespace only", () => {
700+
expect(hasPackageChanges(" \n ")).toBe(false);
701+
});
702+
703+
test("returns true when package section is present", () => {
704+
const diff = `<<< /nix/store/c7hi9s9k8p4gpa941c7z7qzh604dhgwp-nixos-system-lxc-share-lxc-proxmox-26.05.20251225.3e2499d.drv
705+
>>> /nix/store/77k3zm8172bg5kq3chkpg4hqm9yzcm4k-nixos-system-lxc-share-lxc-proxmox-26.05.20251225.3e2499d.drv
706+
707+
ADDED
708+
[A.] hello 2.12.2.drv, 2.12.2.tar.gz.drv
709+
710+
SIZE: 18.8 MiB -> 18.8 MiB
711+
DIFF: 5.48 KiB`;
712+
expect(hasPackageChanges(diff)).toBe(true);
713+
});
714+
715+
test("returns false when no package section is present", () => {
716+
const diff = `<<< /nix/store/qhhdx5khfpa07zc1lwfxcbrhn4r2g9xm-darwin-system-26.05.c2b3620.drv
717+
>>> /nix/store/b3g2v8jf13307zkcmip1w6wdxwhhijrp-darwin-system-26.05.c2b3620.drv
718+
719+
SIZE: 260 MiB -> 260 MiB
720+
DIFF: 32 bytes`;
721+
expect(hasPackageChanges(diff)).toBe(false);
722+
});
723+
});

src/services/github.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Effect, Option } from "effect";
33
import { NotPullRequestContextError, GitHubApiError } from "../errors.js";
44
import type { GitHubContext, Octokit, PullRequestPayload, CommentOptions } from "../types.js";
55
import type { DiffResult } from "../schemas.js";
6-
import { hasDixChanges } from "./utils.js";
6+
import { hasDixChanges, hasPackageChanges } from "./utils.js";
77

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

@@ -70,16 +70,15 @@ export const formatAggregatedComment = (
7070
headSha: string,
7171
options?: FormatCommentOptions,
7272
): string => {
73-
const visibleResults = results.filter((r) => hasDixChanges(r.diff));
74-
const maxDiffLength = calculateMaxDiffPerAttribute(visibleResults.length);
73+
const maxDiffLength = calculateMaxDiffPerAttribute(results.length);
7574
// Single attribute: displayName-specific marker for matrix + update strategy
7675
// Multiple attributes: generic marker (results order may vary in comment-only mode)
7776
const marker =
78-
visibleResults.length === 1
79-
? getNixDiffActionMarker(visibleResults[0].displayName)
77+
results.length === 1
78+
? getNixDiffActionMarker(results[0].displayName)
8079
: getNixDiffActionMarker();
8180

82-
const sections = visibleResults
81+
const sections = results
8382
.map((result) => {
8483
const { truncated, text } = truncateDiff(
8584
result.diff || "No differences found",
@@ -269,17 +268,19 @@ export class GitHubService extends Effect.Service<GitHubService>()("GitHubServic
269268
formatOptions?: FormatCommentOptions,
270269
): Effect.Effect<void, GitHubApiError> =>
271270
Effect.gen(function* () {
272-
const hasChanges = results.some((r) => hasDixChanges(r.diff));
273-
const commentBody = formatAggregatedComment(results, pr.head.sha, formatOptions);
274-
// Use displayName-specific marker for single attribute
275-
const displayName = results.length === 1 ? results[0].displayName : undefined;
276-
277-
if (options.skipNoChange && !hasChanges) {
271+
const visibleResults = results.filter(
272+
(r) => hasDixChanges(r.diff) && hasPackageChanges(r.diff),
273+
);
274+
if (options.skipNoChange && visibleResults.length === 0) {
278275
return yield* Effect.logInfo(
279-
"No differences found. Skipping comment (skip-no-change is enabled).",
276+
"No meaningful differences found. Skipping comment (skip-no-change is enabled).",
280277
);
281278
}
282279

280+
const commentBody = formatAggregatedComment(visibleResults, pr.head.sha, formatOptions);
281+
// Use displayName-specific marker for single attribute
282+
const displayName = visibleResults.length === 1 ? visibleResults[0].displayName : undefined;
283+
283284
if (options.commentStrategy === "update") {
284285
const existing = yield* findExistingNixDiffComment(
285286
octokit,

src/services/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ export const hasDixChanges = (diff: string | undefined): boolean => {
2323
return baseMatch[1].trim() !== prMatch[1].trim();
2424
};
2525

26+
// Detect if dix output includes any package section content
27+
export const hasPackageChanges = (diff: string | undefined): boolean => {
28+
if (!diff || diff.trim() === "") return false;
29+
30+
const lines = diff.split(/\r?\n/);
31+
32+
return lines.length > 5;
33+
};
34+
2635
// Git utilities
2736
export { sanitizeBranchName } from "./git.js";
2837

0 commit comments

Comments
 (0)