@@ -1355,6 +1355,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13551355 step((generator = generator.apply(thisArg, _arguments || [])).next());
13561356 });
13571357};
1358+ var __asyncValues = (this && this.__asyncValues) || function (o) {
1359+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1360+ var m = o[Symbol.asyncIterator], i;
1361+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
1362+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
1363+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
1364+ };
13581365var __importDefault = (this && this.__importDefault) || function (mod) {
13591366 return (mod && mod.__esModule) ? mod : { "default": mod };
13601367};
@@ -1392,6 +1399,7 @@ class GitHubHelper {
13921399 }
13931400 createOrUpdate(inputs, baseRepository, headRepository) {
13941401 return __awaiter(this, void 0, void 0, function* () {
1402+ var _a, e_1, _b, _c;
13951403 const [headOwner] = headRepository.split('/');
13961404 const headBranch = `${headOwner}:${inputs.branch}`;
13971405 // Try to create the pull request
@@ -1424,8 +1432,37 @@ class GitHubHelper {
14241432 // Update the pull request that exists for this branch and base
14251433 core.info(`Fetching existing pull request`);
14261434 const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranch, base: inputs.base }));
1435+ let existingPullNumber = undefined;
1436+ if ((pulls === null || pulls === void 0 ? void 0 : pulls.length) === 0 || pulls === null || pulls === undefined) {
1437+ core.error(`Failed to fetch existing pull request details through API - fetching all pull requests to manually check`);
1438+ try {
1439+ for (var _d = true, _e = __asyncValues(this.octokit.paginate.iterator(this.octokit.rest.pulls.list, Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', base: inputs.base }))), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
1440+ _c = _f.value;
1441+ _d = false;
1442+ const response = _c;
1443+ const existingPull = response.data.find(pull => pull.head.label === headBranch);
1444+ if (existingPull !== undefined) {
1445+ existingPullNumber = existingPull.number;
1446+ break;
1447+ }
1448+ }
1449+ }
1450+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1451+ finally {
1452+ try {
1453+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
1454+ }
1455+ finally { if (e_1) throw e_1.error; }
1456+ }
1457+ }
1458+ else {
1459+ existingPullNumber = pulls[0].number;
1460+ }
1461+ if (existingPullNumber === undefined) {
1462+ throw new Error(`A pull request already exists for ${headBranch} but couldn't acquire the pull number`);
1463+ }
14271464 core.info(`Attempting update of pull request`);
1428- const { data: pull } = yield this.octokit.rest.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pulls[0].number , title: inputs.title, body: inputs.body }));
1465+ const { data: pull } = yield this.octokit.rest.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: existingPullNumber , title: inputs.title, body: inputs.body }));
14291466 core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`);
14301467 return {
14311468 number: pull.number,
0 commit comments