diff --git a/.changeset/purple-rocks-explode.md b/.changeset/purple-rocks-explode.md new file mode 100644 index 0000000000..86f575e317 --- /dev/null +++ b/.changeset/purple-rocks-explode.md @@ -0,0 +1,5 @@ +--- +'@backstage/integration': patch +--- + +Fixed bug for comparing Organization name in `GithubCredentialsProvider` 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..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 === owner, + inst => inst.account?.login?.toLowerCase() === owner.toLowerCase(), ); if (installation) { return {