Skip to content

Auto format code on non-protected branches.#1208

Closed
niccokunzmann wants to merge 23 commits into
collective:mainfrom
niccokunzmann:auto-format
Closed

Auto format code on non-protected branches.#1208
niccokunzmann wants to merge 23 commits into
collective:mainfrom
niccokunzmann:auto-format

Conversation

@niccokunzmann
Copy link
Copy Markdown
Member

@niccokunzmann niccokunzmann commented Feb 17, 2026

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 .x and main and tags are exempt.

Checklist

  • I've added a change log entry to CHANGES.rst.
  • I've added or updated tests if applicable.
  • I've run and ensured all tests pass locally by following Run tests.
  • I've added or edited documentation, both as docstrings to be rendered in the API documentation and narrative documentation, as necessary.

Additional information

The commit 98bca82 should be reverted automatically.


📚 Documentation preview 📚: https://icalendar--1208.org.readthedocs.build/

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.yml to run ruff format / ruff check --fix and 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.

Comment thread .github/workflows/ruff-format.yml Outdated
Comment thread .github/workflows/ruff-format.yml
Comment thread .github/workflows/ruff-format.yml
Comment thread .github/workflows/ruff-format.yml
Comment thread .github/workflows/ruff-format.yml
Comment thread src/icalendar/__init__.py Outdated
@niccokunzmann
Copy link
Copy Markdown
Member Author

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.

@niccokunzmann niccokunzmann marked this pull request as draft February 17, 2026 17:42
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 22106041453

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.091%

Totals Coverage Status
Change from base Build 22089382994: 0.0%
Covered Lines: 11382
Relevant Lines: 11597

💛 - Coveralls

@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 22106548673

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.091%

Totals Coverage Status
Change from base Build 22089382994: 0.0%
Covered Lines: 11382
Relevant Lines: 11597

💛 - Coveralls

@coveralls
Copy link
Copy Markdown

coveralls commented Feb 17, 2026

Pull Request Test Coverage Report for Build 22277551569

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.081%

Totals Coverage Status
Change from base Build 22274921870: 0.0%
Covered Lines: 11418
Relevant Lines: 11635

💛 - Coveralls

@niccokunzmann niccokunzmann marked this pull request as ready for review February 17, 2026 17:49
@niccokunzmann
Copy link
Copy Markdown
Member Author

The commit d7128bf was automatically created on the fork's repository and pushed with the formatting changes.

@niccokunzmann niccokunzmann changed the title Auto format Auto format code on non-protected branches. Feb 17, 2026
@SashankBhamidi
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread .github/workflows/ruff-format.yml Outdated
Comment thread .github/workflows/ruff-format.yml Outdated
Comment thread .github/workflows/ruff-format.yml Outdated
Comment thread .github/workflows/ruff-format.yml
Comment thread .github/workflows/ruff-format.yml
Comment thread CHANGES.rst Outdated
niccokunzmann and others added 2 commits February 17, 2026 21:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Steve Piercy <web@stevepiercy.com>
@niccokunzmann
Copy link
Copy Markdown
Member Author

@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

@stevepiercy
Copy link
Copy Markdown
Member

stevepiercy commented Feb 17, 2026

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.

Copy link
Copy Markdown
Member

@SashankBhamidi SashankBhamidi left a comment

Choose a reason for hiding this comment

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

A few things:

  • Lines 21-22: github.event.pull_request.* is null on push events. Checkout falls back to defaults (verified in checkout's input-helper.ts: core.getInput('repository') || context.repo). These lines do nothing, should be removed.
  • Copilot correctly flagged lines 21-22 and the ruff check --fix scope. Worth reconsidering those.

Comment thread .github/workflows/ruff-format.yml Outdated
Comment thread .github/workflows/ruff-format.yml Outdated
Comment thread .github/workflows/ruff-format.yml
Comment thread .github/workflows/ruff-format.yml
Comment thread CHANGES.rst Outdated
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')
Copy link
Copy Markdown
Member Author

@niccokunzmann niccokunzmann Feb 18, 2026

Choose a reason for hiding this comment

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

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.

Comment thread .github/workflows/ruff-format.yml Outdated
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')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

heh, and you just updated it, but my suggestion stands.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, comments and purpose are in 73a97fe. Please have a look.

#
# This workflow EXCLUDES:
#
# - branch "main"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

@niccokunzmann niccokunzmann Feb 18, 2026

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
SashankBhamidi previously approved these changes Feb 22, 2026
Copy link
Copy Markdown
Member

@SashankBhamidi SashankBhamidi left a comment

Choose a reason for hiding this comment

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

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.

@niccokunzmann
Copy link
Copy Markdown
Member Author

Yes, that could be an issue. I guess, we will see if they can cope if we see the formatting commits.

@stevepiercy
Copy link
Copy Markdown
Member

It's not just first-timer contributors, but all contributors, including me. I personally hate it. Really, REALLY hate it.

@niccokunzmann
Copy link
Copy Markdown
Member Author

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.

@niccokunzmann
Copy link
Copy Markdown
Member Author

niccokunzmann commented Feb 23, 2026

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.

@stevepiercy
Copy link
Copy Markdown
Member

It would be nice to just comment "Please format" and that PR gets formatted.

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.

@niccokunzmann
Copy link
Copy Markdown
Member Author

This is stale. I will close this now. This can be taken up and changed when needed.

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.

5 participants