Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update method to determine latest valid PR reviews #51

Open
LoveIsGrief opened this issue Sep 24, 2023 · 0 comments
Open

Update method to determine latest valid PR reviews #51

LoveIsGrief opened this issue Sep 24, 2023 · 0 comments

Comments

@LoveIsGrief
Copy link
Owner

After lastPushedAt was deprecated, one still needs a method to determine which reviews are still valid. After a review has been made, the branch can still be pushed to.

One way to do this is to check if the commit associated with the review is also the latest.

query($repoName: String!, $repoOwner: String!, $prNumber: Int!){
          repository(name: $repoName, owner: $repoOwner) {
            pullRequest(number: $prNumber) {
              title
                number
      		  commits(first: 1){
                  nodes{
                    id
                  }
                }
                latestReviews(last: 100) {
                  nodes {
                    state
                    commit {
                      id
                    }
                    author {
                      login
                    }
                    publishedAt
                  }
                }
            }
          }
        }

One can use the latestReviews[].commit.id == pullRequest.commits[-1].id.

Example:

Call with

{
  "repoName": "nixpkgs",
  "repoOwner": "NixOS",
  "prNumber": 68884
}

Output

{
  "data": {
    "repository": {
      "pullRequest": {
        "title": "nixos/unifi: add test and additional config options [WIP]",
        "number": 68884,
        "commits": {
          "nodes": [
            {
              "id": "MDE3OlB1bGxSZXF1ZXN0Q29tbWl0MzE3NzczMzkyOjcxMDgwZGZlYjRhNDM1MzNlMTYwYjdhYjkyNzkxZmRjNGVmMTU1Mzk="
            }
          ]
        },
        "latestReviews": {
          "nodes": [
            {
              "state": "COMMENTED",
              "commit": null,
              "author": {
                "login": "aanderse"
              },
              "publishedAt": "2019-09-17T01:06:03Z"
            },
            {
              "state": "CHANGES_REQUESTED",
              "commit": {
                "id": "MDY6Q29tbWl0NDU0MjcxNjo3MTA4MGRmZWI0YTQzNTMzZTE2MGI3YWI5Mjc5MWZkYzRlZjE1NTM5"
              },
              "author": {
                "login": "veehaitch"
              },
              "publishedAt": "2021-05-20T09:33:23Z"
            }
          ]
        }
      }
    }
  }
}

Maybe the comparison can just be review.state == "APPROVED" && review.commit.id != null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant