Support for Jira server

This commit is contained in:
Ricardo Espinoza
2020-02-01 18:15:56 -05:00
parent c06934d973
commit 94b13ddea2
7 changed files with 73 additions and 594 deletions

View File

@@ -17,37 +17,7 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const data = Buffer.from(`${credentials!.email}:${credentials!.apiToken}`).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;
}
}
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 data = Buffer.from(`${credentials!.email}:${(credentials.jiraVersion === 'server') ? credentials.password : credentials.apiKey }`).toString(BINARY_ENCODING);
const headerWithAuthentication = Object.assign({},
{ Authorization: `Basic ${data}`, Accept: 'application/json', 'Content-Type': 'application/json' });
const options: OptionsWithUri = {
@@ -95,29 +65,6 @@ 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;
try {