Skip to content

[FEATURE]: Git Co-Author - GitHub actions #892

@surapuramakhil

Description

@surapuramakhil

Feature summary

Problem to fix when commits are sqashed.

Feature description

this is a common problem - when commits are squashed during PR merges - credit for original contributors gets lot.

git co-author is for that

https://www.dormant.ninja/git-co-author-script/

draft co author - github CI

name: Add Co-Authors
on:
  pull_request:
    types: [closed]
jobs:
  add-coauthors:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Add co-authors
        run: |
          # Extract contributors and append as co-authors (refer script)
          
# Define the base branch (e.g., main or master)
BASE_BRANCH=main

# Find the merge base (divergence point) between the current branch and the base branch
MERGE_BASE=$(git merge-base HEAD $BASE_BRANCH)

# Extract contributors from the commits starting at the merge base up to HEAD
CONTRIBUTORS=$(git log $MERGE_BASE..HEAD --format='%aN <%aE>' | sort | uniq)

# Output or append contributors as Co-authored-by lines
for CONTRIBUTOR in $CONTRIBUTORS; do
  echo "Co-authored-by: $CONTRIBUTOR"
done

Motivation

No response

Alternatives considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions