mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
parent
6d7368d723
commit
3d45b67d50
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
|
@ -16,7 +17,7 @@ import {
|
|||
* @param {object} body
|
||||
* @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');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
|
@ -34,7 +35,9 @@ export async function gitlabApiRequest(this: IHookFunctions | IExecuteFunctions,
|
|||
};
|
||||
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
//@ts-ignore
|
||||
return await this.helpers?.request(options);
|
||||
|
||||
} catch (error) {
|
||||
if (error.statusCode === 401) {
|
||||
// Return a clear error
|
||||
|
|
|
@ -135,7 +135,10 @@ export class GitlabTrigger implements INodeType {
|
|||
// Webhook got created before so check if it still exists
|
||||
const owner = this.getNodeParameter('owner') 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 {
|
||||
await gitlabApiRequest.call(this, 'GET', endpoint, {});
|
||||
|
@ -175,15 +178,22 @@ export class GitlabTrigger implements INodeType {
|
|||
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 = {
|
||||
url: webhookUrl,
|
||||
events,
|
||||
...events,
|
||||
enable_ssl_verification: false,
|
||||
};
|
||||
|
||||
|
||||
let responseData;
|
||||
try {
|
||||
responseData = await gitlabApiRequest.call(this, 'POST', endpoint, body);
|
||||
|
@ -208,7 +218,10 @@ export class GitlabTrigger implements INodeType {
|
|||
if (webhookData.webhookId !== undefined) {
|
||||
const owner = this.getNodeParameter('owner') 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 = {};
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue