Skip to content

Conversation

@TomasTomecek
Copy link
Member

@TomasTomecek TomasTomecek commented Jan 14, 2026

This first version of this PR was completely implemented by Claude Code and Ambient Code.

After Nikola's amazing review, I fixed the problems myself, especially tinkering with padding fixups and updating the regex that parses day of month to properly account for double-digit days (and don't stop at the first digit - thanks Claude for that one).

Fixes #216

RELEASE NOTES BEGIN

Changelog entries that have incorrect padding set for a day of a month are now fixed if possible or ignored.

RELEASE NOTES END

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @TomasTomecek, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where malformed changelog entries with incorrect day-of-month padding could propagate incorrect formatting. It introduces robust validation for RPM changelog day padding and modifies the entry addition logic to ignore invalid existing entries, ensuring that newly added changelog entries adhere to correct formatting standards. This significantly improves the reliability of changelog processing within the system.

Highlights

  • New has_valid_day_padding property: Introduced a property in ChangelogEntry to validate day-of-month padding in RPM changelog headers. It ensures double-digit days (10-31) have no space padding, while single-digit days (1-9) can have any padding, preventing malformed entries.
  • Improved add_changelog_entry method: The add_changelog_entry method now filters out changelog entries with invalid day padding before determining the preferred padding style. If all existing entries are invalid, it defaults to zero-padding, ensuring new entries are always correctly formatted.
  • Comprehensive Testing: Added both unit and integration tests to cover the new validation logic. The unit test verifies has_valid_day_padding with various valid and invalid headers, and the integration test simulates a real-world scenario (issue Ignore clearly incorrect entries when guessing day of month padding when adding changelog entry #216) to confirm invalid entries are ignored.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses an issue with incorrect day padding in changelog entries by introducing a validation property has_valid_day_padding and using it to filter out malformed entries when determining padding for new entries. The changes are logical, and the addition of both unit and integration tests ensures the fix is robust. I have one suggestion to make the regular expression in the new validation logic more precise for better long-term maintainability.

Comment on lines 211 to 190
m = re.search(
rf"""
({weekdays}) # weekday
[ ]
({months}) # month
[ ]
(?P<wsp>[ ]*) # optional whitespace padding
(?P<day>(?P<zp>0)?[1-9]\d*) # day of month (1-31)
[ ] # space after day
""",
self.header,
re.VERBOSE,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The regular expression for parsing the day of the month is a bit too loose. [1-9]\\d* can match numbers greater than 31 (e.g., 99). While the subsequent integer conversion handles this for the purpose of checking padding, it's better practice to use a more precise regex to be stricter with the input format and avoid potential issues with malformed changelog entries.\n\nAdditionally, this regex is very similar to those in day_of_month_padding and extended_timestamp. There's an opportunity to reduce code duplication by extracting a common regex pattern or a helper method for date parsing in a future refactoring.

Suggested change
m = re.search(
rf"""
({weekdays}) # weekday
[ ]
({months}) # month
[ ]
(?P<wsp>[ ]*) # optional whitespace padding
(?P<day>(?P<zp>0)?[1-9]\d*) # day of month (1-31)
[ ] # space after day
""",
self.header,
re.VERBOSE,
)
m = re.search(
rf"""
({weekdays}) # weekday
[ ]
({months}) # month
[ ]
(?P<wsp>[ ]*) # optional whitespace padding
(?P<day>(?P<zp>0)?[1-9]|[12]\\d|3[01]) # day of month (1-31)
[ ] # space after day
""",
self.header,
re.VERBOSE,
)

Copy link
Member

Choose a reason for hiding this comment

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

And even better would be to make use of existing day_of_month_padding() without reimplementing everything from scratch. The biggest question here is how to get the info about nonsensical whitespace padding in a Pythonic way from day_of_month_padding() alongside its current return value, the rest is extremely trivial to implement.

@centosinfra-prod-github-app
Copy link
Contributor

@centosinfra-prod-github-app
Copy link
Contributor

@TomasTomecek TomasTomecek marked this pull request as draft January 15, 2026 09:31
@TomasTomecek
Copy link
Member Author

Will update this based on Nikola's feedback. (Funny that Gemini didn't complain about that :)

@centosinfra-prod-github-app
Copy link
Contributor


# Reject invalid padding: double-digit days with whitespace
if day_num >= 10 and wsp:
return ""
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem very smart. Why not rather fix nonsensical padding and return it corrected? day_of_month_padding should be renamed to sanitized_day_of_month_padding or similar in such case, to match the implementation, and nothing else has to change.

Copy link
Member Author

Choose a reason for hiding this comment

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

great point, will do and will cover it by a test case

[ ]
(?P<wsp>[ ]*) # optional whitespace padding
((?P<zp>0)?\d|[12]\d|3[01]) # possibly zero-padded day of month
(?P<day>(?P<zp>0)?[1-9]\d*) # day of month (1-31)
Copy link
Member

Choose a reason for hiding this comment

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

What's wrong with a stricter regex? Are we assuming months will have more than 31 days in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm honestly surprised as well, because I saw the agent prefer the stricter regex but disbanded it in the second iteration; naughty claude

(?P<wsp>[ ]*) # optional whitespace padding
((?P<zp>0)?\d|[12]\d|3[01]) # possibly zero-padded day of month
(?P<day>(?P<zp>0)?[1-9]\d*) # day of month (1-31)
[ ] # space after day
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't have to be here, does it?

@TomasTomecek TomasTomecek marked this pull request as ready for review January 15, 2026 15:42
@TomasTomecek
Copy link
Member Author

/gemini review

@centosinfra-prod-github-app
Copy link
Contributor

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves the issue of malformed changelog entries with incorrect day padding. The changes in specfile/changelog.py enhance the robustness of the day_of_month_padding property by refining the regex for day parsing and introducing explicit error handling for invalid day formats and incorrect space padding for double-digit days. The addition of a default value to the max() function in specfile/specfile.py prevents potential ValueError exceptions when processing empty changelogs, ensuring a sensible default padding. The accompanying unit and integration tests have been thoughtfully updated and expanded to cover these new behaviors and edge cases, providing strong validation for the implemented solution.

@centosinfra-prod-github-app
Copy link
Contributor

@TomasTomecek
Copy link
Member Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses an issue with parsing changelog entries that have incorrect padding for the day of the month. The approach of updating the regular expression for better day parsing and sanitizing the padding is sound. The accompanying unit and integration tests are well-written and thoroughly validate the fix. I have a couple of minor suggestions to enhance the readability of the new logic in specfile/changelog.py, but overall, this is a solid contribution.

[ ]
(?P<wsp>[ ]*) # optional whitespace padding
((?P<zp>0)?\d|[12]\d|3[01]) # possibly zero-padded day of month
((?P<zp>0)?(?P<day>[12]\d|3[01]|[1-9])) # possibly zero-padded day of month
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The regex for capturing the day of the month contains an unnecessary outer pair of parentheses. Removing them would simplify the expression without changing its behavior, improving readability.

Suggested change
((?P<zp>0)?(?P<day>[12]\d|3[01]|[1-9])) # possibly zero-padded day of month
(?P<zp>0)?(?P<day>[12]\d|3[01]|[1-9]) # possibly zero-padded day of month

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, true!

Copy link
Member Author

Choose a reason for hiding this comment

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

actually I'll split it to two lines

Comment on lines 193 to 196
return ("" if len(m.group("day")) == 2 else m.group("wsp")) + (
m.group("zp") or ""
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This conditional expression is a bit dense. Refactoring it into separate variables for whitespace and zero padding would improve readability and make the logic easier to follow.

Suggested change
return ("" if len(m.group("day")) == 2 else m.group("wsp")) + (
m.group("zp") or ""
)
whitespace_padding = "" if len(m.group("day")) == 2 else m.group("wsp")
zero_padding = m.group("zp") or ""
return whitespace_padding + zero_padding

Copy link
Member Author

Choose a reason for hiding this comment

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

Nikola hated that, so sorry mate, no can't do

Copy link
Member

@nforro nforro Jan 19, 2026

Choose a reason for hiding this comment

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

I mean, it seems quite self-explanatory to me even without the variables, but since the compact version doesn't fit on a single line anyway, I'm fine with the suggestion.

Alternative would be something like this, but let's go with the variables:

return (
    ("" if len(m.group("day")) == 2 else m.group("wsp")) +
    (m.group("zp") or "")
)

@centosinfra-prod-github-app
Copy link
Contributor

@centosinfra-prod-github-app
Copy link
Contributor

Copy link
Member

@nforro nforro left a comment

Choose a reason for hiding this comment

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

👍

@TomasTomecek TomasTomecek added the mergeit Merge via Zuul label Jan 19, 2026
@nforro nforro removed the mergeit Merge via Zuul label Jan 19, 2026
@nforro
Copy link
Member

nforro commented Jan 19, 2026

Sorry, I didn't notice the tests failing on EL8. That has to be fixed.

@TomasTomecek
Copy link
Member Author

My bad, the other green ticks convinced me all is good so I ignored the EL failures.

@centosinfra-prod-github-app
Copy link
Contributor

I had to fix the regex to correctly account for double-digit days (only
first digit was parsed before this change).

This commit also ignores extra padding for double-digit days.

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
Assisted-by: Claude
Co-authored-by: Nikola Forró <nforro@redhat.com>
@centosinfra-prod-github-app
Copy link
Contributor

@TomasTomecek TomasTomecek added the mergeit Merge via Zuul label Jan 19, 2026
@TomasTomecek
Copy link
Member Author

regate

@centosinfra-prod-github-app
Copy link
Contributor

@centosinfra-prod-github-app centosinfra-prod-github-app bot merged commit d0da008 into packit:main Jan 19, 2026
38 of 44 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Packit pull requests Jan 19, 2026
@TomasTomecek TomasTomecek deleted the iss216 branch January 19, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mergeit Merge via Zuul

Projects

Development

Successfully merging this pull request may close these issues.

Ignore clearly incorrect entries when guessing day of month padding when adding changelog entry

2 participants