mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
🔀 Merge branch 'master' of github.com:n8n-io/n8n
This commit is contained in:
commit
2437356f91
|
@ -58,58 +58,36 @@ export class BitbucketTrigger implements INodeType {
|
||||||
type: 'options',
|
type: 'options',
|
||||||
required: true,
|
required: true,
|
||||||
options: [
|
options: [
|
||||||
{
|
|
||||||
name: 'User',
|
|
||||||
value: 'user',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Team',
|
|
||||||
value: 'team',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'Repository',
|
name: 'Repository',
|
||||||
value: 'repository',
|
value: 'repository',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Workspace',
|
||||||
|
value: 'workspace',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
default: 'user',
|
default: 'workspace',
|
||||||
description: 'The resource to operate on.',
|
description: 'The resource to operate on.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Events',
|
displayName: 'Workspace',
|
||||||
name: 'events',
|
name: 'workspace',
|
||||||
type: 'multiOptions',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: [
|
|
||||||
'user',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
typeOptions: {
|
|
||||||
loadOptionsMethod: 'getUsersEvents',
|
|
||||||
},
|
|
||||||
options: [],
|
|
||||||
required: true,
|
|
||||||
default: [],
|
|
||||||
description: 'The events to listen to.',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Team',
|
|
||||||
name: 'team',
|
|
||||||
type: 'options',
|
type: 'options',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'team',
|
'workspace',
|
||||||
|
'repository',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
loadOptionsMethod: 'getTeams',
|
loadOptionsMethod: 'getWorkspaces',
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The team of which to listen to the events.',
|
description: 'The repository of which to listen to the events.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Events',
|
displayName: 'Events',
|
||||||
|
@ -118,12 +96,12 @@ export class BitbucketTrigger implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'team',
|
'workspace',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
loadOptionsMethod: 'getTeamEvents',
|
loadOptionsMethod: 'getWorkspaceEvents',
|
||||||
},
|
},
|
||||||
options: [],
|
options: [],
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -143,6 +121,9 @@ export class BitbucketTrigger implements INodeType {
|
||||||
},
|
},
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
loadOptionsMethod: 'getRepositories',
|
loadOptionsMethod: 'getRepositories',
|
||||||
|
loadOptionsDependsOn: [
|
||||||
|
'workspace',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -208,89 +189,50 @@ export class BitbucketTrigger implements INodeType {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
loadOptions: {
|
loadOptions: {
|
||||||
// Get all the events to display them to user so that he can
|
async getWorkspaceEvents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
// select them easily
|
|
||||||
async getUsersEvents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
const events = await bitbucketApiRequestAllItems.call(this, 'values', 'GET', '/hook_events/user');
|
const events = await bitbucketApiRequestAllItems.call(this, 'values', 'GET', '/hook_events/workspace');
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
const eventName = event.event;
|
|
||||||
const eventId = event.event;
|
|
||||||
const eventDescription = event.description;
|
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: eventName,
|
name: event.event,
|
||||||
value: eventId,
|
value: event.event,
|
||||||
description: eventDescription,
|
description: event.description,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
// Get all the events to display them to user so that he can
|
|
||||||
// select them easily
|
|
||||||
async getTeamEvents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
|
||||||
const events = await bitbucketApiRequestAllItems.call(this, 'values', 'GET', '/hook_events/team');
|
|
||||||
for (const event of events) {
|
|
||||||
const eventName = event.event;
|
|
||||||
const eventId = event.event;
|
|
||||||
const eventDescription = event.description;
|
|
||||||
returnData.push({
|
|
||||||
name: eventName,
|
|
||||||
value: eventId,
|
|
||||||
description: eventDescription,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return returnData;
|
|
||||||
},
|
|
||||||
// Get all the events to display them to user so that he can
|
|
||||||
// select them easily
|
|
||||||
async getRepositoriesEvents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getRepositoriesEvents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
const events = await bitbucketApiRequestAllItems.call(this, 'values', 'GET', '/hook_events/repository');
|
const events = await bitbucketApiRequestAllItems.call(this, 'values', 'GET', '/hook_events/repository');
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
const eventName = event.event;
|
|
||||||
const eventId = event.event;
|
|
||||||
const eventDescription = event.description;
|
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: eventName,
|
name: event.event,
|
||||||
value: eventId,
|
value: event.event,
|
||||||
description: eventDescription,
|
description: event.description,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
// Get all the repositories to display them to user so that he can
|
|
||||||
// select them easily
|
|
||||||
async getRepositories(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getRepositories(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const credentials = await this.getCredentials('bitbucketApi');
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
const repositories = await bitbucketApiRequestAllItems.call(this, 'values', 'GET', `/repositories/${credentials!.username}`);
|
const workspace = this.getCurrentNodeParameter('workspace') as string;
|
||||||
|
const repositories = await bitbucketApiRequestAllItems.call(this, 'values', 'GET', `/repositories/${workspace}`);
|
||||||
for (const repository of repositories) {
|
for (const repository of repositories) {
|
||||||
const repositoryName = repository.slug;
|
|
||||||
const repositoryId = repository.slug;
|
|
||||||
const repositoryDescription = repository.description;
|
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: repositoryName,
|
name: repository.slug,
|
||||||
value: repositoryId,
|
value: repository.slug,
|
||||||
description: repositoryDescription,
|
description: repository.description,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
// Get all the teams to display them to user so that he can
|
async getWorkspaces(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
// select them easily
|
|
||||||
async getTeams(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
const qs: IDataObject = {
|
const workspaces = await bitbucketApiRequestAllItems.call(this, 'values', 'GET', `/workspaces`);
|
||||||
role: 'member',
|
for (const workspace of workspaces) {
|
||||||
};
|
|
||||||
const teams = await bitbucketApiRequestAllItems.call(this, 'values', 'GET', '/teams', {}, qs);
|
|
||||||
for (const team of teams) {
|
|
||||||
const teamName = team.display_name;
|
|
||||||
const teamId = team.username;
|
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: teamName,
|
name: workspace.name,
|
||||||
value: teamId,
|
value: workspace.slug,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
|
@ -302,29 +244,25 @@ export class BitbucketTrigger implements INodeType {
|
||||||
default: {
|
default: {
|
||||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||||
let endpoint = '';
|
let endpoint = '';
|
||||||
const credentials = await this.getCredentials('bitbucketApi');
|
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
|
const workspace = this.getNodeParameter('workspace', 0) as string;
|
||||||
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
if (webhookData.webhookId === undefined) {
|
if (resource === 'workspace') {
|
||||||
return false;
|
endpoint = `/workspaces/${workspace}/hooks`;
|
||||||
}
|
|
||||||
if (resource === 'user') {
|
|
||||||
endpoint = `/users/${credentials!.username}/hooks/${webhookData.webhookId}`;
|
|
||||||
}
|
|
||||||
if (resource === 'team') {
|
|
||||||
const team = this.getNodeParameter('team', 0) as string;
|
|
||||||
endpoint = `/teams/${team}/hooks/${webhookData.webhookId}`;
|
|
||||||
}
|
}
|
||||||
if (resource === 'repository') {
|
if (resource === 'repository') {
|
||||||
const repository = this.getNodeParameter('repository', 0) as string;
|
const repository = this.getNodeParameter('repository', 0) as string;
|
||||||
endpoint = `/repositories/${credentials!.username}/${repository}/hooks/${webhookData.webhookId}`;
|
endpoint = `/repositories/${workspace}/${repository}/hooks`;
|
||||||
}
|
|
||||||
try {
|
|
||||||
await bitbucketApiRequest.call(this, 'GET', endpoint);
|
|
||||||
} catch (error) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
const { values: hooks } = await bitbucketApiRequest.call(this, 'GET', endpoint);
|
||||||
|
for (const hook of hooks) {
|
||||||
|
if (webhookUrl === hook.url && hook.active === true) {
|
||||||
|
webhookData.webhookId = hook.uuid.replace('{', '').replace('}', '');
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
async create(this: IHookFunctions): Promise<boolean> {
|
async create(this: IHookFunctions): Promise<boolean> {
|
||||||
let responseData;
|
let responseData;
|
||||||
|
@ -333,18 +271,14 @@ export class BitbucketTrigger implements INodeType {
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
const events = this.getNodeParameter('events') as string[];
|
const events = this.getNodeParameter('events') as string[];
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
const credentials = await this.getCredentials('bitbucketApi');
|
const workspace = this.getNodeParameter('workspace', 0) as string;
|
||||||
|
|
||||||
if (resource === 'user') {
|
if (resource === 'workspace') {
|
||||||
endpoint = `/users/${credentials!.username}/hooks`;
|
endpoint = `/workspaces/${workspace}/hooks`;
|
||||||
}
|
|
||||||
if (resource === 'team') {
|
|
||||||
const team = this.getNodeParameter('team', 0) as string;
|
|
||||||
endpoint = `/teams/${team}/hooks`;
|
|
||||||
}
|
}
|
||||||
if (resource === 'repository') {
|
if (resource === 'repository') {
|
||||||
const repository = this.getNodeParameter('repository', 0) as string;
|
const repository = this.getNodeParameter('repository', 0) as string;
|
||||||
endpoint = `/repositories/${credentials!.username}/${repository}/hooks`;
|
endpoint = `/repositories/${workspace}/${repository}/hooks`;
|
||||||
}
|
}
|
||||||
const body: IDataObject = {
|
const body: IDataObject = {
|
||||||
description: 'n8n webhook',
|
description: 'n8n webhook',
|
||||||
|
@ -359,22 +293,18 @@ export class BitbucketTrigger implements INodeType {
|
||||||
async delete(this: IHookFunctions): Promise<boolean> {
|
async delete(this: IHookFunctions): Promise<boolean> {
|
||||||
let endpoint = '';
|
let endpoint = '';
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
const credentials = await this.getCredentials('bitbucketApi');
|
const workspace = this.getNodeParameter('workspace', 0) as string;
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
if (resource === 'user') {
|
if (resource === 'workspace') {
|
||||||
endpoint = `/users/${credentials!.username}/hooks/${webhookData.webhookId}`;
|
endpoint = `/workspaces/${workspace}/hooks/${webhookData.webhookId}`;
|
||||||
}
|
|
||||||
if (resource === 'team') {
|
|
||||||
const team = this.getNodeParameter('team', 0) as string;
|
|
||||||
endpoint = `/teams/${team}/hooks/${webhookData.webhookId}`;
|
|
||||||
}
|
}
|
||||||
if (resource === 'repository') {
|
if (resource === 'repository') {
|
||||||
const repository = this.getNodeParameter('repository', 0) as string;
|
const repository = this.getNodeParameter('repository', 0) as string;
|
||||||
endpoint = `/repositories/${credentials!.username}/${repository}/hooks/${webhookData.webhookId}`;
|
endpoint = `/repositories/${workspace}/${repository}/hooks/${webhookData.webhookId}`;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await bitbucketApiRequest.call(this, 'DELETE', endpoint);
|
await bitbucketApiRequest.call(this, 'DELETE', endpoint);
|
||||||
} catch(error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
delete webhookData.webhookId;
|
delete webhookData.webhookId;
|
||||||
|
|
Loading…
Reference in a new issue