Skip to content

Props bot: automate contributor attribution with Co-authored-by lines in PR Description #65587

@vcanales

Description

@vcanales

Currently, adding Co-authored-by lines manually to the commit message when merging a pull request is an extra step that can overlooked, leading to missed attributions for contributors. This process could be streamlined to improve the developer experience and ensure proper recognition for everyone involved.

We can leverage GitHub’s squash merge functionality, which allows us to customize the commit message by including both the PR title and description. By automatically maintaining the list of contributors in the PR description, the Co-authored-by lines would be automatically appended to the squash commit message during the merge.

Steps required

  1. Add an option to https://github.com/WordPress/props-bot-action/tree/trunk to output the Co-author lines as a step output.
  2. Set the default message for Squash Merge commits on this repo to include the Pull Request title and description.
  3. Implement the action, which could look like this:
name: Props Bot - Auto-update PR with Contributors

on:
 # run conditions should remain the same as the ones in the current props-bot.yml workflow.
 # https://github.com/WordPress/gutenberg/blob/trunk/.github/workflows/props-bot.yml#L3-L30
jobs:
  update_coauthors:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      # Step 2: Use WordPress/props-bot-action to update the PR with co-authors
      # Assume that the action sets a variable that can be consumed in the next step.
      - name: Update PR with Contributors
        id: props_bot
        uses: WordPress/props-bot-action@trunk
        with:
          # Configure props-bot to add co-author lines
          github-token: ${{ secrets.GITHUB_TOKEN }}
          
      # Step 3: Fetch the updated PR description and append the co-authors, ensuring they are at the bottom.
      - name: Adjust PR Description for Co-authors
        run: |
          # Fetch the current PR description.
          CURRENT_DESCRIPTION=$(gh pr view ${{ github.event.pull_request.number }} --json body --jq '.body')

          # Remove any existing co-authored section to prevent duplicates.
          CLEAN_DESCRIPTION=$(echo "$CURRENT_DESCRIPTION" | sed '/<!-- Co-authored-by section start -->/,/<!-- Co-authored-by section end -->/d')

          # Fetch the new co-author lines from the output of the props-bot-action.
          COAUTHOR_LINES="${{ steps.props_bot.outputs.coauthors }}"

          # Insert delimiters and co-author lines at the bottom of the description.
          NEW_DESCRIPTION="$CLEAN_DESCRIPTION\n\n<!-- Co-authored-by section start -->\n$COAUTHOR_LINES\n<!-- Co-authored-by section end -->"
          
          # Update the PR with the new description.
          gh pr edit ${{ github.event.pull_request.number }} --body "$NEW_DESCRIPTION"

cc. @desrosj

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] Project ManagementMeta-issues related to project management of Gutenberg

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions