Add GitHub PR reviews (#1346)

* Adds operations to get and create PR reviews

* Improvements to #709

*  Fix commit field description

Co-authored-by: Johannes Kettmann <jkettmann@gmx.net>
This commit is contained in:
Ricardo Espinoza
2021-01-20 02:33:17 -05:00
committed by GitHub
parent 28d54ed439
commit 3b49764fb8
5 changed files with 388 additions and 9 deletions

View File

@@ -18,7 +18,7 @@ import {
* @param {object} body
* @returns {Promise<any>}
*/
export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: object, query?: object): Promise<any> { // tslint:disable-line:no-any
export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: object, query?: object, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const options: OptionsWithUri = {
method,
@@ -31,6 +31,10 @@ export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions,
json: true,
};
if (Object.keys(option).length !== 0) {
Object.assign(options, option);
}
try {
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken') as string;
@@ -95,3 +99,22 @@ export async function getFileSha(this: IHookFunctions | IExecuteFunctions, owner
}
return responseData.sha;
}
export async function githubApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = [];
let responseData;
query.per_page = 100;
query.page = 1;
do {
responseData = await githubApiRequest.call(this, method, endpoint, body, query, { resolveWithFullResponse: true });
query.page++;
returnData.push.apply(returnData, responseData.body);
} while (
responseData.headers.link && responseData.headers.link.includes('next')
);
return returnData;
}