Skip to content

Commit

Permalink
Merge pull request #70 from PagerDuty/next
Browse files Browse the repository at this point in the history
release: 0.7.2
  • Loading branch information
t1agob authored Jul 5, 2024
2 parents 0ab7bb3 + 714f4fe commit 57e0eac
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
58 changes: 57 additions & 1 deletion src/service/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,62 @@ describe('createRouter', () => {
expect(result).toEqual(expectedReferenceDictionary);
});

it("ignores invalid integration keys when building entity mapping reference", async () => {
mocked(fetch).mockReturnValue(mockedResponse(200, {"services": []}));

const mockEntitiesResponse = {
"items":
[
{
"metadata":
{
"namespace": "default",
"annotations":
{
"pagerduty.com/integration-key": "PAGERDUTY-INTEGRATION-KEY-1",
},
"name": "ENTITY1",
"uid": "00000000-0000-4000-0000-000000000001",
},
"apiVersion": "backstage.io/v1alpha1",
"kind": "Component",
"spec":
{
"type": "website",
"lifecycle": "experimental",
"owner": "OWNER1",
"system": "SYSTEM1",
},
"relations":
[
{
"type": "ownedBy",
"targetRef": "group:default/OWNER1",
"target":
{ "kind": "group", "namespace": "default", "name": "OWNER1" },
},
{
"type": "partOf",
"targetRef": "system:default/SYSTEM1",
"target":
{
"kind": "system",
"namespace": "default",
"name": "SYSTEM1",
},
},
],
},
],
};

const expectedReferenceDictionary: Record<string, { ref: string, name: string }> = {};

const result = await createComponentEntitiesReferenceDict(mockEntitiesResponse);

expect(result).toEqual(expectedReferenceDictionary);
});

it("builds entity mapping response for with InSync status when ONLY config mapping exists", async () => {
const mockEntityMappings: RawDbEntityResultRow[] = [];

Expand Down Expand Up @@ -1883,4 +1939,4 @@ describe('createRouter', () => {
});
});
});
});
});
7 changes: 4 additions & 3 deletions src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export async function createComponentEntitiesReferenceDict({ items: componentEnt
};
}
else if (integrationKey !== undefined && integrationKey !== "") {
// get service id from integration key
const service : PagerDutyService = await getServiceByIntegrationKey(integrationKey);
// get service id from integration key, we ignore errors here since we're focused
// only on building a mapping between valid service IDs and the corresponding Backstage entity
const service = await getServiceByIntegrationKey(integrationKey).catch(() => undefined);

if (service !== undefined) {
componentEntitiesDict[service.id] = {
Expand Down Expand Up @@ -535,4 +536,4 @@ export async function createRouter(

// Return the router
return router;
}
}

0 comments on commit 57e0eac

Please sign in to comment.