@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
87 lines (86 loc) • 5.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const log_1 = require("diginext-utils/dist/xconsole/log");
async function updateBranchProtection(options) {
//
// https://api.github.com/repos/OWNER/REPO/branches/BRANCH/protection \
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
// console.log("options :>> ", options);
// console.log("options.git :>> ", options.git);
// console.log("options.git?.type :>> ", options.git?.type);
const type = ((_a = options.git) === null || _a === void 0 ? void 0 : _a.type) || options.app.git.provider;
switch (type) {
case "github":
{
const token = (_b = options.git) === null || _b === void 0 ? void 0 : _b.access_token;
const owner = (_c = options.git) === null || _c === void 0 ? void 0 : _c.org;
const repo = options.repoSlug;
const branch = options.defaultBranch || "main";
try {
const res = await (0, axios_1.default)({
method: "put",
url: `https://api.github.com/repos/${owner}/${repo}/branches/${branch}/protection`,
headers: {
Accept: "application/vnd.github+json",
Authorization: `token ${token}`,
//
},
data: {
required_status_checks: null,
enforce_admins: null,
required_pull_request_reviews: {
dismiss_stale_reviews: false,
require_code_owner_reviews: false,
required_approving_review_count: 0,
require_last_push_approval: null,
},
restrictions: null,
required_linear_history: false,
allow_force_pushes: true,
allow_deletions: null,
block_creations: null,
required_conversation_resolution: null,
lock_branch: null,
allow_fork_syncing: true,
},
});
// if (options.isDebugging) log("res Update main branch protection :>> ", res?.statusText);
if (options.isDebugging)
console.log("Update main branch protection :>> ", res === null || res === void 0 ? void 0 : res.statusText);
}
catch (error) {
if (error === null || error === void 0 ? void 0 : error.response) {
// The request was made and the server responded with a status code outside of the 2xx range
if ((_e = (_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.message)
(0, log_1.logWarn)((_g = (_f = error === null || error === void 0 ? void 0 : error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.message);
if (options.isDebugging) {
console.log("[PROTECT_GIT_BRANCH] URL:>> ", `https://api.github.com/repos/${owner}/${repo}/branches/${branch}/protection`);
console.log("[PROTECT_GIT_BRANCH] ==> error?.response?.data\n", (_h = error === null || error === void 0 ? void 0 : error.response) === null || _h === void 0 ? void 0 : _h.data);
console.log("[PROTECT_GIT_BRANCH] ==> error?.response?.status\n", (_j = error === null || error === void 0 ? void 0 : error.response) === null || _j === void 0 ? void 0 : _j.status);
console.log("[PROTECT_GIT_BRANCH] ==> error?.response?.headers\n", (_k = error === null || error === void 0 ? void 0 : error.response) === null || _k === void 0 ? void 0 : _k.headers);
}
}
else if (error === null || error === void 0 ? void 0 : error.request) {
// The request was made but no response was received
if (options.isDebugging)
console.log("[PROTECT_GIT_BRANCH] Error:\n", error === null || error === void 0 ? void 0 : error.request);
}
else {
// Something happened in setting up the request that triggered an Error
if (options.isDebugging)
console.log("[PROTECT_GIT_BRANCH] Error:\n", error === null || error === void 0 ? void 0 : error.message);
}
}
}
break;
case "bitbucket":
break;
default:
break;
}
}
exports.default = updateBranchProtection;