kubernetes / website

Kubernetes website and documentation repo:

Home Page:https://kubernetes.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automate a reminder to PR authors when their PR contains a large number of commits

rolfedh opened this issue · comments

This is a discussion of how to solve the following problem:

The 903 commits in the upstream dev-1.24-bn.1 are not following the SIG-Docs commit squashing policy. dev-1.24-bn.1 contains too many redundant or irrelevant commits. My suggestion was to open another PR with one squashed commit for this first release of the Bengali localization. (#45009 (comment))
Reviewed how we've managed similar cases in the past: #45009 (comment)

Please disregard the previous obsolete proposal.

previous obsolete proposal

This is a Feature Request

Problem: In some cases, pull requests (PRs) contain a large number of commits. This often occurs in localization PRs when the author accepts multiple suggestions through the GitHub UI, creating a new commit for each suggestion. Consequently, a single PR can add hundreds of commits to the repository's change history. This excessive change history becomes counterproductive if these commits do not provide significant value. Although we encourage PR authors to squash their changes, they occasionally forget, and these PRs, along with their extensive commit histories, sometimes get merged. We rely on training and reminders to address this issue, but these measures are not always effective. Thus, there is a need for a more automated solution to ensure a clean and manageable commit history.

What would you like to be added

To address the problem of PRs containing excessive commits, I propose adding a feature that automatically comments on PRs with more than a specified number of commits, reminding authors to squash their commits before merging. This can be implemented using GitHub Actions as follows:

  1. GitHub Action Workflow:

    • Create a GitHub Action that triggers on pull request events (e.g., when a PR is opened or updated).
    • The Action will check the number of commits in the PR.
  2. Automated Comment:

    • If the number of commits exceeds a specified threshold (e.g., 10 commits), the Action will automatically post a comment on the PR.
    • The comment will remind the PR author to squash their commits before merging.
  3. Implementation Example:

    • Below is an example of a GitHub Action workflow that achieves this functionality:
name: Comment on PR with Many Commits

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  comment:
    runs-on: ubuntu-latest

    steps:
    - name: Check out repository
      uses: actions/checkout@v2

    - name: Count commits in the pull request
      id: count_commits
      run: |
        PR_NUMBER=$(echo "${{ github.event.number }}")
        COMMITS=$(gh pr view $PR_NUMBER --json commits --jq '.commits | length')
        echo "commit_count=$COMMITS" >> $GITHUB_ENV

    - name: Post comment if commit count exceeds 10
      if: env.commit_count > 10
      run: |
        PR_NUMBER=$(echo "${{ github.event.number }}")
        gh pr comment $PR_NUMBER --body "This pull request contains more than 10 commits. Please consider squashing some commits."
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Comments

This method leverages GitHub Actions for automation, ensuring that your repository maintains a clean and manageable commit history by automatically reminding PR authors to squash their commits when necessary.

This issue is currently awaiting triage.

SIG Docs takes a lead on issue triage for this website, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@seokho-son @a-mccarthy I've created this draft proposal to address the following items in the agenda for today's "SIG Docs Localization Subgroup Monthly Meeting":

The 903 commits in the upstream dev-1.24-bn.1 are not following the SIG-Docs commit squashing policy. dev-1.24-bn.1 contains too many redundant or irrelevant commits. My suggestion was to open another PR with one squashed commit for this first release of the Bengali localization. (#45009 (comment))
Reviewed how we've managed similar cases in the past: #45009 (comment)

You can close this issue if it duplicates others or seems impractical. I'm only putting it up here for discussion.

We would definitely need to enhance the message to something like:

This pull request contains more than 10 commits. To keep our commit history clean and manageable, please squash your commits before merging. If the detailed commit history is necessary for this PR, please communicate this in the PR description and request that the maintainer preserves it. Otherwise, maintainers are advised to use the 'Squash and merge' option when merging.

/sig contributor-experience

/sig testing

I'm not sure this would help. Most of the PRs that made dev-1.24-bn.1 have a high number of commits were not squashed (which I'd recommend), but for an anecdotal look, a large number of them had between 2 and 10 commits.

Alternative: we could offer training to new localization approvers.

between 2 and 10 commits.

We can adjust the threshold number of commits in the script.
It's crucial to proactively train the localization approvers and promote their reliance on the documented guidelines relating to this issue: we can even link to the guideline in the body of the output comment.
This GitHub action serves the purpose of familiarizing or reiterating these guidelines to PR authors when needed.

I don't think a bot that only counts can help here @rolfedh. We can use something more sophisticated but commit count alone is a poor indicator of good practices being followed.

@sftim Agreed, then: no simple bot.
Would you say more about "something more sophisticated," please?
Let's solve the following issue:

The 903 commits in the upstream dev-1.24-bn.1 are not following the SIG-Docs commit squashing policy. dev-1.24-bn.1 contains too many redundant or irrelevant commits. My suggestion was to open another PR with one squashed commit for this first release of the Bengali localization. (#45009 (comment))
Reviewed how we've managed similar cases in the past: #45009 (comment)

My preference is still approver training. We shouldn't be working on a bot ahead of making sure that new approvers could also provide the same PR feedback manually.

I wasn't aware of a policy about squashing commits, although as a maintainer I will often suggest squashing. It's more of a convention.

Thanks for the conversation, @sftim. I think we can close this issue.
If anyone wants to propose an alternate solution, please open a new issue/enhancement request.

Bit of cleanup
/reopen

@sftim: Reopened this issue.

In response to this:

Bit of cleanup
/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

/close not-planned

@sftim: Closing this issue, marking it as "Not Planned".

In response to this:

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.