UNPKG

@topgroup/diginext

Version:

A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.

75 lines (74 loc) 4.52 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateRepoSetting = void 0; const axios_1 = __importDefault(require("axios")); const log_1 = require("diginext-utils/dist/xconsole/log"); async function updateRepoSetting(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; try { // repos/OWNER/REPO const res = await (0, axios_1.default)({ method: "PATCH", url: `https://api.github.com/repos/${owner}/${repo}`, headers: { "X-GitHub-Api-Version": "2022-11-28", Accept: "application/vnd.github+json", Authorization: `token ${token}`, // }, data: { allow_auto_merge: 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("[UPDATE_REPO_SETTING] URL:>> ", `https://api.github.com/repos/${owner}/${repo}`); console.log("[UPDATE_REPO_SETTING] ==> error?.response?.data\n", (_h = error === null || error === void 0 ? void 0 : error.response) === null || _h === void 0 ? void 0 : _h.data); console.log("[UPDATE_REPO_SETTING] ==> error?.response?.status\n", (_j = error === null || error === void 0 ? void 0 : error.response) === null || _j === void 0 ? void 0 : _j.status); console.log("[UPDATE_REPO_SETTING] ==> 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("[UPDATE_REPO_SETTING] 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("[UPDATE_REPO_SETTING] Error:\n", error === null || error === void 0 ? void 0 : error.message); } } } break; case "bitbucket": break; default: break; } } exports.default = updateRepoSetting; exports.updateRepoSetting = updateRepoSetting;