🐛 Fixes issue #663 and #664

This commit is contained in:
Ricardo Espinoza 2020-06-20 12:08:30 -04:00 committed by GitHub
parent 6d7368d723
commit 3d45b67d50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View file

@ -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

View file

@ -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 {