You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2020/12/27 13:55:01 UTC

[airflow-get-workflow-origin] 04/08: Add support for pull_request_review type and added PR pagination

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow-get-workflow-origin.git

commit a0fc88cf92cadf7145ec723e7f93ab64eb9b96fc
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Wed Oct 28 16:50:35 2020 +0100

    Add support for pull_request_review type and added PR pagination
---
 dist/index.js |  9 +++++----
 src/main.ts   | 19 ++++++++++++-------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/dist/index.js b/dist/index.js
index f67f8c6..ed5e583 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1486,12 +1486,12 @@ function findPullRequest(octokit, owner, repo, headRepo, headBranch, headSha) {
     return __awaiter(this, void 0, void 0, function* () {
         // Finds Pull request for this workflow run
         core.info(`\nFinding PR request id for: owner: ${owner}, Repo:${repo}, Head:${headRepo}:${headBranch}.\n`);
-        const pullRequests = yield octokit.pulls.list({
+        const pullRequests = yield octokit.paginate(octokit.pulls.list({
             owner,
             repo,
             head: `${headRepo}:${headBranch}`
-        });
-        for (const pullRequest of pullRequests.data) {
+        }));
+        for (const pullRequest of pullRequests) {
             core.info(`\nComparing: ${pullRequest.number} sha: ${pullRequest.head.sha} with expected: ${headSha}.\n`);
             if (pullRequest.head.sha === headSha) {
                 core.info(`\nFound PR: ${pullRequest.number}\n`);
@@ -1515,7 +1515,8 @@ function getOrigin(octokit, runId, owner, repo) {
             `Head branch: ${sourceRun.head_branch} ` +
             `Event: ${sourceRun.event}, Head sha: ${sourceRun.head_sha}, url: ${sourceRun.url}`);
         let pullRequest = null;
-        if (sourceRun.event === 'pull_request') {
+        if (sourceRun.event === 'pull_request' ||
+            sourceRun.event === 'pull_request_review') {
             pullRequest = yield findPullRequest(octokit, owner, repo, sourceRun.head_repository.owner.login, sourceRun.head_branch, sourceRun.head_sha);
         }
         return [
diff --git a/src/main.ts b/src/main.ts
index 63d0c23..b545f5f 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -43,12 +43,14 @@ async function findPullRequest(
   core.info(
     `\nFinding PR request id for: owner: ${owner}, Repo:${repo}, Head:${headRepo}:${headBranch}.\n`
   )
-  const pullRequests = await octokit.pulls.list({
-    owner,
-    repo,
-    head: `${headRepo}:${headBranch}`
-  })
-  for (const pullRequest of pullRequests.data) {
+  const pullRequests = await octokit.paginate(
+    octokit.pulls.list({
+      owner,
+      repo,
+      head: `${headRepo}:${headBranch}`
+    })
+  )
+  for (const pullRequest of pullRequests) {
     core.info(
       `\nComparing: ${pullRequest.number} sha: ${pullRequest.head.sha} with expected: ${headSha}.\n`
     )
@@ -82,7 +84,10 @@ async function getOrigin(
       `Event: ${sourceRun.event}, Head sha: ${sourceRun.head_sha}, url: ${sourceRun.url}`
   )
   let pullRequest: rest.PullsListResponseItem | null = null
-  if (sourceRun.event === 'pull_request') {
+  if (
+    sourceRun.event === 'pull_request' ||
+    sourceRun.event === 'pull_request_review'
+  ) {
     pullRequest = await findPullRequest(
       octokit,
       owner,