mirror of
https://github.com/semantic-release/semantic-release.git
synced 2026-10-25 15:39:35 +00:00
973d763c2e
Co-authored-by: alanturing881 <alanturing881@users.noreply.github.com>
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { escapeRegExp, isString, size } from "lodash-es";
|
|
import { SECRET_MIN_SIZE, SECRET_REPLACEMENT } from "./definitions/constants.js";
|
|
|
|
export default (env) => {
|
|
const toReplace = Object.keys(env).filter((envVar) => {
|
|
// https://github.com/semantic-release/semantic-release/issues/1558
|
|
if (envVar === "GOPRIVATE") {
|
|
return false;
|
|
}
|
|
|
|
return (
|
|
/token|password|credential|secret|private|key|auth|webhook/i.test(envVar) &&
|
|
size(env[envVar].trim()) >= SECRET_MIN_SIZE
|
|
);
|
|
});
|
|
|
|
const regexp = new RegExp(
|
|
toReplace
|
|
.flatMap((envVar) => {
|
|
const value = env[envVar];
|
|
const forms = new Set([
|
|
value,
|
|
encodeURI(value),
|
|
encodeURIComponent(value),
|
|
// The form emitted by `url.format()`, which `get-git-auth-url.js` uses to embed credentials
|
|
// in the repository URL: like `encodeURIComponent()`, but `:` separators are kept as is
|
|
value.split(":").map(encodeURIComponent).join(":"),
|
|
]);
|
|
return [...forms].map(escapeRegExp);
|
|
})
|
|
.join("|"),
|
|
"g"
|
|
);
|
|
return (output) =>
|
|
output && isString(output) && toReplace.length > 0 ? output.toString().replace(regexp, SECRET_REPLACEMENT) : output;
|
|
};
|