mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
parent
6d7368d723
commit
3d45b67d50
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
|
ILoadOptionsFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -16,7 +17,7 @@ import {
|
||||||
* @param {object} body
|
* @param {object} body
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
export async function gitlabApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: object, query?: object): Promise<any> { // tslint:disable-line:no-any
|
export async function gitlabApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: object, query?: object): Promise<any> { // tslint:disable-line:no-any
|
||||||
const credentials = this.getCredentials('gitlabApi');
|
const credentials = this.getCredentials('gitlabApi');
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
throw new Error('No credentials got returned!');
|
throw new Error('No credentials got returned!');
|
||||||
|
@ -34,7 +35,9 @@ export async function gitlabApiRequest(this: IHookFunctions | IExecuteFunctions,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request(options);
|
//@ts-ignore
|
||||||
|
return await this.helpers?.request(options);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.statusCode === 401) {
|
if (error.statusCode === 401) {
|
||||||
// Return a clear error
|
// Return a clear error
|
||||||
|
|
|
@ -135,7 +135,10 @@ export class GitlabTrigger implements INodeType {
|
||||||
// Webhook got created before so check if it still exists
|
// Webhook got created before so check if it still exists
|
||||||
const owner = this.getNodeParameter('owner') as string;
|
const owner = this.getNodeParameter('owner') as string;
|
||||||
const repository = this.getNodeParameter('repository') as string;
|
const repository = this.getNodeParameter('repository') as string;
|
||||||
const endpoint = `/projects/${owner}%2F${repository}/hooks/${webhookData.webhookId}`;
|
|
||||||
|
const path = (`${owner}/${repository}`).replace(/\//g,'%2F');
|
||||||
|
|
||||||
|
const endpoint = `/projects/${path}/hooks/${webhookData.webhookId}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await gitlabApiRequest.call(this, 'GET', endpoint, {});
|
await gitlabApiRequest.call(this, 'GET', endpoint, {});
|
||||||
|
@ -175,15 +178,22 @@ export class GitlabTrigger implements INodeType {
|
||||||
events[`${e}_events`] = true;
|
events[`${e}_events`] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const endpoint = `/projects/${owner}%2F${repository}/hooks`;
|
// gitlab set the push_events to true when the field it's not sent.
|
||||||
|
// set it to false when it's not picked by the user.
|
||||||
|
if (events['push_events'] === undefined) {
|
||||||
|
events['push_events'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = (`${owner}/${repository}`).replace(/\//g,'%2F');
|
||||||
|
|
||||||
|
const endpoint = `/projects/${path}/hooks`;
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
url: webhookUrl,
|
url: webhookUrl,
|
||||||
events,
|
...events,
|
||||||
enable_ssl_verification: false,
|
enable_ssl_verification: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let responseData;
|
let responseData;
|
||||||
try {
|
try {
|
||||||
responseData = await gitlabApiRequest.call(this, 'POST', endpoint, body);
|
responseData = await gitlabApiRequest.call(this, 'POST', endpoint, body);
|
||||||
|
@ -208,7 +218,10 @@ export class GitlabTrigger implements INodeType {
|
||||||
if (webhookData.webhookId !== undefined) {
|
if (webhookData.webhookId !== undefined) {
|
||||||
const owner = this.getNodeParameter('owner') as string;
|
const owner = this.getNodeParameter('owner') as string;
|
||||||
const repository = this.getNodeParameter('repository') as string;
|
const repository = this.getNodeParameter('repository') as string;
|
||||||
const endpoint = `/projects/${owner}%2F${repository}/hooks/${webhookData.webhookId}`;
|
|
||||||
|
const path = (`${owner}/${repository}`).replace(/\//g,'%2F');
|
||||||
|
|
||||||
|
const endpoint = `/projects/${path}/hooks/${webhookData.webhookId}`;
|
||||||
const body = {};
|
const body = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue