mirror of
https://github.com/n8n-io/n8n-nodes-starter.git
synced 2025-10-27 21:52:26 -05:00
32 lines
849 B
TypeScript
32 lines
849 B
TypeScript
import type {
|
|
IHookFunctions,
|
|
IExecuteFunctions,
|
|
IExecuteSingleFunctions,
|
|
ILoadOptionsFunctions,
|
|
IHttpRequestMethods,
|
|
IDataObject,
|
|
IHttpRequestOptions,
|
|
} from 'n8n-workflow';
|
|
|
|
export async function githubApiRequest(
|
|
this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
|
method: IHttpRequestMethods,
|
|
resource: string,
|
|
qs: IDataObject = {},
|
|
body: IDataObject | undefined = undefined,
|
|
) {
|
|
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
|
|
|
const options: IHttpRequestOptions = {
|
|
method: method,
|
|
qs,
|
|
body,
|
|
url: `https://api.github.com${resource}`,
|
|
json: true,
|
|
};
|
|
|
|
const credentialType =
|
|
authenticationMethod === 'accessToken' ? 'githubIssuesApi' : 'githubIssuesOAuth2Api';
|
|
|
|
return this.helpers.httpRequestWithAuthentication.call(this, credentialType, options);
|
|
}
|