From 8345c46c910ef7f4101f10fc814874f827707211 Mon Sep 17 00:00:00 2001 From: alex meredith Date: Tue, 3 May 2022 11:59:00 +0100 Subject: [PATCH 1/9] options and operations added --- package-lock.json | 4 +- .../nodes-base/nodes/Github/Github.node.ts | 73 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 17a986a45f9e0..025f0a3f7a03b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "n8n", - "version": "0.174.0", + "version": "0.175.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "n8n", - "version": "0.174.0", + "version": "0.175.1", "dependencies": { "@babel/core": "^7.14.6", "@fontsource/open-sans": "^4.5.0", diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index a59d6b2b12072..1b9f88defdc83 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -111,6 +111,10 @@ export class Github implements INodeType { name: 'User', value: 'user', }, + { + name: 'Organization', + value: 'organization', + }, ], default: 'issue', description: 'The resource to operate on.', @@ -121,6 +125,25 @@ export class Github implements INodeType { // ---------------------------------- // operations // ---------------------------------- + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'organization', + ], + }, + }, + options: [{ + name: 'getOrgRepositories', + value: 'getOrgRepositories', + description: 'Get all repositories of an organization',}], + default: 'getOrgRepositories', + description: 'The operation to perform.', + }, + { displayName: 'Operation', name: 'operation', @@ -1717,7 +1740,56 @@ export class Github implements INodeType { }, default: 50, description: 'How many results to return.', + + }, + + // ---------------------------------- + // Org:getOrgRepositories + // ---------------------------------- + { + displayName: 'get Org Repositories', + name: 'getOrgRepositories', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'organisation', + ], + operation: [ + 'getOrgRepositories', + ], + }, + }, + default: true, + description: 'If all results should be returned or only up to a given limit.', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'getOrgRepositories', + ], + returnAll: [ + false, + ], + }, + }, + typeOptions: { + minValue: 1, + maxValue: 100, + }, + default: 50, + description: 'How many results to return.', + + }, + // ---------------------------------- // user:invite // ---------------------------------- @@ -2223,6 +2295,7 @@ export class Github implements INodeType { qs.per_page = this.getNodeParameter('limit', 0) as number; } + } else if (operation === 'invite') { // ---------------------------------- // invite From a09650116aff0594f95ea27579db00b38ee77918 Mon Sep 17 00:00:00 2001 From: alex meredith Date: Wed, 4 May 2022 15:33:46 +0100 Subject: [PATCH 2/9] IT WORKS! --- .../nodes-base/nodes/Github/Github.node.ts | 107 ++++++++---------- 1 file changed, 46 insertions(+), 61 deletions(-) diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 1b9f88defdc83..5136b333edae2 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -125,24 +125,29 @@ export class Github implements INodeType { // ---------------------------------- // operations // ---------------------------------- - { + + { displayName: 'Operation', name: 'operation', type: 'options', displayOptions: { - show: { - resource: [ - 'organization', - ], - }, + show: { + resource: [ + 'organization', + ], + + }, }, - options: [{ - name: 'getOrgRepositories', - value: 'getOrgRepositories', - description: 'Get all repositories of an organization',}], - default: 'getOrgRepositories', + options: [ + { + name: 'Get all Repositories', + value: 'getAll', + description: 'Returns all repositories of an organization', + }, + ], + default: 'getAll', description: 'The operation to perform.', - }, + }, { displayName: 'Operation', @@ -389,7 +394,7 @@ export class Github implements INodeType { name: 'owner', type: 'string', default: '', - required: true, + required: false, displayOptions: { hide: { operation: [ @@ -405,7 +410,7 @@ export class Github implements INodeType { name: 'repository', type: 'string', default: '', - required: true, + required: false, displayOptions: { hide: { resource: [ @@ -1744,52 +1749,6 @@ export class Github implements INodeType { }, - // ---------------------------------- - // Org:getOrgRepositories - // ---------------------------------- - { - displayName: 'get Org Repositories', - name: 'getOrgRepositories', - type: 'boolean', - displayOptions: { - show: { - resource: [ - 'organisation', - ], - operation: [ - 'getOrgRepositories', - ], - }, - }, - default: true, - description: 'If all results should be returned or only up to a given limit.', - }, - { - displayName: 'Limit', - name: 'limit', - type: 'number', - displayOptions: { - show: { - resource: [ - 'user', - ], - operation: [ - 'getOrgRepositories', - ], - returnAll: [ - false, - ], - }, - }, - typeOptions: { - minValue: 1, - maxValue: 100, - }, - default: 50, - description: 'How many results to return.', - - }, - // ---------------------------------- // user:invite // ---------------------------------- @@ -1910,6 +1869,7 @@ export class Github implements INodeType { 'user:getRepositories', 'release:getAll', 'review:getAll', + 'organization:getAll', ]; @@ -1940,7 +1900,7 @@ export class Github implements INodeType { } let repository = ''; - if (fullOperation !== 'user:getRepositories' && fullOperation !== 'user:invite') { + if (fullOperation !== 'user:getRepositories' && fullOperation !== 'user:invite' && fullOperation !== 'organization:getAll') { repository = this.getNodeParameter('repository', i) as string; } @@ -1997,6 +1957,7 @@ export class Github implements INodeType { } endpoint = `/repos/${owner}/${repository}/contents/${encodeURI(filePath)}`; + } else if (operation === 'delete') { // ---------------------------------- // delete @@ -2301,12 +2262,36 @@ export class Github implements INodeType { // invite // ---------------------------------- + requestMethod = 'POST'; 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 === 'getAll') { + // ---------------------------------- + // getRepositories + // ---------------------------------- + + requestMethod = 'GET'; + + endpoint = `/orgs/${owner}/repos`; + + } + + } else if (operation === 'invite') { + // ---------------------------------- + // invite + // ---------------------------------- + + requestMethod = 'POST'; + const org = this.getNodeParameter('organization', i) as string; + endpoint = `/orgs/${org}/invitations`; + body.email = this.getNodeParameter('email', i) as string; + + } else { throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`); From 60cd3513116f1f737b862404f36dce70529bfe9e Mon Sep 17 00:00:00 2001 From: alex meredith Date: Wed, 4 May 2022 17:46:19 +0100 Subject: [PATCH 3/9] Added ReturnALL to GET method --- packages/nodes-base/nodes/Github/Github.node.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 5136b333edae2..1903fd2dc1c59 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -2278,6 +2278,7 @@ export class Github implements INodeType { requestMethod = 'GET'; endpoint = `/orgs/${owner}/repos`; + returnAll = true; } From 155a9961e6346f184c6fd3fc2ab6b78d2a8b2941 Mon Sep 17 00:00:00 2001 From: alex meredith Date: Thu, 5 May 2022 16:31:26 +0100 Subject: [PATCH 4/9] comit for PR --- packages/nodes-base/nodes/Github/Github.node.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 1903fd2dc1c59..075d107866cc6 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -141,11 +141,11 @@ export class Github implements INodeType { options: [ { name: 'Get all Repositories', - value: 'getAll', + value: 'getRepositories', description: 'Returns all repositories of an organization', }, ], - default: 'getAll', + default: 'getRepositories', description: 'The operation to perform.', }, @@ -415,6 +415,7 @@ export class Github implements INodeType { hide: { resource: [ 'user', + 'organization', ], operation: [ 'getRepositories', @@ -1869,7 +1870,7 @@ export class Github implements INodeType { 'user:getRepositories', 'release:getAll', 'review:getAll', - 'organization:getAll', + 'organization:getRepositories', ]; @@ -1900,7 +1901,7 @@ export class Github implements INodeType { } let repository = ''; - if (fullOperation !== 'user:getRepositories' && fullOperation !== 'user:invite' && fullOperation !== 'organization:getAll') { + if (fullOperation !== 'user:getRepositories' && fullOperation !== 'user:invite' && fullOperation !== 'organization:getRepositories') { repository = this.getNodeParameter('repository', i) as string; } @@ -2270,7 +2271,7 @@ export class Github implements INodeType { } } else if (resource === 'organization') { - if (operation === 'getAll') { + if (operation === 'getRepositories') { // ---------------------------------- // getRepositories // ---------------------------------- From 1e2244b658cdd6bfef3cf6c74e74740d61985ed8 Mon Sep 17 00:00:00 2001 From: ajmeredith1200 <100841449+ajmeredith1200@users.noreply.github.com> Date: Thu, 5 May 2022 17:00:27 +0100 Subject: [PATCH 5/9] updating shared operations --- packages/nodes-base/nodes/Github/Github.node.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 075d107866cc6..822d62ba9806a 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -394,7 +394,7 @@ export class Github implements INodeType { name: 'owner', type: 'string', default: '', - required: false, + required: true, displayOptions: { hide: { operation: [ @@ -410,7 +410,7 @@ export class Github implements INodeType { name: 'repository', type: 'string', default: '', - required: false, + required: true, displayOptions: { hide: { resource: [ From 559e1d7366d9edb4d4a82d5f1e26ce30a29fc77c Mon Sep 17 00:00:00 2001 From: Michael Kret Date: Tue, 31 May 2022 08:54:32 +0300 Subject: [PATCH 6/9] :zap: linter fixes --- .../nodes-base/nodes/Github/Github.node.ts | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 54187dfff0eda..2bba948c2c8c2 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -119,34 +119,32 @@ export class Github implements INodeType { default: 'issue', }, - - // ---------------------------------- // operations // ---------------------------------- - { + { displayName: 'Operation', name: 'operation', type: 'options', + noDataExpression: true, displayOptions: { - show: { - resource: [ - 'organization', - ], + show: { + resource: [ + 'organization', + ], - }, + }, }, options: [ - { - name: 'Get all Repositories', - value: 'getRepositories', - description: 'Returns all repositories of an organization', - }, + { + name: 'Get all Repositories', + value: 'getRepositories', + description: 'Returns all repositories of an organization', + }, ], default: 'getRepositories', - description: 'The operation to perform.', - }, + }, { displayName: 'Operation', From f3c0d50e37d6593b3dc8a525265de05281df73f5 Mon Sep 17 00:00:00 2001 From: Michael Kret Date: Tue, 31 May 2022 10:11:50 +0300 Subject: [PATCH 7/9] :zap: improvements --- package-lock.json | 4 +- .../nodes-base/nodes/Github/Github.node.ts | 658 +++++++----------- 2 files changed, 254 insertions(+), 408 deletions(-) diff --git a/package-lock.json b/package-lock.json index 08a9a617bc1aa..bfc252e3268be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "n8n", - "version": "0.178.2", + "version": "0.179.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "n8n", - "version": "0.178.2", + "version": "0.179.0", "dependencies": { "@babel/core": "^7.14.6", "@fontsource/open-sans": "^4.5.0", diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 2bba948c2c8c2..cea151cc05a9b 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -1,4 +1,6 @@ -import { OptionsWithUri } from 'request'; +import { + OptionsWithUri, +} from 'request'; import { IExecuteFunctions, @@ -46,9 +48,7 @@ export class Github implements INodeType { testedBy: 'githubApiTest', displayOptions: { show: { - authentication: [ - 'accessToken', - ], + authentication: ['accessToken'], }, }, }, @@ -57,9 +57,7 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - authentication: [ - 'oAuth2', - ], + authentication: ['oAuth2'], }, }, }, @@ -122,7 +120,6 @@ export class Github implements INodeType { // ---------------------------------- // operations // ---------------------------------- - { displayName: 'Operation', name: 'operation', @@ -130,15 +127,12 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'organization', - ], - + resource: ['organization'], }, }, options: [ { - name: 'Get all Repositories', + name: 'Get Repositories', value: 'getRepositories', description: 'Returns all repositories of an organization', }, @@ -153,9 +147,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'issue', - ], + resource: ['issue'], }, }, options: [ @@ -195,9 +187,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'file', - ], + resource: ['file'], }, }, options: [ @@ -237,9 +227,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'repository', - ], + resource: ['repository'], }, }, options: [ @@ -251,7 +239,8 @@ export class Github implements INodeType { { name: 'Get License', value: 'getLicense', - description: 'Returns the contents of the repository\'s license file, if one is detected', + description: + 'Returns the contents of the repository\'s license file, if one is detected', }, { name: 'Get Issues', @@ -261,7 +250,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', @@ -284,9 +274,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'user', - ], + resource: ['user'], }, }, options: [ @@ -311,9 +299,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'release', - ], + resource: ['release'], }, }, options: [ @@ -353,9 +339,7 @@ export class Github implements INodeType { noDataExpression: true, displayOptions: { show: { - resource: [ - 'review', - ], + resource: ['review'], }, }, options: [ @@ -394,9 +378,7 @@ export class Github implements INodeType { required: true, displayOptions: { hide: { - operation: [ - 'invite', - ], + operation: ['invite'], }, }, placeholder: 'n8n-io', @@ -410,21 +392,14 @@ export class Github implements INodeType { required: true, displayOptions: { hide: { - resource: [ - 'user', - 'organization', - ], - operation: [ - 'getRepositories', - ], + resource: ['user', 'organization'], + operation: ['getRepositories'], }, }, placeholder: 'n8n', description: 'The name of the repository', }, - - // ---------------------------------- // file // ---------------------------------- @@ -440,14 +415,10 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - resource: [ - 'file', - ], + resource: ['file'], }, hide: { - operation: [ - 'list', - ], + operation: ['list'], }, }, placeholder: 'docs/README.md', @@ -464,12 +435,8 @@ export class Github implements INodeType { default: '', displayOptions: { show: { - resource: [ - 'file', - ], - operation: [ - 'list', - ], + resource: ['file'], + operation: ['list'], }, }, placeholder: 'docs/', @@ -487,13 +454,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', @@ -506,18 +468,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', @@ -530,18 +484,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', @@ -554,14 +500,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'create', - 'delete', - 'edit', - ], - resource: [ - 'file', - ], + operation: ['create', 'delete', 'edit'], + resource: ['file'], }, }, }, @@ -574,14 +514,8 @@ export class Github implements INodeType { default: {}, displayOptions: { show: { - operation: [ - 'create', - 'delete', - 'edit', - ], - resource: [ - 'file', - ], + operation: ['create', 'delete', 'edit'], + resource: ['file'], }, }, options: [ @@ -614,7 +548,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.', }, ], }, @@ -651,15 +586,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', @@ -669,20 +601,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', }, { @@ -694,12 +620,8 @@ export class Github implements INodeType { default: {}, displayOptions: { show: { - operation: [ - 'get', - ], - resource: [ - 'file', - ], + operation: ['get'], + resource: ['file'], }, }, options: [ @@ -709,7 +631,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).', }, ], }, @@ -729,12 +652,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'issue', - ], + operation: ['create'], + resource: ['issue'], }, }, description: 'The title of the issue', @@ -749,12 +668,8 @@ export class Github implements INodeType { default: '', displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'issue', - ], + operation: ['create'], + resource: ['issue'], }, }, description: 'The body of the issue', @@ -769,15 +684,11 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'issue', - ], + operation: ['create'], + resource: ['issue'], }, }, - default: { 'label': '' }, + default: { label: '' }, options: [ { displayName: 'Label', @@ -798,15 +709,11 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'issue', - ], + operation: ['create'], + resource: ['issue'], }, }, - default: { 'assignee': '' }, + default: { assignee: '' }, options: [ { displayName: 'Assignee', @@ -829,12 +736,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', @@ -848,12 +751,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'createComment', - ], - resource: [ - 'issue', - ], + operation: ['createComment'], + resource: ['issue'], }, }, default: '', @@ -871,12 +770,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', @@ -890,12 +785,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'edit', - ], - resource: [ - 'issue', - ], + operation: ['edit'], + resource: ['issue'], }, }, default: {}, @@ -944,7 +835,7 @@ export class Github implements INodeType { multipleValues: true, multipleValueButtonText: 'Add Label', }, - default: { 'label': '' }, + default: { label: '' }, options: [ { displayName: 'Label', @@ -963,7 +854,7 @@ export class Github implements INodeType { multipleValues: true, multipleValueButtonText: 'Add Assignee', }, - default: { 'assignee': '' }, + default: { assignee: '' }, options: [ { displayName: 'Assignees', @@ -988,12 +879,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', @@ -1010,12 +897,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', @@ -1026,12 +909,8 @@ export class Github implements INodeType { type: 'options', displayOptions: { show: { - operation: [ - 'lock', - ], - resource: [ - 'issue', - ], + operation: ['lock'], + resource: ['issue'], }, }, options: [ @@ -1060,8 +939,6 @@ export class Github implements INodeType { description: 'The reason to lock the issue', }, - - // ---------------------------------- // release // ---------------------------------- @@ -1077,12 +954,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'release', - ], + operation: ['create'], + resource: ['release'], }, }, description: 'The tag of the release', @@ -1096,12 +969,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'release', - ], + operation: ['create'], + resource: ['release'], }, }, default: {}, @@ -1128,21 +997,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).', }, ], }, @@ -1158,14 +1030,8 @@ export class Github implements INodeType { required: true, displayOptions: { show: { - resource: [ - 'release', - ], - operation: [ - 'get', - 'delete', - 'update', - ], + resource: ['release'], + operation: ['get', 'delete', 'update'], }, }, }, @@ -1182,12 +1048,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'update', - ], - resource: [ - 'release', - ], + operation: ['update'], + resource: ['release'], }, }, default: {}, @@ -1207,7 +1069,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', @@ -1221,7 +1084,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', @@ -1235,7 +1099,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).', }, ], }, @@ -1248,12 +1113,8 @@ export class Github implements INodeType { type: 'boolean', displayOptions: { show: { - resource: [ - 'release', - ], - operation: [ - 'getAll', - ], + resource: ['release'], + operation: ['getAll'], }, }, default: false, @@ -1265,15 +1126,9 @@ export class Github implements INodeType { type: 'number', displayOptions: { show: { - resource: [ - 'release', - ], - operation: [ - 'getAll', - ], - returnAll: [ - false, - ], + resource: ['release'], + operation: ['getAll'], + returnAll: [false], }, }, typeOptions: { @@ -1284,7 +1139,6 @@ export class Github implements INodeType { description: 'Max number of results to return', }, - // ---------------------------------- // repository // ---------------------------------- @@ -1298,12 +1152,8 @@ export class Github implements INodeType { type: 'boolean', displayOptions: { show: { - resource: [ - 'repository', - ], - operation: [ - 'getIssues', - ], + resource: ['repository'], + operation: ['getIssues'], }, }, default: false, @@ -1315,15 +1165,9 @@ export class Github implements INodeType { type: 'number', displayOptions: { show: { - resource: [ - 'repository', - ], - operation: [ - 'getIssues', - ], - returnAll: [ - false, - ], + resource: ['repository'], + operation: ['getIssues'], + returnAll: [false], }, }, typeOptions: { @@ -1342,12 +1186,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'getIssues', - ], - resource: [ - 'repository', - ], + operation: ['getIssues'], + resource: ['repository'], }, }, default: {}, @@ -1378,7 +1218,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', @@ -1454,11 +1295,9 @@ export class Github implements INodeType { default: 'desc', description: 'The sort order', }, - ], }, - // ---------------------------------- // rerview // ---------------------------------- @@ -1473,13 +1312,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', @@ -1492,13 +1326,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', @@ -1515,12 +1344,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', @@ -1531,12 +1356,8 @@ export class Github implements INodeType { type: 'boolean', displayOptions: { show: { - resource: [ - 'review', - ], - operation: [ - 'getAll', - ], + resource: ['review'], + operation: ['getAll'], }, }, default: false, @@ -1548,15 +1369,9 @@ export class Github implements INodeType { type: 'number', displayOptions: { show: { - resource: [ - 'review', - ], - operation: [ - 'getAll', - ], - returnAll: [ - false, - ], + resource: ['review'], + operation: ['getAll'], + returnAll: [false], }, }, typeOptions: { @@ -1577,12 +1392,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', @@ -1593,12 +1404,8 @@ export class Github implements INodeType { type: 'options', displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'review', - ], + operation: ['create'], + resource: ['review'], }, }, options: [ @@ -1635,16 +1442,9 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'review', - ], - event: [ - 'requestChanges', - 'comment', - ], + operation: ['create'], + resource: ['review'], + event: ['requestChanges', 'comment'], }, }, default: '', @@ -1658,12 +1458,8 @@ export class Github implements INodeType { default: {}, displayOptions: { show: { - operation: [ - 'create', - ], - resource: [ - 'review', - ], + operation: ['create'], + resource: ['review'], }, }, options: [ @@ -1688,12 +1484,8 @@ export class Github implements INodeType { }, displayOptions: { show: { - operation: [ - 'update', - ], - resource: [ - 'review', - ], + operation: ['update'], + resource: ['review'], }, }, default: '', @@ -1708,12 +1500,8 @@ export class Github implements INodeType { type: 'boolean', displayOptions: { show: { - resource: [ - 'user', - ], - operation: [ - 'getRepositories', - ], + resource: ['user'], + operation: ['getRepositories'], }, }, default: false, @@ -1725,15 +1513,9 @@ export class Github implements INodeType { type: 'number', displayOptions: { show: { - resource: [ - 'user', - ], - operation: [ - 'getRepositories', - ], - returnAll: [ - false, - ], + resource: ['user'], + operation: ['getRepositories'], + returnAll: [false], }, }, typeOptions: { @@ -1755,12 +1537,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', @@ -1773,24 +1551,57 @@ 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', }, + // ---------------------------------- + // 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', + }, ], }; methods = { credentialTest: { - async githubApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise { + async githubApiTest( + this: ICredentialTestFunctions, + credential: ICredentialsDecrypted, + ): Promise { const credentials = credential.data; - const baseUrl = credentials!.server as string || 'https://api.github.com'; + const baseUrl = (credentials!.server as string) || 'https://api.github.com'; const options: OptionsWithUri = { method: 'GET', @@ -1867,7 +1678,6 @@ export class Github implements INodeType { 'organization:getRepositories', ]; - // For Post let body: IDataObject; // For Query string @@ -1895,7 +1705,11 @@ export class Github implements INodeType { } let repository = ''; - if (fullOperation !== 'user:getRepositories' && fullOperation !== 'user:invite' && fullOperation !== 'organization:getRepositories') { + if ( + fullOperation !== 'user:getRepositories' && + fullOperation !== 'user:invite' && + fullOperation !== 'organization:getRepositories' + ) { repository = this.getNodeParameter('repository', i) as string; } @@ -1909,21 +1723,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; @@ -1939,7 +1766,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. @@ -1948,11 +1778,12 @@ 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)}`; - } else if (operation === 'delete') { // ---------------------------------- // delete @@ -1960,28 +1791,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; @@ -2190,7 +2037,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 @@ -2250,19 +2096,15 @@ export class Github implements INodeType { if (returnAll === false) { qs.per_page = this.getNodeParameter('limit', 0) as number; } - - } else if (operation === 'invite') { // ---------------------------------- // invite // ---------------------------------- - requestMethod = 'POST'; 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') { @@ -2273,28 +2115,24 @@ export class Github implements INodeType { requestMethod = 'GET'; endpoint = `/orgs/${owner}/repos`; - returnAll = true; + returnAll = this.getNodeParameter('returnAll', 0) as boolean; + if (returnAll === false) { + qs.per_page = this.getNodeParameter('limit', 0) as number; } - - } else if (operation === 'invite') { - // ---------------------------------- - // invite - // ---------------------------------- - - requestMethod = 'POST'; - const org = this.getNodeParameter('organization', i) as string; - endpoint = `/orgs/${org}/invitations`; - body.email = this.getNodeParameter('email', i) as string; - - - + } } 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); } @@ -2321,7 +2159,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; @@ -2337,10 +2178,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 }; @@ -2351,7 +2194,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 { From e6fef4b494540112741b206d7597146f73dfd115 Mon Sep 17 00:00:00 2001 From: Michael Kret Date: Tue, 31 May 2022 10:14:17 +0300 Subject: [PATCH 8/9] :zap: lock file fix --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index bfc252e3268be..08a9a617bc1aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "n8n", - "version": "0.179.0", + "version": "0.178.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "n8n", - "version": "0.179.0", + "version": "0.178.2", "dependencies": { "@babel/core": "^7.14.6", "@fontsource/open-sans": "^4.5.0", From 2ca27006fd86be24fd1d8ece8a890943f2ef53d3 Mon Sep 17 00:00:00 2001 From: Michael Kret Date: Tue, 31 May 2022 10:46:20 +0300 Subject: [PATCH 9/9] :zap: credentials update --- .../credentials/GithubApi.credentials.ts | 16 ++++++ .../nodes/Github/GenericFunctions.ts | 10 ++-- .../nodes-base/nodes/Github/Github.node.ts | 49 ------------------- 3 files changed, 21 insertions(+), 54 deletions(-) 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 cea151cc05a9b..6989ee9efc606 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -1,16 +1,9 @@ -import { - OptionsWithUri, -} from 'request'; - import { IExecuteFunctions, } from 'n8n-core'; import { - ICredentialsDecrypted, - ICredentialTestFunctions, IDataObject, - INodeCredentialTestResult, INodeExecutionData, INodeType, INodeTypeDescription, @@ -45,7 +38,6 @@ export class Github implements INodeType { { name: 'githubApi', required: true, - testedBy: 'githubApiTest', displayOptions: { show: { authentication: ['accessToken'], @@ -1594,47 +1586,6 @@ export class Github implements INodeType { ], }; - 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!', - }; - }, - }, - }; - async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); const returnData: IDataObject[] = [];