fix: replace use of any type (#1251)
This commit is contained in:
parent
171dd555b9
commit
3f9dbd5a76
29
dist/index.js
vendored
29
dist/index.js
vendored
|
@ -452,7 +452,7 @@ function createPullRequest(inputs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(utils.getErrorMessage(error));
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
// Remove auth and restore persisted auth config if it existed
|
// Remove auth and restore persisted auth config if it existed
|
||||||
|
@ -507,6 +507,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
const url_1 = __nccwpck_require__(7310);
|
const url_1 = __nccwpck_require__(7310);
|
||||||
|
const utils = __importStar(__nccwpck_require__(918));
|
||||||
class GitAuthHelper {
|
class GitAuthHelper {
|
||||||
constructor(git) {
|
constructor(git) {
|
||||||
this.extraheaderConfigPlaceholderValue = 'AUTHORIZATION: basic ***';
|
this.extraheaderConfigPlaceholderValue = 'AUTHORIZATION: basic ***';
|
||||||
|
@ -531,7 +532,7 @@ class GitAuthHelper {
|
||||||
core.info('Persisted git credentials restored');
|
core.info('Persisted git credentials restored');
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
core.warning(e);
|
core.warning(utils.getErrorMessage(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -942,6 +943,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.GitHubHelper = void 0;
|
exports.GitHubHelper = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const octokit_client_1 = __nccwpck_require__(5040);
|
const octokit_client_1 = __nccwpck_require__(5040);
|
||||||
|
const utils = __importStar(__nccwpck_require__(918));
|
||||||
const ERROR_PR_REVIEW_FROM_AUTHOR = 'Review cannot be requested from pull request author';
|
const ERROR_PR_REVIEW_FROM_AUTHOR = 'Review cannot be requested from pull request author';
|
||||||
class GitHubHelper {
|
class GitHubHelper {
|
||||||
constructor(token) {
|
constructor(token) {
|
||||||
|
@ -976,8 +978,7 @@ class GitHubHelper {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (e.message &&
|
if (utils.getErrorMessage(e).includes(`A pull request already exists for`)) {
|
||||||
e.message.includes(`A pull request already exists for`)) {
|
|
||||||
core.info(`A pull request already exists for ${headBranch}`);
|
core.info(`A pull request already exists for ${headBranch}`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1040,7 +1041,7 @@ class GitHubHelper {
|
||||||
yield this.octokit.rest.pulls.requestReviewers(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pull.number }), requestReviewersParams));
|
yield this.octokit.rest.pulls.requestReviewers(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pull.number }), requestReviewersParams));
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (e.message && e.message.includes(ERROR_PR_REVIEW_FROM_AUTHOR)) {
|
if (utils.getErrorMessage(e).includes(ERROR_PR_REVIEW_FROM_AUTHOR)) {
|
||||||
core.warning(ERROR_PR_REVIEW_FROM_AUTHOR);
|
core.warning(ERROR_PR_REVIEW_FROM_AUTHOR);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1124,7 +1125,7 @@ function run() {
|
||||||
yield (0, create_pull_request_1.createPullRequest)(inputs);
|
yield (0, create_pull_request_1.createPullRequest)(inputs);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(utils.getErrorMessage(error));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1192,7 +1193,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.fileExistsSync = exports.parseDisplayNameEmail = exports.randomString = exports.secondsSinceEpoch = exports.getRemoteUrl = exports.getRemoteDetail = exports.getRepoPath = exports.getStringAsArray = exports.getInputAsArray = void 0;
|
exports.getErrorMessage = exports.fileExistsSync = exports.parseDisplayNameEmail = exports.randomString = exports.secondsSinceEpoch = exports.getRemoteUrl = exports.getRemoteDetail = exports.getRepoPath = exports.getStringAsArray = exports.getInputAsArray = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
|
@ -1293,10 +1294,10 @@ function fileExistsSync(path) {
|
||||||
stats = fs.statSync(path);
|
stats = fs.statSync(path);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
if (error.code === 'ENOENT') {
|
if (hasErrorCode(error) && error.code === 'ENOENT') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw new Error(`Encountered an error when checking whether path '${path}' exists: ${error.message}`);
|
throw new Error(`Encountered an error when checking whether path '${path}' exists: ${getErrorMessage(error)}`);
|
||||||
}
|
}
|
||||||
if (!stats.isDirectory()) {
|
if (!stats.isDirectory()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1304,6 +1305,16 @@ function fileExistsSync(path) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
exports.fileExistsSync = fileExistsSync;
|
exports.fileExistsSync = fileExistsSync;
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
function hasErrorCode(error) {
|
||||||
|
return typeof (error && error.code) === 'string';
|
||||||
|
}
|
||||||
|
function getErrorMessage(error) {
|
||||||
|
if (error instanceof Error)
|
||||||
|
return error.message;
|
||||||
|
return String(error);
|
||||||
|
}
|
||||||
|
exports.getErrorMessage = getErrorMessage;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
|
@ -243,8 +243,8 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
core.setFailed(error.message)
|
core.setFailed(utils.getErrorMessage(error))
|
||||||
} finally {
|
} finally {
|
||||||
// Remove auth and restore persisted auth config if it existed
|
// Remove auth and restore persisted auth config if it existed
|
||||||
core.startGroup('Restore persisted git credentials')
|
core.startGroup('Restore persisted git credentials')
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as fs from 'fs'
|
||||||
import {GitCommandManager} from './git-command-manager'
|
import {GitCommandManager} from './git-command-manager'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {URL} from 'url'
|
import {URL} from 'url'
|
||||||
|
import * as utils from './utils'
|
||||||
|
|
||||||
export class GitAuthHelper {
|
export class GitAuthHelper {
|
||||||
private git: GitCommandManager
|
private git: GitCommandManager
|
||||||
|
@ -33,8 +34,8 @@ export class GitAuthHelper {
|
||||||
try {
|
try {
|
||||||
await this.setExtraheaderConfig(this.persistedExtraheaderConfigValue)
|
await this.setExtraheaderConfig(this.persistedExtraheaderConfigValue)
|
||||||
core.info('Persisted git credentials restored')
|
core.info('Persisted git credentials restored')
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
core.warning(e)
|
core.warning(utils.getErrorMessage(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {Inputs} from './create-pull-request'
|
import {Inputs} from './create-pull-request'
|
||||||
import {Octokit, OctokitOptions} from './octokit-client'
|
import {Octokit, OctokitOptions} from './octokit-client'
|
||||||
|
import * as utils from './utils'
|
||||||
|
|
||||||
const ERROR_PR_REVIEW_FROM_AUTHOR =
|
const ERROR_PR_REVIEW_FROM_AUTHOR =
|
||||||
'Review cannot be requested from pull request author'
|
'Review cannot be requested from pull request author'
|
||||||
|
@ -64,10 +65,9 @@ export class GitHubHelper {
|
||||||
html_url: pull.html_url,
|
html_url: pull.html_url,
|
||||||
created: true
|
created: true
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
if (
|
if (
|
||||||
e.message &&
|
utils.getErrorMessage(e).includes(`A pull request already exists for`)
|
||||||
e.message.includes(`A pull request already exists for`)
|
|
||||||
) {
|
) {
|
||||||
core.info(`A pull request already exists for ${headBranch}`)
|
core.info(`A pull request already exists for ${headBranch}`)
|
||||||
} else {
|
} else {
|
||||||
|
@ -169,8 +169,8 @@ export class GitHubHelper {
|
||||||
pull_number: pull.number,
|
pull_number: pull.number,
|
||||||
...requestReviewersParams
|
...requestReviewersParams
|
||||||
})
|
})
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
if (e.message && e.message.includes(ERROR_PR_REVIEW_FROM_AUTHOR)) {
|
if (utils.getErrorMessage(e).includes(ERROR_PR_REVIEW_FROM_AUTHOR)) {
|
||||||
core.warning(ERROR_PR_REVIEW_FROM_AUTHOR)
|
core.warning(ERROR_PR_REVIEW_FROM_AUTHOR)
|
||||||
} else {
|
} else {
|
||||||
throw e
|
throw e
|
||||||
|
|
|
@ -30,8 +30,8 @@ async function run(): Promise<void> {
|
||||||
core.debug(`Inputs: ${inspect(inputs)}`)
|
core.debug(`Inputs: ${inspect(inputs)}`)
|
||||||
|
|
||||||
await createPullRequest(inputs)
|
await createPullRequest(inputs)
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
core.setFailed(error.message)
|
core.setFailed(utils.getErrorMessage(error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/utils.ts
18
src/utils.ts
|
@ -134,13 +134,15 @@ export function fileExistsSync(path: string): boolean {
|
||||||
let stats: fs.Stats
|
let stats: fs.Stats
|
||||||
try {
|
try {
|
||||||
stats = fs.statSync(path)
|
stats = fs.statSync(path)
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
if (error.code === 'ENOENT') {
|
if (hasErrorCode(error) && error.code === 'ENOENT') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Encountered an error when checking whether path '${path}' exists: ${error.message}`
|
`Encountered an error when checking whether path '${path}' exists: ${getErrorMessage(
|
||||||
|
error
|
||||||
|
)}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,3 +152,13 @@ export function fileExistsSync(path: string): boolean {
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
function hasErrorCode(error: any): error is {code: string} {
|
||||||
|
return typeof (error && error.code) === 'string'
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getErrorMessage(error: unknown) {
|
||||||
|
if (error instanceof Error) return error.message
|
||||||
|
return String(error)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue