mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ fixes
This commit is contained in:
@@ -13,18 +13,27 @@ import {
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('jiraSoftwareCloudApi');
|
||||
if (credentials === undefined) {
|
||||
let data; let domain;
|
||||
const jiraCloudCredentials = this.getCredentials('jiraSoftwareCloudApi');
|
||||
const jiraServerCredentials = this.getCredentials('jiraSoftwareServerApi');
|
||||
if (jiraCloudCredentials === undefined
|
||||
&& jiraServerCredentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
const data = Buffer.from(`${credentials!.email}:${(credentials.jiraVersion === 'server') ? credentials.password : credentials.apiToken }`).toString(BINARY_ENCODING);
|
||||
if (jiraCloudCredentials !== undefined) {
|
||||
domain = jiraCloudCredentials!.domain;
|
||||
data = Buffer.from(`${jiraCloudCredentials!.email}:${jiraCloudCredentials!.apiToken}`).toString(BINARY_ENCODING);
|
||||
} else {
|
||||
domain = jiraServerCredentials!.domain;
|
||||
data = Buffer.from(`${jiraServerCredentials!.email}:${jiraServerCredentials!.password}`).toString(BINARY_ENCODING);
|
||||
}
|
||||
const headerWithAuthentication = Object.assign({},
|
||||
{ Authorization: `Basic ${data}`, Accept: 'application/json', 'Content-Type': 'application/json' });
|
||||
const options: OptionsWithUri = {
|
||||
headers: headerWithAuthentication,
|
||||
method,
|
||||
qs: query,
|
||||
uri: uri || `${credentials.domain}/rest/api/2${endpoint}`,
|
||||
uri: uri || `${domain}/rest/api/2${endpoint}`,
|
||||
body,
|
||||
json: true
|
||||
};
|
||||
@@ -32,13 +41,11 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
error.response.body.message || error.response.body.Message;
|
||||
|
||||
if (errorMessage !== undefined) {
|
||||
throw errorMessage;
|
||||
let errorMessage = error;
|
||||
if (error.error && error.error.errorMessages) {
|
||||
errorMessage = error.error.errorMessages;
|
||||
}
|
||||
throw error.response.body;
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,18 +55,18 @@ export async function jiraSoftwareCloudApiRequestAllItems(this: IHookFunctions |
|
||||
|
||||
let responseData;
|
||||
|
||||
query.startAt = 0;
|
||||
body.startAt = 0;
|
||||
query.maxResults = 100;
|
||||
|
||||
let uri: string | undefined;
|
||||
body.maxResults = 100;
|
||||
|
||||
do {
|
||||
responseData = await jiraSoftwareCloudApiRequest.call(this, endpoint, method, body, query, uri);
|
||||
uri = responseData.nextPage;
|
||||
responseData = await jiraSoftwareCloudApiRequest.call(this, endpoint, method, body, query);
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
query.startAt = responseData.startAt + responseData.maxResults;
|
||||
body.startAt = responseData.startAt + responseData.maxResults;
|
||||
} while (
|
||||
responseData.isLast !== false &&
|
||||
responseData.nextPage !== undefined &&
|
||||
responseData.nextPage !== null
|
||||
(responseData.startAt + responseData.maxResults < responseData.total)
|
||||
);
|
||||
|
||||
return returnData;
|
||||
|
||||
Reference in New Issue
Block a user