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

Add the ability to post suggested changes during reviews #7806

Closed
wants to merge 4 commits into from

Conversation

adamslc
Copy link
Contributor

@adamslc adamslc commented Aug 6, 2023

This is a draft of how GitHub cli might add the ability to to post suggested
changes during PR reviews. It broadly uses the interface suggested in #5904:
all staged changes will be posted as suggestions.

Todo:

  • Add error handling. In particular, changes can currently only be made to
    lines that are changed in the PR diff (GitHub limitation). I don't currently
    check that a suggestion only modifies lines that are accessible under this
    critera, but it shouldn't be hard to add.
  • Fix upstream bug in diffparser that incorrectly reports the length of a
    diff hunk if there is only one changed line in the original or new file.
  • Refine the interface. In particular, it would be nice to be able to add
    comments to each suggestion as it is posted. Shouldn't be hard to implement...

Fix #5905.

@williammartin
Copy link
Member

@adamslc, thanks for this PR. It seems to have fallen off a cliff somewhere amidst team churn.

For anyone following along the TL;DR here is that giving a staged diff:

➜ git status
On branch williammartin-patch-1
Your branch is up to date with 'origin/williammartin-patch-1'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md

➜ git diff --staged | cat
diff --git a/README.md b/README.md
index 0a1686c..7973ab9 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
 # test-repo

-Some new conten
+Some new content

Running gh pr review --suggest will diff the files and then create a new pull request review thread:

image

It has some issues because it seems like creating a thread starts a review and then execuiting the previously implemented logic tries to start another review:

* Request at 2024-05-06 14:20:25.023505 +0200 CEST m=+12.941443001
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: token ████████████████████
> Content-Length: 226
> Content-Type: application/json
> Graphql-Features: merge_queue
> Time-Zone: Europe/Amsterdam
> User-Agent: GitHub CLI v2.32.1-7-gf42c76d4

GraphQL query:
mutation PullRequestReviewAdd($input:AddPullRequestReviewInput!){addPullRequestReview(input:$input){clientMutationId}}
GraphQL variables: {"input":{"pullRequestId":"PR_kwDOJgN1OM5uoNca","body":"Foo\n","event":"COMMENT"}}

< HTTP/2.0 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Mon, 06 May 2024 12:20:25 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.v4; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: DC77:17F1DB:18D747E0:18F419DE:6638CAFD
< X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
< X-Oauth-Scopes: codespace, gist, read:org, repo, workflow
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 5000
< X-Ratelimit-Reset: 1714998918
< X-Ratelimit-Resource: graphql
< X-Ratelimit-Used: 63
< X-Xss-Protection: 0

{
  "data": {
    "addPullRequestReview": null
  },
  "errors": [
    {
      "type": "UNPROCESSABLE",
      "path": [
        "addPullRequestReview"
      ],
      "locations": [
        {
          "line": 1,
          "column": 66
        }
      ],
      "message": "User can only have one pending review per pull request"
    }
  ]
}

* Request took 341.554459ms
failed to create review: GraphQL: User can only have one pending review per pull request (addPullRequestReview)

While this is interesting, I think we're a long way off being able to commit the time to this work especially given the design work needed as called out in the PR description. I'd definitely like to see this take the form of an extension to get feedback on (I may end up doing it myself because this is very interesting).

This is linked to from the original issue so I don't think it'll get lost in being closed. Thanks.

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

Successfully merging this pull request may close these issues.

Submit a suggested change to a PR from the Github CLI
2 participants