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

Provide a way to integrate/configure googleapis/code-suggester so openrewrite diff is displayed as GitHub PR suggestions #3891

Closed
vlsi opened this issue Jan 7, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@vlsi
Copy link

vlsi commented Jan 7, 2024

What problem are you trying to solve?

It would be nice if OpenRewrite suggestions could be displayed as PR suggestions in GitHub UI.

Describe the solution you'd like

  • "check style workflow" executes OpenRewrite, produces a diff/patch/whatever file as workflow artifact
  • A separate on: workflow_run: types: completed workflow picks up the attached patch artifact and calls https://github.com/googleapis/code-suggester to create code suggestions

A dedicated on: workflow_run workflow would be able to access secrets, so it would be relatively secure, and it would not allow PR builds to access secrets.

Unfortunately, the current googleapis/code-suggester does not support comments for suggestions. In other words, it creates only ```suggestion ... ``` comment, and it would probably be great to pass extra information like the rule name to the message.

For instance, ErrorProne's messages include a link with detailed explanation and the summary:

ERROR: example/myproject/BUILD:29:1: Java compilation in rule '//example/myproject:hello'
ShortSet.java:6: error: [CollectionIncompatibleType] Argument 'i - 1' should not be passed to this method;
its type int is not compatible with its collection's type argument Short
      s.remove(i - 1);
              ^
    (see http://errorprone.info/bugpattern/CollectionIncompatibleType)

OpenRewrite could probably add a link to the rule documentation so the users could know the intention behind the rule.

Additional context

@vlsi
Copy link
Author

vlsi commented Jan 7, 2024

It looks like pull requests=read and write should be enough for the action to create suggestions.
Unfortunately, it would imply the commenter user would have permission to merge PRs.

Here's a screenshot from New fine-grained personal access token page:

GitHub provides no access, read-only, and read-write access for personal access tokens

@koppor
Copy link

koppor commented Jan 28, 2024

As far as I understand reviewdog, it supports diff as input, which should be enough to send the patch file to the API and then one has the suggestions?

It can even made be more simpler - if the diff is existing in the working tree: https://github.com/reviewdog/action-suggester

(I put that as TODO on my list; I wanted to share fast, because we made good experiences in the context of checkstyle with reviewdog)

@timtebeek
Copy link
Contributor

Thanks for the helpful link @koppor; hadn't come across reviewdog before, and seems a convenient option for other platforms than GitHub indeed. For now I'd started to work with code-suggester in these two PRs, and will expand that with recipe runs:

That approach helpfully hides the implementation details in a shared workflow, such that we can always switch as needed. I'd for now considered this something to use on the OpenRewrite repositories itself, but we can look at opening that up as an action ourselves in the future as well. Input & help welcome. :)

@timtebeek timtebeek self-assigned this Feb 4, 2024
@timtebeek
Copy link
Contributor

As part of openrewrite/gh-automation#45 we now have two new workflows that together review PRs:
The first one receives a PR and runs recipes, while the second comments any changes found as code suggestions.

An example of such automated review comments can be seen here openrewrite/rewrite-testing-frameworks#343 (review)

We're likely to refine and expand this approach still, but I believe this is a good first step to show how this can be achieved. We don't yet insert accompanying comments, and that's perhaps indeed not supported by code-suggester, but good enough for use on our own PRs for now.

Further input and suggestions welcome, but I think we've achieved enough to close this issue already; I'll monitor any comments that arrive still, and can reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

3 participants