From 1690e28a11625e7f082ec68eee2b695f2ae5471d Mon Sep 17 00:00:00 2001 From: Chengyou Liu Date: Tue, 9 Apr 2024 16:51:38 +0800 Subject: [PATCH 1/2] feat(Github Node): add get pull requests --- .../nodes-base/nodes/Github/Github.node.ts | 148 +++++++++++++++++- 1 file changed, 147 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 662996ab2118b..003ab3ef4e838 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -239,6 +239,12 @@ export class Github implements INodeType { description: 'Returns issues of a repository', action: 'Get issues of a repository', }, + { + name: 'Get Pull Requests', + value: 'getPullRequests', + description: 'Returns pull requests of a repository', + action: 'Get pull requests of a repository', + }, { name: 'Get License', value: 'getLicense', @@ -1322,7 +1328,7 @@ export class Github implements INodeType { type: 'string', default: '', description: - 'Return only issues with the given labels. Multiple lables can be separated by comma.', + 'Return only issues with the given labels. Multiple labels can be separated by comma.', }, { displayName: 'Updated Since', @@ -1401,6 +1407,129 @@ export class Github implements INodeType { ], }, + // ---------------------------------- + // repository:getPullRequests + // ---------------------------------- + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: ['repository'], + operation: ['getPullRequests'], + }, + }, + default: false, + description: 'Whether to return all results or only up to a given limit', + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: ['repository'], + operation: ['getPullRequests'], + returnAll: [false], + }, + }, + typeOptions: { + minValue: 1, + maxValue: 100, + }, + default: 50, + description: 'Max number of results to return', + }, + { + displayName: 'Filters', + name: 'getRepositoryPullRequestsFilters', + type: 'collection', + typeOptions: { + multipleValueButtonText: 'Add Filter', + }, + displayOptions: { + show: { + operation: ['getPullRequests'], + resource: ['repository'], + }, + }, + default: {}, + options: [ + { + displayName: 'State', + name: 'state', + type: 'options', + options: [ + { + name: 'All', + value: 'all', + description: 'Returns pull requests with any state', + }, + { + name: 'Closed', + value: 'closed', + description: 'Return pull requests with "closed" state', + }, + { + name: 'Open', + value: 'open', + description: 'Return pull requests with "open" state', + }, + ], + default: 'open', + description: 'The state to set', + }, + { + displayName: 'Sort', + name: 'sort', + type: 'options', + options: [ + { + name: 'Created', + value: 'created', + description: 'Sort by created date', + }, + { + name: 'Updated', + value: 'updated', + description: 'Sort by updated date', + }, + { + name: 'Popularity', + value: 'popularity', + description: 'Sort by number of comments', + }, + { + name: 'Long-Running', + value: 'long-running', + description: 'long-running will sort by date created and will limit the results to pull requests that have been open for more than a month and have had activity within the past month.', + }, + ], + default: 'created', + description: 'The order the pull requests should be returned in', + }, + { + displayName: 'Direction', + name: 'direction', + type: 'options', + options: [ + { + name: 'Ascending', + value: 'asc', + description: 'Sort in ascending order', + }, + { + name: 'Descending', + value: 'desc', + description: 'Sort in descending order', + }, + ], + default: 'desc', + description: 'The sort order', + }, + ], + }, // ---------------------------------- // rerview // ---------------------------------- @@ -1734,6 +1863,7 @@ export class Github implements INodeType { const overwriteDataOperationsArray = [ 'file:list', 'repository:getIssues', + 'repository:getPullRequests', 'repository:listPopularPaths', 'repository:listReferrers', 'user:getRepositories', @@ -2072,6 +2202,22 @@ export class Github implements INodeType { returnAll = this.getNodeParameter('returnAll', 0); + if (!returnAll) { + qs.per_page = this.getNodeParameter('limit', 0); + } + } else if (operation === 'getPullRequests') { + // ---------------------------------- + // getPullRequests + // ---------------------------------- + + requestMethod = 'GET'; + + qs = this.getNodeParameter('getRepositoryPullRequestsFilters', i) as IDataObject; + + endpoint = `/repos/${owner}/${repository}/pulls`; + + returnAll = this.getNodeParameter('returnAll', 0); + if (!returnAll) { qs.per_page = this.getNodeParameter('limit', 0); } From 00f37e865f8bad2cbec3dae3376caf4ceb596a11 Mon Sep 17 00:00:00 2001 From: Chengyou Liu Date: Thu, 11 Apr 2024 23:03:23 +0800 Subject: [PATCH 2/2] fix the lint issues --- packages/nodes-base/nodes/Github/Github.node.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 003ab3ef4e838..dcfa2ef9a5fc1 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -239,12 +239,6 @@ export class Github implements INodeType { description: 'Returns issues of a repository', action: 'Get issues of a repository', }, - { - name: 'Get Pull Requests', - value: 'getPullRequests', - description: 'Returns pull requests of a repository', - action: 'Get pull requests of a repository', - }, { name: 'Get License', value: 'getLicense', @@ -259,6 +253,12 @@ export class Github implements INodeType { 'Get the community profile of a repository with metrics, health score, description, license, etc', action: 'Get the profile of a repository', }, + { + name: 'Get Pull Requests', + value: 'getPullRequests', + description: 'Returns pull requests of a repository', + action: 'Get pull requests of a repository', + }, { name: 'List Popular Paths', value: 'listPopularPaths', @@ -1503,7 +1503,8 @@ export class Github implements INodeType { { name: 'Long-Running', value: 'long-running', - description: 'long-running will sort by date created and will limit the results to pull requests that have been open for more than a month and have had activity within the past month.', + description: + 'Sort by date created and will limit the results to pull requests that have been open for more than a month and have had activity within the past month', }, ], default: 'created',