@@ -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};
@@ -1390,6 +1397,43 @@ class GitHubHelper {
13901397 repo: repo
13911398 };
13921399 }
1400+ getPullNumber(baseRepository, headBranch, baseBranch) {
1401+ return __awaiter(this, void 0, void 0, function* () {
1402+ var _a, e_1, _b, _c;
1403+ const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranch, base: baseBranch }));
1404+ let pullNumber = undefined;
1405+ if ((pulls === null || pulls === void 0 ? void 0 : pulls.length) === 0 || pulls === null || pulls === undefined) {
1406+ // This is a fallback due to a bug that affects the list endpoint when called on forks with the same owner as the repository parent.
1407+ core.info(`Pull request not found via list endpoint; attempting fallback mechanism`);
1408+ try {
1409+ 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: baseBranch }))), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
1410+ _c = _f.value;
1411+ _d = false;
1412+ const response = _c;
1413+ const existingPull = response.data.find(pull => pull.head.label === headBranch);
1414+ if (existingPull !== undefined) {
1415+ pullNumber = existingPull.number;
1416+ break;
1417+ }
1418+ }
1419+ }
1420+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1421+ finally {
1422+ try {
1423+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
1424+ }
1425+ finally { if (e_1) throw e_1.error; }
1426+ }
1427+ }
1428+ else {
1429+ pullNumber = pulls[0].number;
1430+ }
1431+ if (pullNumber === undefined) {
1432+ throw new Error(`Failed to find pull request number for branch ${headBranch}`);
1433+ }
1434+ return pullNumber;
1435+ });
1436+ }
13931437 createOrUpdate(inputs, baseRepository, headRepository) {
13941438 return __awaiter(this, void 0, void 0, function* () {
13951439 const [headOwner] = headRepository.split('/');
@@ -1423,9 +1467,9 @@ class GitHubHelper {
14231467 }
14241468 // Update the pull request that exists for this branch and base
14251469 core.info(`Fetching existing pull request`);
1426- const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository( baseRepository)), { state: 'open', head: headBranch, base: inputs.base }) );
1470+ const pullNumber = yield this.getPullNumber( baseRepository, headBranch, inputs.base);
14271471 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 }));
1472+ const { data: pull } = yield this.octokit.rest.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pullNumber , title: inputs.title, body: inputs.body }));
14291473 core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`);
14301474 return {
14311475 number: pull.number,
0 commit comments