From 3c50ff56203171ff9e4af622f3f1b56aac66236d Mon Sep 17 00:00:00 2001 From: Aurelio Saraiva Date: Mon, 2 Aug 2021 10:51:46 -0300 Subject: [PATCH 1/2] fixed bug on when compared in organzation name on github Signed-off-by: Aurelio Saraiva --- .changeset/purple-rocks-explode.md | 5 +++ .../github/GithubCredentialsProvider.test.ts | 31 +++++++++++++++++++ .../src/github/GithubCredentialsProvider.ts | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .changeset/purple-rocks-explode.md diff --git a/.changeset/purple-rocks-explode.md b/.changeset/purple-rocks-explode.md new file mode 100644 index 0000000000..4969a42a6b --- /dev/null +++ b/.changeset/purple-rocks-explode.md @@ -0,0 +1,5 @@ +--- +'@backstage/integration': patch +--- + +Fixed bug on when compared in organzation name on github diff --git a/packages/integration/src/github/GithubCredentialsProvider.test.ts b/packages/integration/src/github/GithubCredentialsProvider.test.ts index 85df1bb4e1..47678ddb89 100644 --- a/packages/integration/src/github/GithubCredentialsProvider.test.ts +++ b/packages/integration/src/github/GithubCredentialsProvider.test.ts @@ -254,4 +254,35 @@ describe('GithubCredentialsProvider tests', () => { }), ).resolves.toEqual({ headers: undefined, token: undefined, type: 'token' }); }); + + it('should to create a token for the organization ignoring case sensitive', async () => { + octokit.apps.listInstallations.mockResolvedValue({ + headers: { + etag: '123', + }, + data: [ + { + id: 1, + repository_selection: 'all', + account: { + login: 'BACKSTAGE', + }, + }, + ], + } as RestEndpointMethodTypes['apps']['listInstallations']['response']); + + octokit.apps.createInstallationAccessToken.mockResolvedValueOnce({ + data: { + expires_at: DateTime.local().plus({ hour: 1 }).toString(), + token: 'secret_token', + }, + } as RestEndpointMethodTypes['apps']['createInstallationAccessToken']['response']); + + const { token, headers } = await github.getCredentials({ + url: 'https://github.com/backstage', + }); + + expect(headers).toEqual({ Authorization: 'Bearer secret_token' }); + expect(token).toEqual('secret_token'); + }); }); diff --git a/packages/integration/src/github/GithubCredentialsProvider.ts b/packages/integration/src/github/GithubCredentialsProvider.ts index 899b233195..36cb0ef14d 100644 --- a/packages/integration/src/github/GithubCredentialsProvider.ts +++ b/packages/integration/src/github/GithubCredentialsProvider.ts @@ -129,7 +129,7 @@ class GithubAppManager { private async getInstallationData(owner: string): Promise { const allInstallations = await this.getInstallations(); const installation = allInstallations.find( - inst => inst.account?.login === owner, + inst => inst.account?.login.toLowerCase() === owner.toLowerCase(), ); if (installation) { return { From c0984b1402ddb4bbe386e8b819336f1cbf6bdab9 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 2 Aug 2021 18:03:41 +0200 Subject: [PATCH 2/2] chore: fixing up the typescript issue and fix up changeset description Signed-off-by: blam --- .changeset/purple-rocks-explode.md | 2 +- packages/integration/src/github/GithubCredentialsProvider.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/purple-rocks-explode.md b/.changeset/purple-rocks-explode.md index 4969a42a6b..86f575e317 100644 --- a/.changeset/purple-rocks-explode.md +++ b/.changeset/purple-rocks-explode.md @@ -2,4 +2,4 @@ '@backstage/integration': patch --- -Fixed bug on when compared in organzation name on github +Fixed bug for comparing Organization name in `GithubCredentialsProvider` diff --git a/packages/integration/src/github/GithubCredentialsProvider.ts b/packages/integration/src/github/GithubCredentialsProvider.ts index 36cb0ef14d..ba30900358 100644 --- a/packages/integration/src/github/GithubCredentialsProvider.ts +++ b/packages/integration/src/github/GithubCredentialsProvider.ts @@ -129,7 +129,7 @@ class GithubAppManager { private async getInstallationData(owner: string): Promise { const allInstallations = await this.getInstallations(); const installation = allInstallations.find( - inst => inst.account?.login.toLowerCase() === owner.toLowerCase(), + inst => inst.account?.login?.toLowerCase() === owner.toLowerCase(), ); if (installation) { return {