Skip to content

Commit

Permalink
fix(GitHub Node): Fix credential tests and File > List operation (#2999)
Browse files Browse the repository at this point in the history
* Fixed credential test failing

* Fixed File list operation not working
  • Loading branch information
Joffcom authored Mar 20, 2022
1 parent 8d04474 commit ec618e2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/nodes-base/nodes/Github/Github.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1767,15 +1767,15 @@ export class Github implements INodeType {
credentialTest: {
async githubApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<INodeCredentialTestResult> {
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',
headers: {
'User-Agent': 'n8n',
Authorization: `token ${credentials!.accessToken}`,
},
uri: baseUrl,
uri: baseUrl.endsWith('/') ? baseUrl + 'user' : baseUrl + '/user',
json: true,
timeout: 5000,
};
Expand Down Expand Up @@ -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;
Expand All @@ -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') {
Expand Down

0 comments on commit ec618e2

Please sign in to comment.