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
11 changes: 7 additions & 4 deletions actions/setup/js/expired_entity_search_helpers.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
/// <reference types="@actions/github-script" />

const { EXPIRATION_PATTERN } = require("./ephemerals.cjs");
const { EXPIRATION_PATTERN, LEGACY_EXPIRATION_PATTERN } = require("./ephemerals.cjs");

/**
* Configuration for entity-specific GraphQL search
Expand Down Expand Up @@ -109,10 +109,11 @@ async function searchEntitiesWithExpiration(github, owner, repo, config) {
continue;
}

// Check if has expiration marker with checked checkbox
// Check if has expiration marker with checked checkbox (try both new and legacy formats)
const match = entity.body ? entity.body.match(EXPIRATION_PATTERN) : null;
const legacyMatch = !match && entity.body ? entity.body.match(LEGACY_EXPIRATION_PATTERN) : null;

if (match) {
if (match || legacyMatch) {
withExpirationCount++;

// Deduplicate if enabled (discussions may have duplicates across pages)
Expand All @@ -125,7 +126,9 @@ async function searchEntitiesWithExpiration(github, owner, repo, config) {
seenIds.add(entity.id);
}

core.info(` Found ${config.entityType.slice(0, -1)} #${entity.number} with expiration marker: "${match[1]}" - ${entity.title}`);
const expirationValue = match ? match[1] : legacyMatch ? legacyMatch[1] : "unknown";
const format = match ? "new" : "legacy";
core.info(` Found ${config.entityType.slice(0, -1)} #${entity.number} with expiration marker (${format} format): "${expirationValue}" - ${entity.title}`);
items.push(entity);
}
}
Expand Down
44 changes: 43 additions & 1 deletion actions/setup/js/expired_entity_search_helpers.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,48 @@ describe("searchEntitiesWithExpiration", () => {
expect(result.stats.totalScanned).toBe(2);
});

it("should find issues with legacy expiration format (without HTML comment)", async () => {
const legacyFormatIssue = {
id: "issue-legacy",
number: 12667,
title: "Legacy Format Issue",
url: "https://github.com/test-owner/test-repo/issues/12667",
body: "> AI generated by workflow\n\n> - [x] expires on Jan 31, 2026, 6:04 AM UTC",
createdAt: "2026-01-30T04:04:42Z",
};

const newFormatIssue = {
id: "issue-new",
number: 123,
title: "New Format Issue",
url: "https://github.com/test-owner/test-repo/issues/123",
body: "> AI generated by workflow\n\n> - [x] expires <!-- gh-aw-expires: 2026-12-31T23:59:59Z --> on Dec 31, 2026, 11:59 PM UTC",
createdAt: "2026-01-01T00:00:00Z",
};

mockGithub = {
graphql: vi.fn().mockResolvedValue({
repository: {
issues: {
pageInfo: { hasNextPage: false, endCursor: null },
nodes: [legacyFormatIssue, newFormatIssue],
},
},
}),
};

const result = await searchEntitiesWithExpiration(mockGithub, owner, repo, {
entityType: "issues",
graphqlField: "issues",
resultKey: "issues",
});

expect(result.items).toHaveLength(2);
expect(result.items).toContainEqual(legacyFormatIssue);
expect(result.items).toContainEqual(newFormatIssue);
expect(result.stats.totalScanned).toBe(2);
});

it("should handle pagination correctly", async () => {
const page1Issue = {
id: "issue-1",
Expand Down Expand Up @@ -423,7 +465,7 @@ describe("searchEntitiesWithExpiration", () => {
expect(global.core.info).toHaveBeenCalledWith("Starting GraphQL search for open issues in test-owner/test-repo");
expect(global.core.info).toHaveBeenCalledWith("Fetching page 1 of open issues (cursor: initial)");
expect(global.core.info).toHaveBeenCalledWith("Page 1: Retrieved 1 open issues (total scanned: 1)");
expect(global.core.info).toHaveBeenCalledWith(expect.stringContaining("Found issue #123 with expiration marker:"));
expect(global.core.info).toHaveBeenCalledWith(expect.stringMatching(/Found issue #123 with expiration marker \((new|legacy) format\):/));
expect(global.core.info).toHaveBeenCalledWith("Search complete: Scanned 1 issues across 1 pages, found 1 with expiration markers");
});
});
Loading