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 };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
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 core = __importStar(__nccwpck_require__(2186));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const flatten_1 = __importDefault(__nccwpck_require__(2394));
|
const flatten_1 = __importDefault(__nccwpck_require__(2394));
|
||||||
const micromatch_1 = __importDefault(__nccwpck_require__(6228));
|
const micromatch_1 = __importDefault(__nccwpck_require__(6228));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
|
const changedFilesOutput_1 = __nccwpck_require__(8930);
|
||||||
const utils_1 = __nccwpck_require__(918);
|
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 getRenamedFiles = ({ inputs, workingDirectory, hasSubmodule, diffResult, submodulePaths }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const renamedFiles = yield (0, utils_1.gitRenamedFiles)({
|
const renamedFiles = yield (0, utils_1.gitRenamedFiles)({
|
||||||
cwd: workingDirectory,
|
cwd: workingDirectory,
|
||||||
@ -1541,59 +1590,11 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
const changedFiles_1 = __nccwpck_require__(7358);
|
const changedFiles_1 = __nccwpck_require__(7358);
|
||||||
const changedFilesOutput_1 = __nccwpck_require__(8930);
|
|
||||||
const commitSha_1 = __nccwpck_require__(8613);
|
const commitSha_1 = __nccwpck_require__(8613);
|
||||||
const env_1 = __nccwpck_require__(9763);
|
const env_1 = __nccwpck_require__(9763);
|
||||||
const inputs_1 = __nccwpck_require__(6180);
|
const inputs_1 = __nccwpck_require__(6180);
|
||||||
const utils_1 = __nccwpck_require__(918);
|
const utils_1 = __nccwpck_require__(918);
|
||||||
const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
const getChangedFilesFromLocalGitHistory = ({ inputs, env, workingDirectory, filePatterns, 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* () {
|
|
||||||
var _a, _b, _c;
|
var _a, _b, _c;
|
||||||
yield (0, utils_1.verifyMinimumGitVersion)();
|
yield (0, utils_1.verifyMinimumGitVersion)();
|
||||||
let quotePathValue = 'on';
|
let quotePathValue = 'on';
|
||||||
@ -1664,7 +1665,7 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
|
|||||||
sha: diffResult.previousSha
|
sha: diffResult.previousSha
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
yield changedFilesOutput({
|
yield (0, changedFiles_1.processChangedFiles)({
|
||||||
filePatterns,
|
filePatterns,
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
inputs,
|
inputs,
|
||||||
@ -1704,7 +1705,7 @@ const getChangedFilesFromRESTAPI = ({ inputs, filePatterns, yamlFilePatterns })
|
|||||||
});
|
});
|
||||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
|
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
|
||||||
core.info('All Done!');
|
core.info('All Done!');
|
||||||
yield changedFilesOutput({
|
yield (0, changedFiles_1.processChangedFiles)({
|
||||||
filePatterns,
|
filePatterns,
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
inputs,
|
inputs,
|
||||||
@ -1769,7 +1770,7 @@ function run() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.info('Using local .git directory');
|
core.info('Using local .git directory');
|
||||||
yield getChangedFilesFromLocalGit({
|
yield getChangedFilesFromLocalGitHistory({
|
||||||
inputs,
|
inputs,
|
||||||
env,
|
env,
|
||||||
workingDirectory,
|
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 flatten from 'lodash/flatten'
|
||||||
import mm from 'micromatch'
|
import mm from 'micromatch'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
import {setChangedFilesOutput} from './changedFilesOutput'
|
||||||
|
|
||||||
import {DiffResult} from './commitSha'
|
import {DiffResult} from './commitSha'
|
||||||
import {Inputs} from './inputs'
|
import {Inputs} from './inputs'
|
||||||
@ -12,12 +13,79 @@ import {
|
|||||||
getAllChangedFiles,
|
getAllChangedFiles,
|
||||||
getDirnameMaxDepth,
|
getDirnameMaxDepth,
|
||||||
getDirNamesIncludeFilesPattern,
|
getDirNamesIncludeFilesPattern,
|
||||||
|
getFilteredChangedFiles,
|
||||||
gitRenamedFiles,
|
gitRenamedFiles,
|
||||||
gitSubmoduleDiffSHA,
|
gitSubmoduleDiffSHA,
|
||||||
isWindows,
|
isWindows,
|
||||||
jsonOutput
|
jsonOutput
|
||||||
} from './utils'
|
} 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 ({
|
export const getRenamedFiles = async ({
|
||||||
inputs,
|
inputs,
|
||||||
workingDirectory,
|
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 * as github from '@actions/github'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import {
|
import {
|
||||||
ChangedFiles,
|
processChangedFiles,
|
||||||
ChangeTypeEnum,
|
ChangeTypeEnum,
|
||||||
getAllDiffFiles,
|
getAllDiffFiles,
|
||||||
getChangedFilesFromGithubAPI,
|
getChangedFilesFromGithubAPI,
|
||||||
getRenamedFiles
|
getRenamedFiles
|
||||||
} from './changedFiles'
|
} from './changedFiles'
|
||||||
import {setChangedFilesOutput} from './changedFilesOutput'
|
|
||||||
import {
|
import {
|
||||||
DiffResult,
|
DiffResult,
|
||||||
getSHAForNonPullRequestEvent,
|
getSHAForNonPullRequestEvent,
|
||||||
@ -18,7 +17,6 @@ import {Env, getEnv} from './env'
|
|||||||
import {getInputs, Inputs} from './inputs'
|
import {getInputs, Inputs} from './inputs'
|
||||||
import {
|
import {
|
||||||
getFilePatterns,
|
getFilePatterns,
|
||||||
getFilteredChangedFiles,
|
|
||||||
getRecoverFilePatterns,
|
getRecoverFilePatterns,
|
||||||
getSubmodulePath,
|
getSubmodulePath,
|
||||||
getYamlFilePatterns,
|
getYamlFilePatterns,
|
||||||
@ -31,73 +29,7 @@ import {
|
|||||||
verifyMinimumGitVersion
|
verifyMinimumGitVersion
|
||||||
} from './utils'
|
} from './utils'
|
||||||
|
|
||||||
const changedFilesOutput = async ({
|
const getChangedFilesFromLocalGitHistory = 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 ({
|
|
||||||
inputs,
|
inputs,
|
||||||
env,
|
env,
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
@ -216,7 +148,7 @@ const getChangedFilesFromLocalGit = async ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
await changedFilesOutput({
|
await processChangedFiles({
|
||||||
filePatterns,
|
filePatterns,
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
inputs,
|
inputs,
|
||||||
@ -267,7 +199,7 @@ const getChangedFilesFromRESTAPI = async ({
|
|||||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
|
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
|
||||||
core.info('All Done!')
|
core.info('All Done!')
|
||||||
|
|
||||||
await changedFilesOutput({
|
await processChangedFiles({
|
||||||
filePatterns,
|
filePatterns,
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
inputs,
|
inputs,
|
||||||
@ -349,7 +281,7 @@ export async function run(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.info('Using local .git directory')
|
core.info('Using local .git directory')
|
||||||
await getChangedFilesFromLocalGit({
|
await getChangedFilesFromLocalGitHistory({
|
||||||
inputs,
|
inputs,
|
||||||
env,
|
env,
|
||||||
workingDirectory,
|
workingDirectory,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user