Skip to content

CI Add a bot to comment on PRs when linter fails #26553

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

Merged
merged 19 commits into from
Jun 19, 2023

Conversation

adrinjalali
Copy link
Member

@adrinjalali adrinjalali commented Jun 9, 2023

In #23362 we decided to have a bot to comment something helpful when linter fails, so that it'd enable us to have more complicated linters (such as adding isort) without burdening the contributors too much.

This PR adds a bot which would comment PRs with relevant information. An example run can be seen here: adrinjalali/gh-action-test#3

Note that we can't really test this until we merge it. The action in a PR form a fork doesn't have permission to post a comment.

@adrinjalali adrinjalali changed the title [WIP - IGNORE] Add a bot to comment on PRs when linter fails. CI Add a bot to comment on PRs when linter fails. Jun 15, 2023
@adrinjalali adrinjalali marked this pull request as ready for review June 15, 2023 14:21
@adrinjalali
Copy link
Member Author

cc @ogrisel @lesteve @thomasjpfan

@adrinjalali adrinjalali changed the title CI Add a bot to comment on PRs when linter fails. CI Add a bot to comment on PRs when linter fails Jun 15, 2023
Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks.

However, I am worried that adding a new comment each time the linter fails can make the discussion thread of the PR very crowded very quickly.

Maybe the bot should delete the previous comments whenever it adds a new comment to the discussion and also when the linter step is green.

WDYT?

id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this potiuk/get-workflow-origin@v1_5 trustable? I don't really know how the security model of the github API works but is it possible to give this step a token with a limited set of permissions just to retrieve the issue number and nothing in write mode?

In particular I am not sure how the abuse of ${{ secrets.GITHUB_TOKEN }} would make it possible for a malicious actions/setup-python@v3 to upload malicious wheels to pypi or anaconda.org's nightly wheel repo one way or another.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should explicitly configure the permissions granted to the actions in this workflow file:

https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token

Copy link
Member

@ogrisel ogrisel Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token permissions are set, now this action only has read access to pull requests.

@adrinjalali
Copy link
Member Author

Maybe the bot should delete the previous comments whenever it adds a new comment to the discussion and also when the linter step is green.

This now deletes all previous comments, and leaves a rolling comment at the end. Each push creates a new one and is always reflecting the latest state of the PR.

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks!

@adrinjalali
Copy link
Member Author

This now keeps the first comment and updates it.

It also skips the details if the message is too long and posting fails. It's tested here: adrinjalali/gh-action-test#5

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasjpfan thomasjpfan enabled auto-merge (squash) June 19, 2023 15:30
@thomasjpfan thomasjpfan merged commit 180e059 into scikit-learn:main Jun 19, 2023
@adrinjalali adrinjalali deleted the bot-commenter branch June 20, 2023 11:23
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Jun 29, 2023
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants