diff --git a/.editorconfig b/.editorconfig index 9cd2488..bcf20c1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,5 +11,8 @@ trim_trailing_whitespace = true [*.yml] indent_size = 2 +[*.ts] +indent_size = 2 + [package.json] indent_size = 2 diff --git a/dist/index.js b/dist/index.js index e7984eb..029800a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5053,10 +5053,11 @@ class GithubManager { return true; } catch (error) { - if (error.name === 'HttpError' && error.status === 404) { + const err = error; + if (err.name === 'HttpError' && err.status === 404) { return false; } - throw new Error(`Failed to check if branch ${branch} exist; ${util_1.inspect(error)}`); + throw new Error(`Failed to check if branch ${branch} exist; ${util_1.inspect(err)}`); } }) }; @@ -5075,11 +5076,12 @@ class GithubManager { }); } catch (error) { - core.debug(util_1.inspect(error)); - if (!!error.errors && - (error.errors[0].message.include('No commits between') || - error.errors[0].message.include('A pull request already exists for'))) { - core.info(error.errors[0].message); + const err = error; + core.debug(util_1.inspect(err)); + if (err.name === 'HttpError' && + (err.message.includes('No commits between') || + err.message.includes('A pull request already exists for'))) { + core.info(err.message); process.exit(0); // there is currently no neutral exit code } else { diff --git a/src/github-manager.ts b/src/github-manager.ts index e4fe79f..380e841 100644 --- a/src/github-manager.ts +++ b/src/github-manager.ts @@ -11,7 +11,8 @@ import { IGithubManager, IGithubManagerBranch, IGithubManagerPulls, - IGithubManagerRepos + IGithubManagerRepos, + OctokitHttpError } from './interfaces' const IS_WINDOWS = process.platform === 'win32' @@ -82,12 +83,14 @@ export class GithubManager implements IGithubManager { return true } catch (error) { - if (error.name === 'HttpError' && error.status === 404) { + const err: OctokitHttpError = error + + if (err.name === 'HttpError' && err.status === 404) { return false } throw new Error( - `Failed to check if branch ${branch} exist; ${inspect(error)}` + `Failed to check if branch ${branch} exist; ${inspect(err)}` ) } } @@ -114,16 +117,16 @@ export class GithubManager implements IGithubManager { body }) } catch (error) { - core.debug(inspect(error)) + const err: OctokitHttpError = error + + core.debug(inspect(err)) if ( - !!error.errors && - (error.errors[0].message.include('No commits between') || - error.errors[0].message.include( - 'A pull request already exists for' - )) + err.name === 'HttpError' && + (err.message.includes('No commits between') || + err.message.includes('A pull request already exists for')) ) { - core.info(error.errors[0].message) + core.info(err.message) process.exit(0) // there is currently no neutral exit code } else { diff --git a/src/interfaces.ts b/src/interfaces.ts index 55c9528..d083c22 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,4 +1,5 @@ import {URL} from 'url' +import {RequestOptions, ResponseHeaders} from '@octokit/types' export interface IPayloadRepository { full_name?: string @@ -211,3 +212,25 @@ export interface ISettings { clean: boolean } + +export interface OctokitHttpError extends Error { + name: string + /** + * http status code + */ + status: number + /** + * http status code + * + * @deprecated `error.code` is deprecated in favor of `error.status` + */ + code: number + /** + * error response headers + */ + headers: ResponseHeaders + /** + * Request options that lead to the error. + */ + request: RequestOptions +}