Skip to content

Commit

Permalink
feat(Linear Node): Add Linear Node (#2971)
Browse files Browse the repository at this point in the history
* ✨ Linear node

* ⚡ Improvements
  • Loading branch information
RicardoE105 authored Mar 20, 2022
1 parent 1a7f0a4 commit 8d04474
Show file tree
Hide file tree
Showing 6 changed files with 864 additions and 4 deletions.
62 changes: 58 additions & 4 deletions packages/nodes-base/nodes/Linear/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ import {
} from 'n8n-core';

import {
ICredentialDataDecryptedObject,
ICredentialTestFunctions,
IDataObject,
IHookFunctions,
IWebhookFunctions,
JsonObject,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';

import get = require('lodash.get');

import {
query,
} from './Queries';

export async function linearApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, body: any = {}, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const credentials = await this.getCredentials('linearApi') as IDataObject;

Expand All @@ -32,14 +40,60 @@ export async function linearApiRequest(this: IExecuteFunctions | IWebhookFunctio
};
options = Object.assign({}, options, option);
try {

return await this.helpers.request!(options);

} catch (error) {
throw new NodeApiError(this.getNode(), error);
throw new NodeApiError(this.getNode(), error as JsonObject);
}
}

export function capitalizeFirstLetter(data: string) {
return data.charAt(0).toUpperCase() + data.slice(1);
}
}

export async function linearApiRequestAllItems(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, propertyName: string, body: any = {}): Promise<any> { // tslint:disable-line:no-any

const returnData: IDataObject[] = [];

let responseData;
body.variables.first = 50;
body.variables.after = null;

do {
responseData = await linearApiRequest.call(this, body);
returnData.push.apply(returnData, get(responseData, `${propertyName}.nodes`));
body.variables.after = get(responseData, `${propertyName}.pageInfo.endCursor`);
} while (
get(responseData, `${propertyName}.pageInfo.hasNextPage`)
);
return returnData;
}

export async function validateCrendetials(this: ICredentialTestFunctions, decryptedCredentials: ICredentialDataDecryptedObject): Promise<any> { // tslint:disable-line:no-any
const credentials = decryptedCredentials;

const options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
Authorization: credentials.apiKey,
},
method: 'POST',
body: {
query: query.getIssues(),
variables: {
first: 1,
},
},
uri: 'https://api.linear.app/graphql',
json: true,
};

return this.helpers.request!(options);
}

//@ts-ignore
export const sort = (a, b) => {
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) { return -1; }
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) { return 1; }
return 0;
};
Loading

0 comments on commit 8d04474

Please sign in to comment.