diff --git a/packages/nodes-base/credentials/GithubApi.credentials.ts b/packages/nodes-base/credentials/GithubApi.credentials.ts index 83c5c5f9d41ad..e54c02dd3735f 100644 --- a/packages/nodes-base/credentials/GithubApi.credentials.ts +++ b/packages/nodes-base/credentials/GithubApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateHeaderAuth, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -28,4 +30,18 @@ export class GithubApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateHeaderAuth = { + type: 'headerAuth', + properties: { + name: 'Authorization', + value: '=token {{$credentials?.accessToken}}', + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials?.server}}', + url: '/user', + method: 'GET', + }, + }; } diff --git a/packages/nodes-base/nodes/Github/GenericFunctions.ts b/packages/nodes-base/nodes/Github/GenericFunctions.ts index 12e97da9c7260..3a9c534bd7076 100644 --- a/packages/nodes-base/nodes/Github/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Github/GenericFunctions.ts @@ -37,23 +37,23 @@ export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions, try { const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken') as string; + let credentialType = ''; if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('githubApi'); + credentialType = 'githubApi'; const baseUrl = credentials!.server || 'https://api.github.com'; options.uri = `${baseUrl}${endpoint}`; - - options.headers!.Authorization = `token ${credentials.accessToken}`; - return await this.helpers.request(options); } else { const credentials = await this.getCredentials('githubOAuth2Api'); + credentialType = 'githubOAuth2Api'; const baseUrl = credentials.server || 'https://api.github.com'; options.uri = `${baseUrl}${endpoint}`; - //@ts-ignore - return await this.helpers.requestOAuth2.call(this, 'githubOAuth2Api', options); } + + return await this.helpers.requestWithAuthentication.call(this, credentialType, options); } catch (error) { throw new NodeApiError(this.getNode(), error); } diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 5a5352612e69a..c2332cfade37d 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -1,14 +1,9 @@ -import { OptionsWithUri } from 'request'; - import { IExecuteFunctions, } from 'n8n-core'; import { - ICredentialsDecrypted, - ICredentialTestFunctions, IDataObject, - INodeCredentialTestResult, INodeExecutionData, INodeType, INodeTypeDescription, @@ -43,12 +38,9 @@ export class Github implements INodeType { { name: 'githubApi', required: true, - testedBy: 'githubApiTest', displayOptions: { show: { - authentication: [ - 'accessToken', - ], + authentication: ['accessToken'], }, }, }, @@ -57,9 +49,7 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - authentication: [ - 'oAuth2', - ], + authentication: ['oAuth2'], }, }, }, @@ -111,12 +101,14 @@ export class Github implements INodeType { name: 'User', value: 'user', }, + { + name: 'Organization', + value: 'organization', + }, ], default: 'issue', }, - - // ---------------------------------- // operations // ---------------------------------- @@ -127,9 +119,27 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'issue', - ], + resource: ['organization'], + }, + }, + options: [ + { + name: 'Get Repositories', + value: 'getRepositories', + description: 'Returns all repositories of an organization', + }, + ], + default: 'getRepositories', + }, + + { + displayName: 'Operation', + name: 'operation', + type: 'options', + noDataExpression: true, + displayOptions: { + show: { + resource: ['issue'], }, }, options: [ @@ -169,9 +179,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'file', - ], + resource: ['file'], }, }, options: [ @@ -211,9 +219,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'repository', - ], + resource: ['repository'], }, }, options: [ @@ -235,7 +241,8 @@ export class Github implements INodeType { { name: 'Get Profile', value: 'getProfile', - description: 'Get the community profile of a repository with metrics, health score, description, license, etc', + description: + 'Get the community profile of a repository with metrics, health score, description, license, etc', }, { name: 'List Popular Paths', @@ -258,9 +265,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'user', - ], + resource: ['user'], }, }, options: [ @@ -285,9 +290,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'release', - ], + resource: ['release'], }, }, options: [ @@ -327,9 +330,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'review', - ], + resource: ['review'], }, }, options: [ @@ -368,9 +369,7 @@ export class Github implements INodeType { required: true, displayOptions: { hide: { - operation: [ - 'invite', - ], + operation: ['invite'], }, }, placeholder: 'n8n-io', @@ -384,20 +383,14 @@ export class Github implements INodeType { required: true, displayOptions: { hide: { - resource: [ - 'user', - ], - operation: [ - 'getRepositories', - ], + resource: ['user', 'organization'], + operation: ['getRepositories'], }, }, placeholder: 'n8n', description: 'The name of the repository', }, - - // ---------------------------------- // file // ---------------------------------- @@ -413,14 +406,10 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - resource: [ - 'file', - ], + resource: ['file'], }, hide: { - operation: [ - 'list', - ], + operation: ['list'], }, }, placeholder: 'docs/README.md', @@ -437,12 +426,8 @@ export class Github implements INodeType { default: '', displayOptions: { show: { - resource: [ - 'file', - ], - operation: [ - 'list', - ], + resource: ['file'], + operation: ['list'], }, }, placeholder: 'docs/', @@ -460,13 +445,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'create', - 'edit', - ], - resource: [ - 'file', - ], + operation: ['create', 'edit'], + resource: ['file'], }, }, description: 'If the data to upload should be taken from binary field', @@ -479,18 +459,10 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - binaryData: [ - false, - ], - operation: [ - 'create', - 'edit', - ], - resource: [ - 'file', - ], + binaryData: [false], + operation: ['create', 'edit'], + resource: ['file'], }, - }, placeholder: '', description: 'The text content of the file', @@ -503,18 +475,10 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - binaryData: [ - true, - ], - operation: [ - 'create', - 'edit', - ], - resource: [ - 'file', - ], + binaryData: [true], + operation: ['create', 'edit'], + resource: ['file'], }, - }, placeholder: '', description: 'Name of the binary property which contains the data for the file', @@ -527,14 +491,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'create', - 'delete', - 'edit', - ], - resource: [ - 'file', - ], + operation: ['create', 'delete', 'edit'], + resource: ['file'], }, }, }, @@ -547,14 +505,8 @@ export class Github implements INodeType { default: {}, displayOptions: { show: { - operation: [ - 'create', - 'delete', - 'edit', - ], - resource: [ - 'file', - ], + operation: ['create', 'delete', 'edit'], + resource: ['file'], }, }, options: [ @@ -587,7 +539,8 @@ export class Github implements INodeType { name: 'branch', type: 'string', default: '', - description: 'The branch to commit to. If not set the repository’s default branch (usually master) is used.', + description: + 'The branch to commit to. If not set the repository’s default branch (usually master) is used.', }, ], }, @@ -624,15 +577,12 @@ export class Github implements INodeType { default: true, displayOptions: { show: { - operation: [ - 'get', - ], - resource: [ - 'file', - ], + operation: ['get'], + resource: ['file'], }, }, - description: 'If set it will set the data of the file as binary property instead of returning the raw API response', + description: + 'If set it will set the data of the file as binary property instead of returning the raw API response', }, { displayName: 'Binary Property', @@ -642,20 +592,14 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - asBinaryProperty: [ - true, - ], - operation: [ - 'get', - ], - resource: [ - 'file', - ], + asBinaryProperty: [true], + operation: ['get'], + resource: ['file'], }, - }, placeholder: '', - description: 'Name of the binary property in which to save the binary data of the received file', + description: + 'Name of the binary property in which to save the binary data of the received file', }, { @@ -667,12 +611,8 @@ export class Github implements INodeType { default: {}, displayOptions: { show: { - operation: [ - 'get', - ], - resource: [ - 'file', - ], + operation: ['get'], + resource: ['file'], }, }, options: [ @@ -682,7 +622,8 @@ export class Github implements INodeType { type: 'string', default: '', placeholder: 'master', - description: 'The name of the commit/branch/tag. Default: the repository’s default branch (usually master).', + description: + 'The name of the commit/branch/tag. Default: the repository’s default branch (usually master).', }, ], }, @@ -702,12 +643,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'issue', - ], + operation: ['create'], + resource: ['issue'], }, }, description: 'The title of the issue', @@ -722,12 +659,8 @@ export class Github implements INodeType { default: '', displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'issue', - ], + operation: ['create'], + resource: ['issue'], }, }, description: 'The body of the issue', @@ -742,15 +675,11 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'issue', - ], + operation: ['create'], + resource: ['issue'], }, }, - default: { 'label': '' }, + default: { label: '' }, options: [ { displayName: 'Label', @@ -771,15 +700,11 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'issue', - ], + operation: ['create'], + resource: ['issue'], }, }, - default: { 'assignee': '' }, + default: { assignee: '' }, options: [ { displayName: 'Assignee', @@ -802,12 +727,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'createComment', - ], - resource: [ - 'issue', - ], + operation: ['createComment'], + resource: ['issue'], }, }, description: 'The number of the issue on which to create the comment on', @@ -821,12 +742,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'createComment', - ], - resource: [ - 'issue', - ], + operation: ['createComment'], + resource: ['issue'], }, }, default: '', @@ -844,12 +761,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'edit', - ], - resource: [ - 'issue', - ], + operation: ['edit'], + resource: ['issue'], }, }, description: 'The number of the issue edit', @@ -863,12 +776,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'edit', - ], - resource: [ - 'issue', - ], + operation: ['edit'], + resource: ['issue'], }, }, default: {}, @@ -917,7 +826,7 @@ export class Github implements INodeType { multipleValues: true, multipleValueButtonText: 'Add Label', }, - default: { 'label': '' }, + default: { label: '' }, options: [ { displayName: 'Label', @@ -936,7 +845,7 @@ export class Github implements INodeType { multipleValues: true, multipleValueButtonText: 'Add Assignee', }, - default: { 'assignee': '' }, + default: { assignee: '' }, options: [ { displayName: 'Assignees', @@ -961,12 +870,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'get', - ], - resource: [ - 'issue', - ], + operation: ['get'], + resource: ['issue'], }, }, description: 'The number of the issue get data of', @@ -983,12 +888,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'lock', - ], - resource: [ - 'issue', - ], + operation: ['lock'], + resource: ['issue'], }, }, description: 'The number of the issue to lock', @@ -999,12 +900,8 @@ export class Github implements INodeType { type: 'options', displayOptions: { show: { - operation: [ - 'lock', - ], - resource: [ - 'issue', - ], + operation: ['lock'], + resource: ['issue'], }, }, options: [ @@ -1033,8 +930,6 @@ export class Github implements INodeType { description: 'The reason to lock the issue', }, - - // ---------------------------------- // release // ---------------------------------- @@ -1050,12 +945,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'release', - ], + operation: ['create'], + resource: ['release'], }, }, description: 'The tag of the release', @@ -1069,12 +960,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'release', - ], + operation: ['create'], + resource: ['release'], }, }, default: {}, @@ -1101,21 +988,24 @@ export class Github implements INodeType { name: 'draft', type: 'boolean', default: false, - description: 'Set "true" to create a draft (unpublished) release, "false" to create a published one', + description: + 'Set "true" to create a draft (unpublished) release, "false" to create a published one', }, { displayName: 'Prerelease', name: 'prerelease', type: 'boolean', default: false, - description: 'If set to "true" it will point out that the release is non-production ready', + description: + 'If set to "true" it will point out that the release is non-production ready', }, { displayName: 'Target Commitish', name: 'target_commitish', type: 'string', default: '', - description: 'Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository\'s default branch(usually master).', + description: + 'Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository\'s default branch(usually master).', }, ], }, @@ -1131,14 +1021,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - resource: [ - 'release', - ], - operation: [ - 'get', - 'delete', - 'update', - ], + resource: ['release'], + operation: ['get', 'delete', 'update'], }, }, }, @@ -1155,12 +1039,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'update', - ], - resource: [ - 'release', - ], + operation: ['update'], + resource: ['release'], }, }, default: {}, @@ -1180,7 +1060,8 @@ export class Github implements INodeType { name: 'draft', type: 'boolean', default: false, - description: 'Set "true" to create a draft (unpublished) release, "false" to create a published one', + description: + 'Set "true" to create a draft (unpublished) release, "false" to create a published one', }, { displayName: 'Name', @@ -1194,7 +1075,8 @@ export class Github implements INodeType { name: 'prerelease', type: 'boolean', default: false, - description: 'If set to "true" it will point out that the release is non-production ready', + description: + 'If set to "true" it will point out that the release is non-production ready', }, { displayName: 'Tag Name', @@ -1208,7 +1090,8 @@ export class Github implements INodeType { name: 'target_commitish', type: 'string', default: '', - description: 'Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository\'s default branch(usually master).', + description: + 'Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository\'s default branch(usually master).', }, ], }, @@ -1221,12 +1104,8 @@ export class Github implements INodeType { type: 'boolean', displayOptions: { show: { - resource: [ - 'release', - ], - operation: [ - 'getAll', - ], + resource: ['release'], + operation: ['getAll'], }, }, default: false, @@ -1238,15 +1117,9 @@ export class Github implements INodeType { type: 'number', displayOptions: { show: { - resource: [ - 'release', - ], - operation: [ - 'getAll', - ], - returnAll: [ - false, - ], + resource: ['release'], + operation: ['getAll'], + returnAll: [false], }, }, typeOptions: { @@ -1257,7 +1130,6 @@ export class Github implements INodeType { description: 'Max number of results to return', }, - // ---------------------------------- // repository // ---------------------------------- @@ -1271,12 +1143,8 @@ export class Github implements INodeType { type: 'boolean', displayOptions: { show: { - resource: [ - 'repository', - ], - operation: [ - 'getIssues', - ], + resource: ['repository'], + operation: ['getIssues'], }, }, default: false, @@ -1288,15 +1156,9 @@ export class Github implements INodeType { type: 'number', displayOptions: { show: { - resource: [ - 'repository', - ], - operation: [ - 'getIssues', - ], - returnAll: [ - false, - ], + resource: ['repository'], + operation: ['getIssues'], + returnAll: [false], }, }, typeOptions: { @@ -1315,12 +1177,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'getIssues', - ], - resource: [ - 'repository', - ], + operation: ['getIssues'], + resource: ['repository'], }, }, default: {}, @@ -1351,7 +1209,8 @@ export class Github implements INodeType { name: 'labels', type: 'string', default: '', - description: 'Return only issues with the given labels. Multiple lables can be separated by comma.', + description: + 'Return only issues with the given labels. Multiple lables can be separated by comma.', }, { displayName: 'Updated Since', @@ -1427,11 +1286,9 @@ export class Github implements INodeType { default: 'desc', description: 'The sort order', }, - ], }, - // ---------------------------------- // rerview // ---------------------------------- @@ -1446,13 +1303,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'get', - 'update', - ], - resource: [ - 'review', - ], + operation: ['get', 'update'], + resource: ['review'], }, }, description: 'The number of the pull request', @@ -1465,13 +1317,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'get', - 'update', - ], - resource: [ - 'review', - ], + operation: ['get', 'update'], + resource: ['review'], }, }, description: 'ID of the review', @@ -1488,12 +1335,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'getAll', - ], - resource: [ - 'review', - ], + operation: ['getAll'], + resource: ['review'], }, }, description: 'The number of the pull request', @@ -1504,12 +1347,8 @@ export class Github implements INodeType { type: 'boolean', displayOptions: { show: { - resource: [ - 'review', - ], - operation: [ - 'getAll', - ], + resource: ['review'], + operation: ['getAll'], }, }, default: false, @@ -1521,15 +1360,9 @@ export class Github implements INodeType { type: 'number', displayOptions: { show: { - resource: [ - 'review', - ], - operation: [ - 'getAll', - ], - returnAll: [ - false, - ], + resource: ['review'], + operation: ['getAll'], + returnAll: [false], }, }, typeOptions: { @@ -1550,12 +1383,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'review', - ], + operation: ['create'], + resource: ['review'], }, }, description: 'The number of the pull request to review', @@ -1566,12 +1395,8 @@ export class Github implements INodeType { type: 'options', displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'review', - ], + operation: ['create'], + resource: ['review'], }, }, options: [ @@ -1608,16 +1433,9 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'review', - ], - event: [ - 'requestChanges', - 'comment', - ], + operation: ['create'], + resource: ['review'], + event: ['requestChanges', 'comment'], }, }, default: '', @@ -1631,12 +1449,8 @@ export class Github implements INodeType { default: {}, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'review', - ], + operation: ['create'], + resource: ['review'], }, }, options: [ @@ -1661,12 +1475,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'update', - ], - resource: [ - 'review', - ], + operation: ['update'], + resource: ['review'], }, }, default: '', @@ -1681,12 +1491,8 @@ export class Github implements INodeType { type: 'boolean', displayOptions: { show: { - resource: [ - 'user', - ], - operation: [ - 'getRepositories', - ], + resource: ['user'], + operation: ['getRepositories'], }, }, default: false, @@ -1698,15 +1504,9 @@ export class Github implements INodeType { type: 'number', displayOptions: { show: { - resource: [ - 'user', - ], - operation: [ - 'getRepositories', - ], - returnAll: [ - false, - ], + resource: ['user'], + operation: ['getRepositories'], + returnAll: [false], }, }, typeOptions: { @@ -1716,6 +1516,7 @@ export class Github implements INodeType { default: 50, description: 'Max number of results to return', }, + // ---------------------------------- // user:invite // ---------------------------------- @@ -1727,12 +1528,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'invite', - ], - resource: [ - 'user', - ], + operation: ['invite'], + resource: ['user'], }, }, description: 'The GitHub organization that the user is being invited to', @@ -1745,55 +1542,47 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'invite', - ], - resource: [ - 'user', - ], + operation: ['invite'], + resource: ['user'], }, }, description: 'The email address of the invited user', }, - ], - }; - - methods = { - credentialTest: { - async githubApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise { - const credentials = credential.data; - 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.endsWith('/') ? baseUrl + 'user' : baseUrl + '/user', - json: true, - timeout: 5000, - }; - try { - const response = await this.helpers.request(options); - if (!response.id) { - return { - status: 'Error', - message: `Token is not valid: ${response.error}`, - }; - } - } catch (error) { - return { - status: 'Error', - message: `Settings are not valid: ${error}`, - }; - } - return { - status: 'OK', - message: 'Authentication successful!', - }; + // ---------------------------------- + // organization:getRepositories + // ---------------------------------- + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: ['organization'], + operation: ['getRepositories'], + }, + }, + default: false, + description: 'Whether to return all results or only up to a given limit', }, - }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: ['organization'], + operation: ['getRepositories'], + returnAll: [false], + }, + }, + typeOptions: { + minValue: 1, + maxValue: 100, + }, + default: 50, + description: 'Max number of results to return', + }, + ], }; async execute(this: IExecuteFunctions): Promise { @@ -1836,9 +1625,9 @@ export class Github implements INodeType { 'user:getRepositories', 'release:getAll', 'review:getAll', + 'organization:getRepositories', ]; - // For Post let body: IDataObject; // For Query string @@ -1866,7 +1655,11 @@ export class Github implements INodeType { } let repository = ''; - if (fullOperation !== 'user:getRepositories' && fullOperation !== 'user:invite') { + if ( + fullOperation !== 'user:getRepositories' && + fullOperation !== 'user:invite' && + fullOperation !== 'organization:getRepositories' + ) { repository = this.getNodeParameter('repository', i) as string; } @@ -1880,21 +1673,34 @@ export class Github implements INodeType { const filePath = this.getNodeParameter('filePath', i) as string; - const additionalParameters = this.getNodeParameter('additionalParameters', i, {}) as IDataObject; + const additionalParameters = this.getNodeParameter( + 'additionalParameters', + i, + {}, + ) as IDataObject; if (additionalParameters.author) { body.author = additionalParameters.author; } if (additionalParameters.committer) { body.committer = additionalParameters.committer; } - if (additionalParameters.branch && (additionalParameters.branch as IDataObject).branch) { + if ( + additionalParameters.branch && + (additionalParameters.branch as IDataObject).branch + ) { body.branch = (additionalParameters.branch as IDataObject).branch; } if (operation === 'edit') { // If the file should be updated the request has to contain the SHA // of the file which gets replaced. - body.sha = await getFileSha.call(this, owner, repository, filePath, body.branch as string | undefined); + body.sha = await getFileSha.call( + this, + owner, + repository, + filePath, + body.branch as string | undefined, + ); } body.message = this.getNodeParameter('commitMessage', i) as string; @@ -1910,7 +1716,10 @@ export class Github implements INodeType { const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i) as string; if (item.binary[binaryPropertyName] === undefined) { - throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`); + throw new NodeOperationError( + this.getNode(), + `No binary data property "${binaryPropertyName}" does not exists on item!`, + ); } // Currently internally n8n uses base64 and also Github expects it base64 encoded. @@ -1919,7 +1728,9 @@ export class Github implements INodeType { } else { // Is text file // body.content = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'base64'); - body.content = Buffer.from(this.getNodeParameter('fileContent', i) as string).toString('base64'); + body.content = Buffer.from( + this.getNodeParameter('fileContent', i) as string, + ).toString('base64'); } endpoint = `/repos/${owner}/${repository}/contents/${encodeURI(filePath)}`; @@ -1930,28 +1741,44 @@ export class Github implements INodeType { requestMethod = 'DELETE'; - const additionalParameters = this.getNodeParameter('additionalParameters', i, {}) as IDataObject; + const additionalParameters = this.getNodeParameter( + 'additionalParameters', + i, + {}, + ) as IDataObject; if (additionalParameters.author) { body.author = additionalParameters.author; } if (additionalParameters.committer) { body.committer = additionalParameters.committer; } - if (additionalParameters.branch && (additionalParameters.branch as IDataObject).branch) { + if ( + additionalParameters.branch && + (additionalParameters.branch as IDataObject).branch + ) { body.branch = (additionalParameters.branch as IDataObject).branch; } const filePath = this.getNodeParameter('filePath', i) as string; body.message = this.getNodeParameter('commitMessage', i) as string; - body.sha = await getFileSha.call(this, owner, repository, filePath, body.branch as string | undefined); + 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') { requestMethod = 'GET'; const filePath = this.getNodeParameter('filePath', i) as string; - const additionalParameters = this.getNodeParameter('additionalParameters', i) as IDataObject; + const additionalParameters = this.getNodeParameter( + 'additionalParameters', + i, + ) as IDataObject; if (additionalParameters.reference) { qs.ref = additionalParameters.reference; @@ -2160,7 +1987,6 @@ export class Github implements INodeType { const pullRequestNumber = this.getNodeParameter('pullRequestNumber', i) as string; endpoint = `/repos/${owner}/${repository}/pulls/${pullRequestNumber}/reviews/${reviewId}`; - } else if (operation === 'getAll') { // ---------------------------------- // getAll @@ -2220,7 +2046,6 @@ export class Github implements INodeType { if (returnAll === false) { qs.per_page = this.getNodeParameter('limit', 0) as number; } - } else if (operation === 'invite') { // ---------------------------------- // invite @@ -2230,15 +2055,34 @@ export class Github implements INodeType { const org = this.getNodeParameter('organization', i) as string; endpoint = `/orgs/${org}/invitations`; body.email = this.getNodeParameter('email', i) as string; - } + } else if (resource === 'organization') { + if (operation === 'getRepositories') { + // ---------------------------------- + // getRepositories + // ---------------------------------- + + requestMethod = 'GET'; + + endpoint = `/orgs/${owner}/repos`; + returnAll = this.getNodeParameter('returnAll', 0) as boolean; + if (returnAll === false) { + qs.per_page = this.getNodeParameter('limit', 0) as number; + } + } } else { throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`); } if (returnAll === true) { - responseData = await githubApiRequestAllItems.call(this, requestMethod, endpoint, body, qs); + responseData = await githubApiRequestAllItems.call( + this, + requestMethod, + endpoint, + body, + qs, + ); } else { responseData = await githubApiRequest.call(this, requestMethod, endpoint, body, qs); } @@ -2265,7 +2109,10 @@ export class Github implements INodeType { Object.assign(newItem.binary, items[i].binary); } - newItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(responseData.content, 'base64'), responseData.path); + newItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData( + Buffer.from(responseData.content, 'base64'), + responseData.path, + ); items[i] = newItem; @@ -2281,10 +2128,12 @@ export class Github implements INodeType { } else if (overwriteDataOperationsArray.includes(fullOperation)) { returnData.push.apply(returnData, responseData); } - } catch (error) { if (this.continueOnFail()) { - if (overwriteDataOperations.includes(fullOperation) || overwriteDataOperationsArray.includes(fullOperation)) { + if ( + overwriteDataOperations.includes(fullOperation) || + overwriteDataOperationsArray.includes(fullOperation) + ) { returnData.push({ error: error.message }); } else { items[i].json = { error: error.message }; @@ -2295,7 +2144,10 @@ export class Github implements INodeType { } } - if (overwriteDataOperations.includes(fullOperation) || overwriteDataOperationsArray.includes(fullOperation)) { + if ( + overwriteDataOperations.includes(fullOperation) || + overwriteDataOperationsArray.includes(fullOperation) + ) { // Return data gets replaced return [this.helpers.returnJsonArray(returnData)]; } else {