Skip to content

Commit

Permalink
trim labels to 20
Browse files Browse the repository at this point in the history
  • Loading branch information
ezhong2 committed Aug 22, 2024
1 parent ed06f0c commit b3f6847
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ modules:
function: import-projects
method: import
app:
id: ari:cloud:ecosystem::app/fe7b0913-7421-4c84-b401-041eaab2ef2e
id: ari:cloud:ecosystem::app/439a701c-b846-44dc-8f07-d956f173a405

features:
autoUserConsent: true
resources:
Expand Down
2 changes: 1 addition & 1 deletion src/client/compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const throwIfErrors = function throwIfSdkErrors(method: string, errors: SdkError

export const createComponent = async (cloudId: string, project: ImportableProject): Promise<Component | never> => {
const { name, description, typeId, labels, url, ownerId } = project;
const formattedLabels = formatLabels(labels);
const formattedLabels = formatLabels(labels).slice(0, 19);
const component = {
name,
description,
Expand Down
3 changes: 2 additions & 1 deletion src/resolvers/import-queue-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ resolver.define('import', async (req) => {
await createMRWithCompassYML(project, component.id, groupId);
}
} else if (hasComponent && !(isCompassFilePrOpened && isManaged)) {
const formattedLabels = formatLabels(labels);
const formattedLabels = formatLabels(labels).slice(0, 19);

const component = {
name,
description,
Expand Down
25 changes: 20 additions & 5 deletions src/services/sync-component-with-file/sync-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ const getFileUrl = (filePath: string, event: PushEvent, branchName: string) => {
return `${event.project.web_url}/blob/${branchName}/${filePath}`;
};

// Helper function to merge the project labels with the current labels
function mergeLabels(projectLabels: string[], currentLabels: string[], importLabel: string): string[] {
const formattedLabels = formatLabels(projectLabels);
const labels = currentLabels ? [...currentLabels, ...formattedLabels] : formattedLabels;

// Deduplicate and sort the labels for consistency
const uniqueLabels = Array.from(new Set(labels));
uniqueLabels.sort();

// If first20Labels doesn't include IMPORT_LABEL, add it to the first 20 labels
const first20Labels = uniqueLabels.slice(0, 20);
if (!first20Labels.includes(importLabel)) {
first20Labels.pop();
first20Labels.unshift(importLabel);
}

return first20Labels;
}

export const syncComponent = async (
componentSyncPayload: ComponentSyncPayload,
componentSyncDetails: ComponentSyncDetails,
Expand Down Expand Up @@ -57,11 +76,7 @@ export const syncComponent = async (
const { topics } = await getProjectById(token, event.project.id);
const projectLabels = await getProjectLabels(event.project.id, token, topics);

const formattedLabels = formatLabels(projectLabels);

const labels = currentComponent.labels
? [...currentComponent.labels, IMPORT_LABEL, ...formattedLabels]
: [IMPORT_LABEL, ...formattedLabels];
const labels = mergeLabels(projectLabels, currentComponent.labels, IMPORT_LABEL);

await updateComponent({
currentComponent,
Expand Down

0 comments on commit b3f6847

Please sign in to comment.