From ec618e25bba5e36592ff37e7c560d738387c9112 Mon Sep 17 00:00:00 2001 From: Jonathan Bennetts Date: Sun, 20 Mar 2022 09:24:04 +0000 Subject: [PATCH] fix(GitHub Node): Fix credential tests and File > List operation (#2999) * Fixed credential test failing * Fixed File list operation not working --- packages/nodes-base/nodes/Github/Github.node.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index da2f306433..9984093688 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -1767,7 +1767,7 @@ export class Github implements INodeType { credentialTest: { async githubApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise { const credentials = credential.data; - const baseUrl = credentials!.server as string || 'https://api.github.com/user'; + const baseUrl = credentials!.server as string || 'https://api.github.com'; const options: OptionsWithUri = { method: 'GET', @@ -1775,7 +1775,7 @@ export class Github implements INodeType { 'User-Agent': 'n8n', Authorization: `token ${credentials!.accessToken}`, }, - uri: baseUrl, + uri: baseUrl.endsWith('/') ? baseUrl + 'user' : baseUrl + '/user', json: true, timeout: 5000, }; @@ -1952,7 +1952,7 @@ export class Github implements INodeType { body.sha = await getFileSha.call(this, owner, repository, filePath, body.branch as string | undefined); endpoint = `/repos/${owner}/${repository}/contents/${encodeURI(filePath)}`; - } else if (operation === 'get' || operation === 'list') { + } else if (operation === 'get') { requestMethod = 'GET'; const filePath = this.getNodeParameter('filePath', i) as string; @@ -1961,6 +1961,11 @@ export class Github implements INodeType { if (additionalParameters.reference) { qs.ref = additionalParameters.reference; } + + endpoint = `/repos/${owner}/${repository}/contents/${encodeURI(filePath)}`; + } else if (operation === 'list') { + requestMethod = 'GET'; + const filePath = this.getNodeParameter('filePath', i) as string; endpoint = `/repos/${owner}/${repository}/contents/${encodeURI(filePath)}`; } } else if (resource === 'issue') {