chore: refactor function (#1572)
Co-authored-by: GitHub Action <action@github.com> Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
parent
662c03ea61
commit
d8904df6c5
107
dist/index.js
generated
vendored
107
dist/index.js
generated
vendored
@ -49,13 +49,62 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getChangedFilesFromGithubAPI = exports.getAllChangeTypeFiles = exports.getChangeTypeFiles = exports.getAllDiffFiles = exports.ChangeTypeEnum = exports.getRenamedFiles = void 0;
|
||||
exports.getChangedFilesFromGithubAPI = exports.getAllChangeTypeFiles = exports.getChangeTypeFiles = exports.getAllDiffFiles = exports.ChangeTypeEnum = exports.getRenamedFiles = exports.processChangedFiles = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const flatten_1 = __importDefault(__nccwpck_require__(2394));
|
||||
const micromatch_1 = __importDefault(__nccwpck_require__(6228));
|
||||
const path = __importStar(__nccwpck_require__(1017));
|
||||
const changedFilesOutput_1 = __nccwpck_require__(8930);
|
||||
const utils_1 = __nccwpck_require__(918);
|
||||
const processChangedFiles = ({ filePatterns, allDiffFiles, inputs, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
if (filePatterns.length > 0) {
|
||||
core.startGroup('changed-files-patterns');
|
||||
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
|
||||
allDiffFiles,
|
||||
filePatterns
|
||||
});
|
||||
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`);
|
||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns
|
||||
});
|
||||
core.info('All Done!');
|
||||
core.endGroup();
|
||||
}
|
||||
if (Object.keys(yamlFilePatterns).length > 0) {
|
||||
for (const key of Object.keys(yamlFilePatterns)) {
|
||||
core.startGroup(`changed-files-yaml-${key}`);
|
||||
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
|
||||
allDiffFiles,
|
||||
filePatterns: yamlFilePatterns[key]
|
||||
});
|
||||
core.debug(`All filtered diff files for ${key}: ${JSON.stringify(allFilteredDiffFiles)}`);
|
||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns: yamlFilePatterns[key],
|
||||
outputPrefix: key
|
||||
});
|
||||
core.info('All Done!');
|
||||
core.endGroup();
|
||||
}
|
||||
}
|
||||
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
|
||||
core.startGroup('changed-files-all');
|
||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles: allDiffFiles,
|
||||
inputs
|
||||
});
|
||||
core.info('All Done!');
|
||||
core.endGroup();
|
||||
}
|
||||
});
|
||||
exports.processChangedFiles = processChangedFiles;
|
||||
const getRenamedFiles = ({ inputs, workingDirectory, hasSubmodule, diffResult, submodulePaths }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const renamedFiles = yield (0, utils_1.gitRenamedFiles)({
|
||||
cwd: workingDirectory,
|
||||
@ -1541,59 +1590,11 @@ const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||
const changedFiles_1 = __nccwpck_require__(7358);
|
||||
const changedFilesOutput_1 = __nccwpck_require__(8930);
|
||||
const commitSha_1 = __nccwpck_require__(8613);
|
||||
const env_1 = __nccwpck_require__(9763);
|
||||
const inputs_1 = __nccwpck_require__(6180);
|
||||
const utils_1 = __nccwpck_require__(918);
|
||||
const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
if (filePatterns.length > 0) {
|
||||
core.startGroup('changed-files-patterns');
|
||||
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
|
||||
allDiffFiles,
|
||||
filePatterns
|
||||
});
|
||||
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`);
|
||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns
|
||||
});
|
||||
core.info('All Done!');
|
||||
core.endGroup();
|
||||
}
|
||||
if (Object.keys(yamlFilePatterns).length > 0) {
|
||||
for (const key of Object.keys(yamlFilePatterns)) {
|
||||
core.startGroup(`changed-files-yaml-${key}`);
|
||||
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
|
||||
allDiffFiles,
|
||||
filePatterns: yamlFilePatterns[key]
|
||||
});
|
||||
core.debug(`All filtered diff files for ${key}: ${JSON.stringify(allFilteredDiffFiles)}`);
|
||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns: yamlFilePatterns[key],
|
||||
outputPrefix: key
|
||||
});
|
||||
core.info('All Done!');
|
||||
core.endGroup();
|
||||
}
|
||||
}
|
||||
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
|
||||
core.startGroup('changed-files-all');
|
||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles: allDiffFiles,
|
||||
inputs
|
||||
});
|
||||
core.info('All Done!');
|
||||
core.endGroup();
|
||||
}
|
||||
});
|
||||
const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const getChangedFilesFromLocalGitHistory = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a, _b, _c;
|
||||
yield (0, utils_1.verifyMinimumGitVersion)();
|
||||
let quotePathValue = 'on';
|
||||
@ -1664,7 +1665,7 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
|
||||
sha: diffResult.previousSha
|
||||
});
|
||||
}
|
||||
yield changedFilesOutput({
|
||||
yield (0, changedFiles_1.processChangedFiles)({
|
||||
filePatterns,
|
||||
allDiffFiles,
|
||||
inputs,
|
||||
@ -1704,7 +1705,7 @@ const getChangedFilesFromRESTAPI = ({ inputs, filePatterns, yamlFilePatterns })
|
||||
});
|
||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
|
||||
core.info('All Done!');
|
||||
yield changedFilesOutput({
|
||||
yield (0, changedFiles_1.processChangedFiles)({
|
||||
filePatterns,
|
||||
allDiffFiles,
|
||||
inputs,
|
||||
@ -1769,7 +1770,7 @@ function run() {
|
||||
return;
|
||||
}
|
||||
core.info('Using local .git directory');
|
||||
yield getChangedFilesFromLocalGit({
|
||||
yield getChangedFilesFromLocalGitHistory({
|
||||
inputs,
|
||||
env,
|
||||
workingDirectory,
|
||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -4,6 +4,7 @@ import type {RestEndpointMethodTypes} from '@octokit/rest'
|
||||
import flatten from 'lodash/flatten'
|
||||
import mm from 'micromatch'
|
||||
import * as path from 'path'
|
||||
import {setChangedFilesOutput} from './changedFilesOutput'
|
||||
|
||||
import {DiffResult} from './commitSha'
|
||||
import {Inputs} from './inputs'
|
||||
@ -12,12 +13,79 @@ import {
|
||||
getAllChangedFiles,
|
||||
getDirnameMaxDepth,
|
||||
getDirNamesIncludeFilesPattern,
|
||||
getFilteredChangedFiles,
|
||||
gitRenamedFiles,
|
||||
gitSubmoduleDiffSHA,
|
||||
isWindows,
|
||||
jsonOutput
|
||||
} from './utils'
|
||||
|
||||
export const processChangedFiles = async ({
|
||||
filePatterns,
|
||||
allDiffFiles,
|
||||
inputs,
|
||||
yamlFilePatterns
|
||||
}: {
|
||||
filePatterns: string[]
|
||||
allDiffFiles: ChangedFiles
|
||||
inputs: Inputs
|
||||
yamlFilePatterns: Record<string, string[]>
|
||||
}): Promise<void> => {
|
||||
if (filePatterns.length > 0) {
|
||||
core.startGroup('changed-files-patterns')
|
||||
const allFilteredDiffFiles = await getFilteredChangedFiles({
|
||||
allDiffFiles,
|
||||
filePatterns
|
||||
})
|
||||
core.debug(
|
||||
`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`
|
||||
)
|
||||
await setChangedFilesOutput({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns
|
||||
})
|
||||
core.info('All Done!')
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
if (Object.keys(yamlFilePatterns).length > 0) {
|
||||
for (const key of Object.keys(yamlFilePatterns)) {
|
||||
core.startGroup(`changed-files-yaml-${key}`)
|
||||
const allFilteredDiffFiles = await getFilteredChangedFiles({
|
||||
allDiffFiles,
|
||||
filePatterns: yamlFilePatterns[key]
|
||||
})
|
||||
core.debug(
|
||||
`All filtered diff files for ${key}: ${JSON.stringify(
|
||||
allFilteredDiffFiles
|
||||
)}`
|
||||
)
|
||||
await setChangedFilesOutput({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns: yamlFilePatterns[key],
|
||||
outputPrefix: key
|
||||
})
|
||||
core.info('All Done!')
|
||||
core.endGroup()
|
||||
}
|
||||
}
|
||||
|
||||
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
|
||||
core.startGroup('changed-files-all')
|
||||
await setChangedFilesOutput({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles: allDiffFiles,
|
||||
inputs
|
||||
})
|
||||
core.info('All Done!')
|
||||
core.endGroup()
|
||||
}
|
||||
}
|
||||
|
||||
export const getRenamedFiles = async ({
|
||||
inputs,
|
||||
workingDirectory,
|
||||
|
78
src/main.ts
78
src/main.ts
@ -2,13 +2,12 @@ import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import path from 'path'
|
||||
import {
|
||||
ChangedFiles,
|
||||
processChangedFiles,
|
||||
ChangeTypeEnum,
|
||||
getAllDiffFiles,
|
||||
getChangedFilesFromGithubAPI,
|
||||
getRenamedFiles
|
||||
} from './changedFiles'
|
||||
import {setChangedFilesOutput} from './changedFilesOutput'
|
||||
import {
|
||||
DiffResult,
|
||||
getSHAForNonPullRequestEvent,
|
||||
@ -18,7 +17,6 @@ import {Env, getEnv} from './env'
|
||||
import {getInputs, Inputs} from './inputs'
|
||||
import {
|
||||
getFilePatterns,
|
||||
getFilteredChangedFiles,
|
||||
getRecoverFilePatterns,
|
||||
getSubmodulePath,
|
||||
getYamlFilePatterns,
|
||||
@ -31,73 +29,7 @@ import {
|
||||
verifyMinimumGitVersion
|
||||
} from './utils'
|
||||
|
||||
const changedFilesOutput = async ({
|
||||
filePatterns,
|
||||
allDiffFiles,
|
||||
inputs,
|
||||
yamlFilePatterns
|
||||
}: {
|
||||
filePatterns: string[]
|
||||
allDiffFiles: ChangedFiles
|
||||
inputs: Inputs
|
||||
yamlFilePatterns: Record<string, string[]>
|
||||
}): Promise<void> => {
|
||||
if (filePatterns.length > 0) {
|
||||
core.startGroup('changed-files-patterns')
|
||||
const allFilteredDiffFiles = await getFilteredChangedFiles({
|
||||
allDiffFiles,
|
||||
filePatterns
|
||||
})
|
||||
core.debug(
|
||||
`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`
|
||||
)
|
||||
await setChangedFilesOutput({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns
|
||||
})
|
||||
core.info('All Done!')
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
if (Object.keys(yamlFilePatterns).length > 0) {
|
||||
for (const key of Object.keys(yamlFilePatterns)) {
|
||||
core.startGroup(`changed-files-yaml-${key}`)
|
||||
const allFilteredDiffFiles = await getFilteredChangedFiles({
|
||||
allDiffFiles,
|
||||
filePatterns: yamlFilePatterns[key]
|
||||
})
|
||||
core.debug(
|
||||
`All filtered diff files for ${key}: ${JSON.stringify(
|
||||
allFilteredDiffFiles
|
||||
)}`
|
||||
)
|
||||
await setChangedFilesOutput({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles,
|
||||
inputs,
|
||||
filePatterns: yamlFilePatterns[key],
|
||||
outputPrefix: key
|
||||
})
|
||||
core.info('All Done!')
|
||||
core.endGroup()
|
||||
}
|
||||
}
|
||||
|
||||
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
|
||||
core.startGroup('changed-files-all')
|
||||
await setChangedFilesOutput({
|
||||
allDiffFiles,
|
||||
allFilteredDiffFiles: allDiffFiles,
|
||||
inputs
|
||||
})
|
||||
core.info('All Done!')
|
||||
core.endGroup()
|
||||
}
|
||||
}
|
||||
|
||||
const getChangedFilesFromLocalGit = async ({
|
||||
const getChangedFilesFromLocalGitHistory = async ({
|
||||
inputs,
|
||||
env,
|
||||
workingDirectory,
|
||||
@ -216,7 +148,7 @@ const getChangedFilesFromLocalGit = async ({
|
||||
})
|
||||
}
|
||||
|
||||
await changedFilesOutput({
|
||||
await processChangedFiles({
|
||||
filePatterns,
|
||||
allDiffFiles,
|
||||
inputs,
|
||||
@ -267,7 +199,7 @@ const getChangedFilesFromRESTAPI = async ({
|
||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
|
||||
core.info('All Done!')
|
||||
|
||||
await changedFilesOutput({
|
||||
await processChangedFiles({
|
||||
filePatterns,
|
||||
allDiffFiles,
|
||||
inputs,
|
||||
@ -349,7 +281,7 @@ export async function run(): Promise<void> {
|
||||
}
|
||||
|
||||
core.info('Using local .git directory')
|
||||
await getChangedFilesFromLocalGit({
|
||||
await getChangedFilesFromLocalGitHistory({
|
||||
inputs,
|
||||
env,
|
||||
workingDirectory,
|
||||
|
Loading…
x
Reference in New Issue
Block a user