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
37 changes: 37 additions & 0 deletions src/__tests__/unit/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,43 @@ describe("getMetaData", () => {
URL: "https://github.com/upstream-owner/upstream-repo",
});
});

it("preserves existing tags that are not repository topics", async () => {
const deps = createMockDeps();
const helpers = createHelpers(deps);

const existing = {
...validCodeJSON,
tags: ["featured"],
} as any;

const result = await getMetaData(helpers, deps, existing);

expect(result.tags).toEqual(["test", "automation", "featured"]);
});

it("does not duplicate tags that already exist as repository topics", async () => {
const deps = createMockDeps();
const helpers = createHelpers(deps);

const existing = {
...validCodeJSON,
tags: ["test", "featured"],
} as any;

const result = await getMetaData(helpers, deps, existing);

expect(result.tags).toEqual(["test", "automation", "featured"]);
});

it("uses repository topics when no existing code.json is present", async () => {
const deps = createMockDeps();
const helpers = createHelpers(deps);

const result = await getMetaData(helpers, deps, null);

expect(result.tags).toEqual(["test", "automation"]);
});
});

describe("runWithDeps", () => {
Expand Down
9 changes: 9 additions & 0 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export function createHelpers(deps: Dependencies) {
readJSON,
sendPR,
pushDirectlyWithFallback,
mergeTags,
};
}

Expand Down Expand Up @@ -390,6 +391,14 @@ export function mergeReusedCode(
return merged;
}

// combines repository topics with existing manually added tags, de-duped
export function mergeTags(
repositoryTopics: string[] = [],
existingTags: string[] = [],
): string[] {
return Array.from(new Set([...repositoryTopics, ...existingTags]));
Comment thread
sachin-panayil marked this conversation as resolved.
}

function bodyOfPR(): string {
return `
## Welcome to the Federal Open Source Community!
Expand Down
13 changes: 6 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ async function getMetaData(
? partialCodeJSON.description
: existingCodeJSON?.description || "";

// only update tags if we have new ones from GitHub Topics, otherwise keep existing
const shouldUpdateTags =
partialCodeJSON.tags && partialCodeJSON.tags.length > 0;
const tags = shouldUpdateTags
? partialCodeJSON.tags
: existingCodeJSON?.tags || [];
// preserve existing tags and append repository topics, de-duped
const tags = helpers.mergeTags(
partialCodeJSON.tags ?? [],
existingCodeJSON?.tags ?? [],
);

// handling legacy contractNumber that turned from string to array which caused validation errors
let contractNumber: string[] = [];
Expand All @@ -135,7 +134,7 @@ async function getMetaData(

if (deps.isArchived) {
status = "Archival";
tags?.push("archived");
tags.push("archived");
}

// detect the fork upstream and government-made dependencies, then merge with any existing reusedCode
Expand Down
Loading