mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
@@ -6,8 +6,16 @@ import type {
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
IWebhookFunctions,
|
||||
IWebhookResponseData,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
NodeApiError,
|
||||
NodeConnectionTypes,
|
||||
NodeOperationError,
|
||||
WAIT_INDEFINITELY,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
getFileSha,
|
||||
@@ -16,15 +24,19 @@ import {
|
||||
isBase64,
|
||||
validateJSON,
|
||||
} from './GenericFunctions';
|
||||
import { getRepositories, getUsers, getWorkflows } from './SearchFunctions';
|
||||
import { getRefs, getRepositories, getUsers, getWorkflows } from './SearchFunctions';
|
||||
import { defaultWebhookDescription } from '../Webhook/description';
|
||||
|
||||
export class Github implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'GitHub',
|
||||
name: 'github',
|
||||
icon: { light: 'file:github.svg', dark: 'file:github.dark.svg' },
|
||||
icon: {
|
||||
light: 'file:github.svg',
|
||||
dark: 'file:github.dark.svg',
|
||||
},
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
version: [1, 1.1],
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume GitHub API',
|
||||
defaults: {
|
||||
@@ -33,6 +45,15 @@ export class Github implements INodeType {
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
webhooks: [
|
||||
{
|
||||
...defaultWebhookDescription,
|
||||
path: '',
|
||||
restartWebhook: true,
|
||||
httpMethod: 'POST',
|
||||
responseMode: 'onReceived',
|
||||
},
|
||||
],
|
||||
credentials: [
|
||||
{
|
||||
name: 'githubApi',
|
||||
@@ -220,7 +241,7 @@ export class Github implements INodeType {
|
||||
name: 'List',
|
||||
value: 'list',
|
||||
description: 'List contents of a folder',
|
||||
action: 'List a file',
|
||||
action: 'List files',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
@@ -396,9 +417,6 @@ export class Github implements INodeType {
|
||||
default: 'create',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// workflow
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
@@ -422,6 +440,13 @@ export class Github implements INodeType {
|
||||
description: 'Dispatch a workflow event',
|
||||
action: 'Dispatch a workflow event',
|
||||
},
|
||||
{
|
||||
name: 'Dispatch and Wait for Completion',
|
||||
value: 'dispatchAndWait',
|
||||
description:
|
||||
'Dispatch a workflow event and wait for a webhook to be called before proceeding',
|
||||
action: 'Dispatch a workflow event and wait for completion',
|
||||
},
|
||||
{
|
||||
name: 'Enable',
|
||||
value: 'enable',
|
||||
@@ -450,86 +475,17 @@ export class Github implements INodeType {
|
||||
default: 'dispatch',
|
||||
},
|
||||
{
|
||||
displayName: 'Workflow',
|
||||
name: 'workflowId',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
required: true,
|
||||
modes: [
|
||||
{
|
||||
displayName: 'From List',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'Select a workflow...',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getWorkflows',
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By ID',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
placeholder: 'e.g. 12345678',
|
||||
validation: [
|
||||
{
|
||||
type: 'regex',
|
||||
properties: {
|
||||
regex: '\\d+',
|
||||
errorMessage: 'Not a valid Github Workflow ID',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'By File Name',
|
||||
name: 'filename',
|
||||
type: 'string',
|
||||
placeholder: 'e.g. main.yaml or main.yml',
|
||||
validation: [
|
||||
{
|
||||
type: 'regex',
|
||||
properties: {
|
||||
regex: '[a-zA-Z0-9_-]+.(yaml|yml)',
|
||||
errorMessage: 'Not a valid Github Workflow File Name',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
displayName:
|
||||
'Your execution will pause until a webhook is called. This URL will be generated at runtime and passed to your Github workflow as a resumeUrl input.',
|
||||
name: 'webhookNotice',
|
||||
type: 'notice',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['workflow'],
|
||||
operation: ['disable', 'dispatch', 'get', 'getUsage', 'enable'],
|
||||
operation: ['dispatchAndWait'],
|
||||
},
|
||||
},
|
||||
description: 'The workflow to dispatch',
|
||||
},
|
||||
{
|
||||
displayName: 'Ref',
|
||||
name: 'ref',
|
||||
type: 'string',
|
||||
default: 'main',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['workflow'],
|
||||
operation: ['dispatch'],
|
||||
},
|
||||
},
|
||||
description: 'The git reference for the workflow dispatch (branch, tag, or commit SHA)',
|
||||
},
|
||||
{
|
||||
displayName: 'Inputs',
|
||||
name: 'inputs',
|
||||
type: 'json',
|
||||
default: '{}',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['workflow'],
|
||||
operation: ['dispatch'],
|
||||
},
|
||||
},
|
||||
description: 'JSON object with input parameters for the workflow',
|
||||
default: '',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
@@ -599,7 +555,10 @@ export class Github implements INodeType {
|
||||
displayName: 'Repository Name',
|
||||
name: 'repository',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' },
|
||||
default: {
|
||||
mode: 'list',
|
||||
value: '',
|
||||
},
|
||||
required: true,
|
||||
modes: [
|
||||
{
|
||||
@@ -656,6 +615,142 @@ export class Github implements INodeType {
|
||||
},
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// workflow
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Workflow',
|
||||
name: 'workflowId',
|
||||
type: 'resourceLocator',
|
||||
default: {
|
||||
mode: 'list',
|
||||
value: '',
|
||||
},
|
||||
required: true,
|
||||
modes: [
|
||||
{
|
||||
displayName: 'Workflow',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'Select a workflow...',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getWorkflows',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By File Name',
|
||||
name: 'filename',
|
||||
type: 'string',
|
||||
placeholder: 'e.g. main.yaml or main.yml',
|
||||
validation: [
|
||||
{
|
||||
type: 'regex',
|
||||
properties: {
|
||||
regex: '[a-zA-Z0-9_-]+.(yaml|yml)',
|
||||
errorMessage: 'Not a valid Github Workflow File Name',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'By ID',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
placeholder: 'e.g. 12345678',
|
||||
validation: [
|
||||
{
|
||||
type: 'regex',
|
||||
properties: {
|
||||
regex: '\\d+',
|
||||
errorMessage: 'Not a valid Github Workflow ID',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['workflow'],
|
||||
operation: ['disable', 'dispatch', 'dispatchAndWait', 'get', 'getUsage', 'enable'],
|
||||
},
|
||||
},
|
||||
description: 'The workflow to dispatch',
|
||||
},
|
||||
{
|
||||
displayName: 'Ref',
|
||||
name: 'ref',
|
||||
type: 'string',
|
||||
default: 'main',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['workflow'],
|
||||
operation: ['dispatch', 'dispatchAndWait'],
|
||||
'@version': [{ _cnd: { lte: 1 } }],
|
||||
},
|
||||
},
|
||||
description: 'The git reference for the workflow dispatch (branch or tag name)',
|
||||
},
|
||||
{
|
||||
displayName: 'Ref',
|
||||
name: 'ref',
|
||||
type: 'resourceLocator',
|
||||
default: {
|
||||
mode: 'list',
|
||||
value: '',
|
||||
},
|
||||
required: true,
|
||||
modes: [
|
||||
{
|
||||
displayName: 'From List',
|
||||
name: 'list',
|
||||
type: 'list',
|
||||
placeholder: 'Select a branch, tag, or commit...',
|
||||
typeOptions: {
|
||||
searchListMethod: 'getRefs',
|
||||
searchable: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'By Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
placeholder: 'e.g. main',
|
||||
validation: [
|
||||
{
|
||||
type: 'regex',
|
||||
properties: {
|
||||
regex: '^[a-zA-Z0-9/._-]+$',
|
||||
errorMessage: 'Not a valid branch, tag',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['workflow'],
|
||||
operation: ['dispatch', 'dispatchAndWait'],
|
||||
'@version': [{ _cnd: { gte: 1.1 } }],
|
||||
},
|
||||
},
|
||||
description: 'The git reference for the workflow dispatch (branch, tag, or commit SHA)',
|
||||
},
|
||||
{
|
||||
displayName: 'Inputs',
|
||||
name: 'inputs',
|
||||
type: 'json',
|
||||
default: '{}',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['workflow'],
|
||||
operation: ['dispatch', 'dispatchAndWait'],
|
||||
},
|
||||
},
|
||||
description: 'JSON object with input parameters for the workflow',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// file
|
||||
// ----------------------------------
|
||||
@@ -867,7 +962,6 @@ export class Github implements INodeType {
|
||||
placeholder: '',
|
||||
hint: 'The name of the output binary field to put the file in',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'Additional Parameters',
|
||||
name: 'additionalParameters',
|
||||
@@ -1148,6 +1242,7 @@ export class Github implements INodeType {
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// issue:get
|
||||
// ----------------------------------
|
||||
@@ -1163,7 +1258,7 @@ export class Github implements INodeType {
|
||||
resource: ['issue'],
|
||||
},
|
||||
},
|
||||
description: 'The number of the issue get data of',
|
||||
description: 'The issue number to get data for',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
@@ -1181,7 +1276,7 @@ export class Github implements INodeType {
|
||||
resource: ['issue'],
|
||||
},
|
||||
},
|
||||
description: 'The number of the issue to lock',
|
||||
description: 'The issue number to lock',
|
||||
},
|
||||
{
|
||||
displayName: 'Lock Reason',
|
||||
@@ -1216,7 +1311,7 @@ export class Github implements INodeType {
|
||||
},
|
||||
],
|
||||
default: 'resolved',
|
||||
description: 'The reason to lock the issue',
|
||||
description: 'The reason for locking the issue',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
@@ -1382,6 +1477,7 @@ export class Github implements INodeType {
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// release:getAll
|
||||
// ----------------------------------
|
||||
@@ -1700,9 +1796,11 @@ export class Github implements INodeType {
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// rerview
|
||||
// ----------------------------------
|
||||
|
||||
// ----------------------------------
|
||||
// review:getAll
|
||||
// ----------------------------------
|
||||
@@ -1783,6 +1881,7 @@ export class Github implements INodeType {
|
||||
default: 50,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// review:create
|
||||
// ----------------------------------
|
||||
@@ -1871,6 +1970,7 @@ export class Github implements INodeType {
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// review:update
|
||||
// ----------------------------------
|
||||
@@ -1887,6 +1987,7 @@ export class Github implements INodeType {
|
||||
default: '',
|
||||
description: 'The body of the review',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// user:getRepositories
|
||||
// ----------------------------------
|
||||
@@ -1954,6 +2055,7 @@ export class Github implements INodeType {
|
||||
},
|
||||
description: 'The email address of the invited user',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// organization:getRepositories
|
||||
// ----------------------------------
|
||||
@@ -1993,12 +2095,21 @@ export class Github implements INodeType {
|
||||
|
||||
methods = {
|
||||
listSearch: {
|
||||
getUsers,
|
||||
getRefs,
|
||||
getRepositories,
|
||||
getUsers,
|
||||
getWorkflows,
|
||||
},
|
||||
};
|
||||
|
||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||
const requestObject = this.getRequestObject();
|
||||
|
||||
return {
|
||||
workflowData: [this.helpers.returnJsonArray(requestObject.body)],
|
||||
};
|
||||
}
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
@@ -2061,6 +2172,53 @@ export class Github implements INodeType {
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const fullOperation = `${resource}:${operation}`;
|
||||
|
||||
if (resource === 'workflow' && operation === 'dispatchAndWait') {
|
||||
const owner = this.getNodeParameter('owner', 0, '', { extractValue: true }) as string;
|
||||
const repository = this.getNodeParameter('repository', 0, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
const workflowId = this.getNodeParameter('workflowId', 0, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
const ref = this.getNodeParameter('ref', 0, '', { extractValue: true }) as string;
|
||||
|
||||
const inputs = validateJSON(this.getNodeParameter('inputs', 0) as string) as IDataObject;
|
||||
if (!inputs) {
|
||||
throw new NodeOperationError(this.getNode(), 'Inputs: Invalid JSON');
|
||||
}
|
||||
|
||||
endpoint = `/repos/${owner}/${repository}/actions/workflows/${workflowId}/dispatches`;
|
||||
|
||||
body = {
|
||||
ref,
|
||||
inputs,
|
||||
};
|
||||
|
||||
// Generate a webhook URL for the GitHub workflow to call when done
|
||||
const resumeUrl = this.getWorkflowDataProxy(0).$execution.resumeUrl;
|
||||
|
||||
body.inputs = {
|
||||
...inputs,
|
||||
resumeUrl,
|
||||
};
|
||||
|
||||
try {
|
||||
responseData = await githubApiRequest.call(this, 'POST', endpoint, body);
|
||||
} catch (error) {
|
||||
if (error.httpCode === '404' || error.statusCode === 404) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'The workflow to dispatch could not be found. Adjust the "workflow" parameter setting to dispatch the workflow correctly.',
|
||||
{ itemIndex: 0 },
|
||||
);
|
||||
}
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
|
||||
await this.putExecutionToWait(WAIT_INDEFINITELY);
|
||||
return [this.getInputData()];
|
||||
}
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
try {
|
||||
// Reset all values
|
||||
@@ -2504,22 +2662,27 @@ export class Github implements INodeType {
|
||||
|
||||
requestMethod = 'PUT';
|
||||
|
||||
const workflowId = this.getNodeParameter('workflowId', i) as string;
|
||||
const workflowId = this.getNodeParameter('workflowId', i, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
endpoint = `/repos/${owner}/${repository}/actions/workflows/${workflowId}/disable`;
|
||||
} else if (operation === 'dispatch') {
|
||||
}
|
||||
if (operation === 'dispatch') {
|
||||
// ----------------------------------
|
||||
// dispatch
|
||||
// ----------------------------------
|
||||
|
||||
requestMethod = 'POST';
|
||||
|
||||
const workflowId = this.getNodeParameter('workflowId', i, undefined, {
|
||||
const workflowId = this.getNodeParameter('workflowId', i, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
endpoint = `/repos/${owner}/${repository}/actions/workflows/${workflowId}/dispatches`;
|
||||
body.ref = this.getNodeParameter('ref', i) as string;
|
||||
|
||||
const ref = this.getNodeParameter('ref', i, '', { extractValue: true }) as string;
|
||||
body.ref = ref;
|
||||
|
||||
const inputs = validateJSON(
|
||||
this.getNodeParameter('inputs', i) as string,
|
||||
@@ -2537,7 +2700,9 @@ export class Github implements INodeType {
|
||||
|
||||
requestMethod = 'PUT';
|
||||
|
||||
const workflowId = this.getNodeParameter('workflowId', i) as string;
|
||||
const workflowId = this.getNodeParameter('workflowId', i, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
endpoint = `/repos/${owner}/${repository}/actions/workflows/${workflowId}/enable`;
|
||||
} else if (operation === 'get') {
|
||||
@@ -2547,7 +2712,9 @@ export class Github implements INodeType {
|
||||
|
||||
requestMethod = 'GET';
|
||||
|
||||
const workflowId = this.getNodeParameter('workflowId', i) as string;
|
||||
const workflowId = this.getNodeParameter('workflowId', i, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
endpoint = `/repos/${owner}/${repository}/actions/workflows/${workflowId}`;
|
||||
} else if (operation === 'getUsage') {
|
||||
@@ -2557,7 +2724,9 @@ export class Github implements INodeType {
|
||||
|
||||
requestMethod = 'GET';
|
||||
|
||||
const workflowId = this.getNodeParameter('workflowId', i) as string;
|
||||
const workflowId = this.getNodeParameter('workflowId', i, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
endpoint = `/repos/${owner}/${repository}/actions/workflows/${workflowId}/timing`;
|
||||
} else if (operation === 'list') {
|
||||
|
||||
Reference in New Issue
Block a user