Jira Software Server node

This commit is contained in:
Ricardo Espinoza
2020-01-31 10:21:14 -05:00
parent 56c8d4688f
commit c06934d973
4 changed files with 579 additions and 4 deletions

View File

@@ -42,12 +42,36 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut
}
}
export async function jiraSoftwareServerApiRequest(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('jiraSoftwareServerApi');
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const data = Buffer.from(`${credentials!.username}:${credentials!.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}`,
body,
json: true
};
try {
return await this.helpers.request!(options);
} catch (error) {
const errorMessage =
error.response.body.message || error.response.body.Message;
if (errorMessage !== undefined) {
throw errorMessage;
}
throw error.response.body;
}
}
/**
* Make an API request to paginated intercom endpoint
* and return all results
*/
export async function jiraSoftwareCloudApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = [];
@@ -71,6 +95,28 @@ export async function jiraSoftwareCloudApiRequestAllItems(this: IHookFunctions |
return returnData;
}
export async function jiraSoftwareServerApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = [];
let responseData;
query.maxResults = 100;
let uri: string | undefined;
do {
responseData = await jiraSoftwareCloudApiRequest.call(this, endpoint, method, body, query, uri);
uri = responseData.nextPage;
returnData.push.apply(returnData, responseData[propertyName]);
} while (
responseData.isLast !== false &&
responseData.nextPage !== undefined &&
responseData.nextPage !== null
);
return returnData;
}
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
let result;