@@ -10117,10 +10117,29 @@ function wrappy (fn, cb) {
1011710117/***/ }),
1011810118
1011910119/***/ 6719:
10120- /***/ (function(__unused_webpack_module, exports) {
10120+ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__ ) {
1012110121
1012210122"use strict";
1012310123
10124+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10125+ if (k2 === undefined) k2 = k;
10126+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
10127+ }) : (function(o, m, k, k2) {
10128+ if (k2 === undefined) k2 = k;
10129+ o[k2] = m[k];
10130+ }));
10131+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10132+ Object.defineProperty(o, "default", { enumerable: true, value: v });
10133+ }) : function(o, v) {
10134+ o["default"] = v;
10135+ });
10136+ var __importStar = (this && this.__importStar) || function (mod) {
10137+ if (mod && mod.__esModule) return mod;
10138+ var result = {};
10139+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
10140+ __setModuleDefault(result, mod);
10141+ return result;
10142+ };
1012410143var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1012510144 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1012610145 return new (P || (P = Promise))(function (resolve, reject) {
@@ -10132,29 +10151,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1013210151};
1013310152Object.defineProperty(exports, "__esModule", ({ value: true }));
1013410153exports.createBranch = void 0;
10154+ const core = __importStar(__nccwpck_require__(2186));
1013510155function createBranch(getOctokit, context, branch, sha) {
10136- var _a;
1013710156 return __awaiter(this, void 0, void 0, function* () {
1013810157 const toolkit = getOctokit(githubToken());
1013910158 // Sometimes branch might come in with refs/heads already
1014010159 branch = branch.replace('refs/heads/', '');
1014110160 const ref = `refs/heads/${branch}`;
10142- // throws HttpError if branch already exists.
10161+ const refPath = `heads/${branch}`;
10162+ const targetSha = sha || context.sha;
10163+ core.debug(`Target ref: ${ref} (createRef), refPath: ${refPath} (getRef/updateRef), target SHA: ${targetSha}`);
10164+ // Check if branch already exists using git refs API (heads/<branch>)
1014310165 try {
10144- yield toolkit.rest.repos.getBranch(Object.assign(Object.assign({}, context.repo), { branch }));
10166+ const refData = yield toolkit.rest.git.getRef(Object.assign({ ref: refPath }, context.repo));
10167+ core.debug(`Found ref via getRef: ${JSON.stringify(refData.data)}`);
10168+ // If ref exists, update it to target SHA
10169+ const resp = yield toolkit.rest.git.updateRef(Object.assign({ ref: refPath, sha: targetSha }, context.repo));
10170+ core.debug(`updateRef response: ${JSON.stringify(resp.data)}`);
10171+ return isValidRefResponse(resp, ref);
1014510172 }
1014610173 catch (error) {
10174+ // If the ref was not found, create it. Other errors bubble up.
1014710175 if (error.name === 'HttpError' && error.status === 404) {
10148- const resp = yield toolkit.rest.git.createRef(Object.assign({ ref, sha: sha || context.sha }, context.repo));
10149- return ((_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.ref) === ref;
10150- }
10151- else {
10152- throw Error(error);
10176+ core.debug(`Ref not found via getRef, creating new branch`);
10177+ const resp = yield toolkit.rest.git.createRef(Object.assign({ ref, sha: targetSha }, context.repo));
10178+ core.debug(`createRef response: ${JSON.stringify(resp.data)}`);
10179+ return isValidRefResponse(resp, ref);
1015310180 }
10181+ core.debug(`Unexpected error while checking/creating ref: ${error.name} ${error.status} ${error.message}`);
10182+ throw Error(error);
1015410183 }
1015510184 });
1015610185}
1015710186exports.createBranch = createBranch;
10187+ function isValidRefResponse(resp, expectedRef) {
10188+ var _a;
10189+ return ((_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.ref) === expectedRef;
10190+ }
1015810191function githubToken() {
1015910192 const token = process.env.GITHUB_TOKEN;
1016010193 if (!token)
0 commit comments