mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-16 01:26:24 +00:00
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
const is = require('@sindresorhus/is');
|
|
const minimatch = require('minimatch');
|
|
|
|
module.exports = {
|
|
commitFilesToBranch,
|
|
};
|
|
|
|
async function commitFilesToBranch(config) {
|
|
let updatedFiles = config.updatedPackageFiles.concat(config.updatedArtifacts);
|
|
// istanbul ignore if
|
|
if (is.nonEmptyArray(config.excludeCommitPaths)) {
|
|
updatedFiles = updatedFiles.filter(f => {
|
|
const filename = f.name === '|delete|' ? f.contents : f.name;
|
|
const matchesExcludePaths = config.excludeCommitPaths.some(path =>
|
|
minimatch(filename, path, { dot: true })
|
|
);
|
|
if (matchesExcludePaths) {
|
|
logger.debug(`Excluding ${filename} from commit`);
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
if (is.nonEmptyArray(updatedFiles)) {
|
|
logger.debug(`${updatedFiles.length} file(s) to commit`);
|
|
|
|
// istanbul ignore if
|
|
if (config.dryRun) {
|
|
logger.info('DRY-RUN: Would commit files to branch ' + config.branchName);
|
|
} else {
|
|
// API will know whether to create new branch or not
|
|
const res = await platform.commitFilesToBranch(
|
|
config.branchName,
|
|
updatedFiles,
|
|
config.commitMessage,
|
|
config.baseBranch || undefined
|
|
);
|
|
if (res) {
|
|
logger.info({ branch: config.branchName }, `Branch ${res}`);
|
|
}
|
|
}
|
|
} else {
|
|
logger.debug(`No files to commit`);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|