first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,309 @@
|
||||
import type { INodeProperties } from 'n8n-workflow';
|
||||
|
||||
export const buildOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['build'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Cancel',
|
||||
value: 'cancel',
|
||||
description: 'Cancel a build',
|
||||
action: 'Cancel a build',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a build',
|
||||
action: 'Get a build',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getAll',
|
||||
description: 'Get many builds',
|
||||
action: 'Get many builds',
|
||||
},
|
||||
{
|
||||
name: 'Restart',
|
||||
value: 'restart',
|
||||
description: 'Restart a build',
|
||||
action: 'Restart a build',
|
||||
},
|
||||
{
|
||||
name: 'Trigger',
|
||||
value: 'trigger',
|
||||
description: 'Trigger a build',
|
||||
action: 'Trigger a build',
|
||||
},
|
||||
],
|
||||
default: 'cancel',
|
||||
},
|
||||
];
|
||||
|
||||
export const buildFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* build:cancel */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Build ID',
|
||||
name: 'buildId',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['cancel'],
|
||||
resource: ['build'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Value uniquely identifying the build',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* build:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Build ID',
|
||||
name: 'buildId',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['get'],
|
||||
resource: ['build'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Value uniquely identifying the build',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['build'],
|
||||
operation: ['get'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Include',
|
||||
name: 'include',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'build.commit',
|
||||
description: 'List of attributes to eager load',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* build:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['build'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['getAll'],
|
||||
resource: ['build'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 500,
|
||||
},
|
||||
default: 100,
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['build'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Include',
|
||||
name: 'include',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'build.commit',
|
||||
description: 'List of attributes to eager load',
|
||||
},
|
||||
{
|
||||
displayName: 'Order',
|
||||
name: 'order',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'ASC',
|
||||
value: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'DESC',
|
||||
value: 'desc',
|
||||
},
|
||||
],
|
||||
default: 'asc',
|
||||
description: 'You may specify order to sort your response',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort By',
|
||||
name: 'sortBy',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Created At',
|
||||
value: 'created_at',
|
||||
},
|
||||
{
|
||||
name: 'Finished At',
|
||||
value: 'finished_at',
|
||||
},
|
||||
{
|
||||
name: 'ID',
|
||||
value: 'id',
|
||||
},
|
||||
{
|
||||
name: 'Number',
|
||||
value: 'number',
|
||||
},
|
||||
{
|
||||
name: 'Started At',
|
||||
value: 'started_at',
|
||||
},
|
||||
],
|
||||
default: 'number',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* build:restart */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Build ID',
|
||||
name: 'buildId',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['restart'],
|
||||
resource: ['build'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Value uniquely identifying the build',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* build:trigger */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Slug',
|
||||
name: 'slug',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['trigger'],
|
||||
resource: ['build'],
|
||||
},
|
||||
},
|
||||
placeholder: 'n8n-io/n8n',
|
||||
default: '',
|
||||
description: 'Same as {ownerName}/{repositoryName}',
|
||||
},
|
||||
{
|
||||
displayName: 'Branch',
|
||||
name: 'branch',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['trigger'],
|
||||
resource: ['build'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
placeholder: 'master',
|
||||
description: 'Branch requested to be built',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['build'],
|
||||
operation: ['trigger'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Message',
|
||||
name: 'message',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Travis-ci status message attached to the request',
|
||||
},
|
||||
{
|
||||
displayName: 'Merge Mode',
|
||||
name: 'mergeMode',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Deep Merge',
|
||||
value: 'deep_merge',
|
||||
},
|
||||
{
|
||||
name: 'Deep Merge Append',
|
||||
value: 'deep_merge_append',
|
||||
},
|
||||
{
|
||||
name: 'Deep Merge Prepend',
|
||||
value: 'deep_merge_prepend',
|
||||
},
|
||||
{
|
||||
name: 'Merge',
|
||||
value: 'merge',
|
||||
},
|
||||
{
|
||||
name: 'Replace',
|
||||
value: 'replace',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,74 @@
|
||||
import get from 'lodash/get';
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
JsonObject,
|
||||
IRequestOptions,
|
||||
IHttpRequestMethods,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
export async function travisciApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
body: IDataObject | string = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
option: IDataObject = {},
|
||||
) {
|
||||
const credentials = await this.getCredentials('travisCiApi');
|
||||
let options: IRequestOptions = {
|
||||
headers: {
|
||||
'Travis-API-Version': '3',
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application.json',
|
||||
Authorization: `token ${credentials.apiToken}`,
|
||||
},
|
||||
method,
|
||||
qs,
|
||||
body,
|
||||
uri: uri || `https://api.travis-ci.com${resource}`,
|
||||
json: true,
|
||||
};
|
||||
options = Object.assign({}, options, option);
|
||||
if (Object.keys(options.body as IDataObject).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an API request to paginated TravisCI endpoint
|
||||
* and return all results
|
||||
*/
|
||||
export async function travisciApiRequestAllItems(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
|
||||
body: IDataObject = {},
|
||||
query: IDataObject = {},
|
||||
) {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
|
||||
do {
|
||||
responseData = await travisciApiRequest.call(this, method, resource, body, query);
|
||||
const path = get(responseData, '@pagination.next.@href') as string;
|
||||
if (path !== undefined) {
|
||||
const parsedPath = new URLSearchParams(path);
|
||||
query = Object.fromEntries(parsedPath);
|
||||
}
|
||||
returnData.push.apply(returnData, responseData[propertyName] as IDataObject[]);
|
||||
} while (responseData['@pagination'].is_last !== true);
|
||||
return returnData;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"node": "n8n-nodes-base.travisCi",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Development"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/credentials/travisci/"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.travisci/"
|
||||
}
|
||||
],
|
||||
"generic": [
|
||||
{
|
||||
"label": "How to set up a no-code CI/CD pipeline with GitHub and TravisCI",
|
||||
"icon": "🎡",
|
||||
"url": "https://n8n.io/blog/how-to-set-up-a-ci-cd-pipeline-with-no-code/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeConnectionTypes } from 'n8n-workflow';
|
||||
|
||||
import { buildFields, buildOperations } from './BuildDescription';
|
||||
import { travisciApiRequest, travisciApiRequestAllItems } from './GenericFunctions';
|
||||
|
||||
export class TravisCi implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'TravisCI',
|
||||
name: 'travisCi',
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
||||
icon: 'file:travisci.png',
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume TravisCI API',
|
||||
defaults: {
|
||||
name: 'TravisCI',
|
||||
},
|
||||
usableAsTool: true,
|
||||
inputs: [NodeConnectionTypes.Main],
|
||||
outputs: [NodeConnectionTypes.Main],
|
||||
credentials: [
|
||||
{
|
||||
name: 'travisCiApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Build',
|
||||
value: 'build',
|
||||
},
|
||||
],
|
||||
default: 'build',
|
||||
},
|
||||
...buildOperations,
|
||||
...buildFields,
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
const length = items.length;
|
||||
const qs: IDataObject = {};
|
||||
let responseData;
|
||||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
if (resource === 'build') {
|
||||
//https://developer.travis-ci.com/resource/build#find
|
||||
if (operation === 'get') {
|
||||
const buildId = this.getNodeParameter('buildId', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
if (additionalFields.include) {
|
||||
qs.include = additionalFields.include as string;
|
||||
}
|
||||
|
||||
responseData = await travisciApiRequest.call(this, 'GET', `/build/${buildId}`, {}, qs);
|
||||
}
|
||||
//https://developer.travis-ci.com/resource/builds#for_current_user
|
||||
if (operation === 'getAll') {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
if (additionalFields.sortBy) {
|
||||
qs.sort_by = additionalFields.sortBy;
|
||||
}
|
||||
|
||||
if (additionalFields.sortBy && additionalFields.order) {
|
||||
qs.sort_by = `${additionalFields.sortBy}:${additionalFields.order}`;
|
||||
}
|
||||
|
||||
if (additionalFields.include) {
|
||||
qs.include = additionalFields.include;
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await travisciApiRequestAllItems.call(
|
||||
this,
|
||||
'builds',
|
||||
'GET',
|
||||
'/builds',
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.limit = this.getNodeParameter('limit', i);
|
||||
responseData = await travisciApiRequest.call(this, 'GET', '/builds', {}, qs);
|
||||
responseData = responseData.builds;
|
||||
}
|
||||
}
|
||||
//https://developer.travis-ci.com/resource/build#cancel
|
||||
if (operation === 'cancel') {
|
||||
const buildId = this.getNodeParameter('buildId', i) as string;
|
||||
responseData = await travisciApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/build/${buildId}/cancel`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
}
|
||||
//https://developer.travis-ci.com/resource/build#restart
|
||||
if (operation === 'restart') {
|
||||
const buildId = this.getNodeParameter('buildId', i) as string;
|
||||
responseData = await travisciApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/build/${buildId}/restart`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
}
|
||||
//https://developer.travis-ci.com/resource/requests#create
|
||||
if (operation === 'trigger') {
|
||||
let slug = this.getNodeParameter('slug', i) as string;
|
||||
const branch = this.getNodeParameter('branch', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i);
|
||||
|
||||
slug = slug.replace(new RegExp(/\//g), '%2F');
|
||||
|
||||
const request: IDataObject = {
|
||||
branch,
|
||||
};
|
||||
|
||||
if (additionalFields.message) {
|
||||
request.message = additionalFields.message as string;
|
||||
}
|
||||
|
||||
if (additionalFields.mergeMode) {
|
||||
request.merge_mode = additionalFields.mergeMode as string;
|
||||
}
|
||||
|
||||
responseData = await travisciApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/repo/${slug}/requests`,
|
||||
JSON.stringify({ request }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray(responseData as IDataObject[]),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
|
||||
returnData.push(...executionData);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
const executionErrorData = this.helpers.constructExecutionMetaData(
|
||||
this.helpers.returnJsonArray({ error: error.message }),
|
||||
{ itemData: { item: i } },
|
||||
);
|
||||
returnData.push(...executionErrorData);
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return [returnData];
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
Reference in New Issue
Block a user