Auto format code on non-protected branches.#1208
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a GitHub Actions workflow intended to auto-format Python code with Ruff on pull requests by committing formatting changes back to the PR branch.
Changes:
- Add
.github/workflows/ruff-format.ymlto runruff format/ruff check --fixand auto-commit results. - Add trailing blank lines to
src/icalendar/__init__.py(likely accidental/formatter artifact).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/icalendar/__init__.py |
Adds trailing blank lines at EOF. |
.github/workflows/ruff-format.yml |
New workflow to format/lint-fix code and push commits back to PRs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I think that this would be a nice feature but it needs to run on the repository of the person committing. So, maybe PR is not the right context but push. |
Pull Request Test Coverage Report for Build 22106041453Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 22106548673Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 22277551569Details
💛 - Coveralls |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
The commit d7128bf was automatically created on the fork's repository and pushed with the formatting changes. |
|
Okay, nice. I'll take a look at the changes in the morning. I'm going to rerequest another review from copilot. Why is coveralls spamming? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
28e991a to
e577bab
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Steve Piercy <web@stevepiercy.com>
|
@stevepiercy On the matter of confusion, I would try it out and get feedback. If it is an issue, it can be solved. For now, this would ease this PR: #1205 |
|
First-time contributors who are unfamiliar with git are not likely to disclose problems with not being able to push a commit to a branch that adds another commit from somewhere else. There's nothing automatically that notifies us of a problem, and it leads to the PR getting abandoned. In Plone, I often see strange behavior, including closing and opening multiple PRs, not creating a new branch for each pull request so that all changes pile up onto their most recent PR, and other common mistakes with git. Sometimes pointing the user to our docs for how to use git helps, but they have to read and understand them first. When I can identify the cause, one of these sections sometimes helps.
|
SashankBhamidi
left a comment
There was a problem hiding this comment.
A few things:
- Lines 21-22:
github.event.pull_request.*is null on push events. Checkout falls back to defaults (verified in checkout'sinput-helper.ts:core.getInput('repository') || context.repo). These lines do nothing, should be removed. - Copilot correctly flagged lines 21-22 and the
ruff check --fixscope. Worth reconsidering those.
Co-authored-by: Sashank <hello@sashank.wiki>
| pull-requests: write | ||
| name: Format the code with ruff and push the changes | ||
| runs-on: ubuntu-latest | ||
| if: github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') && !(startsWith(github.ref, 'refs/heads/') && endsWith(github.ref, '.x')) && !startsWith(github.ref, 'refs/heads/release') |
There was a problem hiding this comment.
The ! at the start was ignored by GitHub. I re-ordered the condition to not start with that.
In the downloaded log zip, there is a system.txt showing:
(
true && (
('refs/heads/auto-format' != 'refs/heads/main')
&& !startsWith('refs/heads/auto-format', 'refs/tags/')
&& !(
startsWith('refs/heads/auto-format', 'refs/heads/')
&& endsWith('refs/heads/auto-format', '.x')
)
&& !startsWith('refs/heads/auto-format', 'refs/heads/release')))
That should exclude main, all .x branches and tags as well as the release-... branches created by the maintenance tasks of releasing.
| pull-requests: write | ||
| name: Format the code with ruff and push the changes | ||
| runs-on: ubuntu-latest | ||
| if: ! startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main' && ! (startsWith(github.ref, 'refs/heads/') && endsWith(github.ref, '.x')) && ! startsWith(github.ref, 'refs/heads/release') |
There was a problem hiding this comment.
What is the intent here? It would be good to add a comment and possibly a link to a reference to explain the intent of this statement, as its arguments aren't really clear. That will help make sure what you want is what you get, and help other people understand it.
There was a problem hiding this comment.
heh, and you just updated it, but my suggestion stands.
There was a problem hiding this comment.
Yes, comments and purpose are in 73a97fe. Please have a look.
| # | ||
| # This workflow EXCLUDES: | ||
| # | ||
| # - branch "main" |
There was a problem hiding this comment.
This sounds like I can fork to stevepiercy/icalendar, push to my main and it won't run.
Then when I open a PR against collective/icalendar on its main branch, it still won't run.
Is that what you want?
Same for the remaining exclusions below.
There was a problem hiding this comment.
I think, that is a good start.
It can be extended to format main on other repos as that is where first -timers often start like in #1205. I would do that another time, and it requires more consideration.
I think, I prefer it if main stays main and can be fast-forwarded to collective/calendar's main.
There was a problem hiding this comment.
Honestly, I think automatically rewriting pull requests is a bad idea all around. Pull requests should be intentional and deliberate, which is something only humans can do.
There was a problem hiding this comment.
That is ok. I will not talk about the value. I see value. I would like to see if this is technically correct. Then, I will merge it or someone else does it and we see if it makes sense. We can remove it if it gets in the way of contribution.
There was a problem hiding this comment.
Honestly, I think automatically rewriting pull requests is a bad idea all around. Pull requests should be intentional and deliberate, which is something only humans can do.
+1
SashankBhamidi
left a comment
There was a problem hiding this comment.
This may be merged, has value, but I'm not too sure if first time contributors can keep up with pulling changes from branch to continue working without conflicts.
|
Yes, that could be an issue. I guess, we will see if they can cope if we see the formatting commits. |
|
It's not just first-timer contributors, but all contributors, including me. I personally hate it. Really, REALLY hate it. |
Yes, I think that is clear! Thanks for the perspective. It is not merged. I am still thinking. #1216 also contributes to improving the work flow for non-formatted PRs. |
|
Something like this could help: https://github.com/orgs/community/discussions/25100 It would be nice to just comment "Please format" and that PR gets formatted. I mean... One part of it is ease, the other one being perfectionist and the other one is having fun tinkering and exploring. |
Yes, if it's not 100% automated, but requires a human to intervene and approve the request after they review the proposed changes, then that would be OK. However, I'm afraid that most people will just click the "Go ahead, IDGAF" button and not review the proposed changes. There's a distinct advantage to forcing people to think and make intentional changes, instead of clicking the "easy" button. |
|
This is stale. I will close this now. This can be taken up and changed when needed. |
Closes issue
Contributors might push code that is badly formatted and then need to work more before the change can be accepted.
If you edit a file through the web UI, you do not have code formatting available. This automatically applies certain fixes.
Description
This automatically pushes commits with formatted code to the pull requests.
branches like
.xandmainand tags are exempt.Checklist
CHANGES.rst.Additional information
The commit 98bca82 should be reverted automatically.
📚 Documentation preview 📚: https://icalendar--1208.org.readthedocs.build/