Set timeout for scaffolder octokit client
If a client fails to contact github (or the network connectivity is bad), there is no reasonible timeout for the Octokit client. This change here adds a default timeout of 60 seconds Here is a link to the octokit type definition: https://github.com/octokit/types.ts/blob/master/src/RequestRequestOptions.ts Signed-off-by: Nicolas Arnold <nic@roadie.io>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Set timeout for scaffolder octokit client
|
||||
@@ -22,6 +22,8 @@ import {
|
||||
import { OctokitOptions } from '@octokit/core/dist-types/types';
|
||||
import { parseRepoUrl } from '../publish/util';
|
||||
|
||||
const SECOND = 1000;
|
||||
|
||||
export async function getOctokitOptions(options: {
|
||||
integrations: ScmIntegrationRegistry;
|
||||
credentialsProvider?: GithubCredentialsProvider;
|
||||
@@ -30,6 +32,10 @@ export async function getOctokitOptions(options: {
|
||||
}): Promise<OctokitOptions> {
|
||||
const { integrations, credentialsProvider, repoUrl, token } = options;
|
||||
const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);
|
||||
const requestOptions = {
|
||||
// set timeout to 60 seconds
|
||||
timeout: 60 * SECOND,
|
||||
};
|
||||
|
||||
if (!owner) {
|
||||
throw new InputError(`No owner provided for repo ${repoUrl}`);
|
||||
@@ -47,6 +53,7 @@ export async function getOctokitOptions(options: {
|
||||
auth: token,
|
||||
baseUrl: integrationConfig.apiBaseUrl,
|
||||
previews: ['nebula-preview'],
|
||||
request: requestOptions,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user