Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,33 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11', '3.12', '3.13']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0 # Need full history for git tests

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
- name: Install package and dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest
pip install -e .
pip install pytest pytest-cov

- name: Run unit tests
run: |
pytest tests/ -v --cov=contrib_checker --cov-report=xml --cov-report=term

- name: Run tests
run: pytest -q
env:
PYTHONPATH: ${{ github.workspace }}
- name: Upload coverage to Codecov
if: matrix.python-version == '3.11'
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
14 changes: 14 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include README.md
include LICENSE
include CITATION.cff
include CONTRIBUTING.md
include requirements.txt
include action.yml
include .gitlab-ci.yml
include GITLAB_CI_USAGE.md
include contrib_checker_core.py
include check_contributors_github.py
include check_contributors_gitlab.py
recursive-include tests *.py
global-exclude __pycache__
global-exclude *.py[co]
182 changes: 164 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,110 @@
# ContribChecker
# contrib-checker

ContribChecker is a GitHub Action and helper script that verifies that contributors who appear in the git history are listed in the repository metadata files (`CITATION.cff` and `codemeta.json`). It uses a `.mailmap` file to unify multiple emails/names for the same person.
contrib-checker is a library and set of tools that verify contributors from git history are properly listed in repository metadata files (`CITATION.cff` and `codemeta.json`).
It provides:

Why this is useful
- Keeps citation and credit metadata accurate when new contributors add commits
- Helps projects maintain reproducible credit and citation information
- **Python library**: Installable package for programmatic use
- **Command-line tool**: `contrib-checker` CLI for local checking
- **GitHub Action**: Automated checking in GitHub workflows
- **GitLab CI**: Support for GitLab merge request checking

What this repository provides
- A Python script at `check_contributors.py` that performs the check
- A GitHub Actions bot at `action.yml` that runs the script on PR events
## Installation

How it works
- The action runs on PR events. It runs `git log --use-mailmap --format='%aN <%aE>' BASE..HEAD` to collect commit authors, so ensure `.mailmap` is present if you need to unify multiple emails.
- It compares commit authors against `CITATION.cff` and `codemeta.json` and posts a comment if missing contributors are found.
- If `mode: fail` is set in the config, the Action will fail the job (exit code 1).
### As a Python package

```bash
pip install contrib-checker
```

### For development

```bash
git clone https://github.com/vuillaut/contrib-checker.git
cd contrib-checker
pip install -e .

```

## Usage

### Command-line tool

After installation, you can use the `contrib-checker` command:

```bash
# Check all contributors in current repository
contrib-checker

# Check with specific mode
contrib-checker --mode fail

# Check with ignore lists
contrib-checker --ignore-emails bot@example.com --ignore-logins bot-user

# Check specific commit range
contrib-checker --from-sha abc123 --to-sha def456

# Use specific repository path
contrib-checker --repo-path /path/to/repo

# See all options
contrib-checker --help
```

### As a Python library

```python
from contrib_checker import ContributorChecker
from pathlib import Path

# Initialize checker
config = {
'mode': 'warn', # or 'fail'
'ignore_emails': ['bot@example.com'],
'ignore_logins': ['bot-user']
}

checker = ContributorChecker(
repo_path=Path('.'),
config=config
)

# Check all contributors
success, results = checker.check_all_contributors()

# Check specific commit range
success, results = checker.check_range_contributors(
from_sha='abc123',
to_sha='def456',
description='PR commits'
)

# Check results
if results['missing_overall']:
print("Missing contributors:")
for contributor in results['missing_overall']:
print(f" {contributor}")
```

### Platform-specific usage

```python
# GitHub-specific wrapper
from contrib_checker import GitHubContributorChecker

## Quick start
github_checker = GitHubContributorChecker()
success = github_checker.check_pr_contributors()

# GitLab-specific wrapper
from contrib_checker import GitLabContributorChecker

gitlab_checker = GitLabContributorChecker()
success = gitlab_checker.check_mr_contributors()
```

## GitHub Action Setup

### Quick start

1. Ensure your repository has `CITATION.cff` and/or `codemeta.json` with author/contributor entries.
2. Add a `.mailmap` at the repository root if you need to unify alternate emails or names from the git history.
Expand All @@ -26,6 +114,16 @@ How it works
### Example `.github/workflows/contrib-check.yml`

```yaml
name: Contributor Check

on:
pull_request:
types: [opened, synchronize]

permissions:
contents: read
pull-requests: write # allows posting comments on PRs

jobs:
contrib-check:
runs-on: ubuntu-latest
Expand All @@ -36,12 +134,60 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
mode: warn # or 'fail' to make the workflow fail when contributors are missing
ignore_emails: "dependabot[bot]@users.noreply.github.com,ci-bot@example.com,noreply@github.com"
ignore_logins: "dependabot[bot],github-actions[bot],ci-bot"
ignore_emails: "dependabot[bot]@users.noreply.github.com,ci-bot@example.com"
ignore_logins: "dependabot[bot],github-actions[bot]"
```

## GitLab CI Setup

See [GITLAB_CI_USAGE.md](GITLAB_CI_USAGE.md) for detailed GitLab CI setup instructions.

### Example `.gitlab-ci.yml`

```yaml
contrib-check:
stage: test
image: python:3.11
script:
- pip install contrib-checker
- contrib-checker
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
```

## How it works

- Uses `git log --use-mailmap` to collect commit authors, so ensure `.mailmap` is present if you need to unify multiple emails
- Compares commit authors against `CITATION.cff` and `codemeta.json` contributors
- Posts comments on GitHub PRs or GitLab MRs when missing contributors are found
- Can be configured to fail CI when contributors are missing (`mode: fail`)

## Requirements

- GitHub Actions must be enabled for your repository.
- A `CITATION.cff` or `codemeta.json` file must be present and properly formatted.
- Optional: A `.mailmap` file if you need to unify contributor names/emails from git history.
- Python 3.8+
- Git repository with contributor metadata files
- For GitHub Actions: `CITATION.cff` or `codemeta.json` file
- For GitLab CI: Same metadata files plus GitLab API token
- Optional: `.mailmap` file to unify contributor names/emails

## Configuration

The tool can be configured via:

1. **Configuration file**: `.github/contrib-metadata-check.yml` (GitHub) or environment variables (GitLab)
2. **Command-line arguments**: When using the CLI
3. **Environment variables**: For CI/CD integration

### Configuration options

- `mode`: `warn` (default) or `fail`
- `ignore_emails`: List of email addresses to ignore
- `ignore_logins`: List of login names to ignore

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ runs:
with:
python-version: '3.x'

- name: Install deps
run: python -m pip install -r ${{ github.action_path }}/requirements.txt
- name: Install contrib-checker package
run: python -m pip install ${{ github.action_path }}
shell: bash

- name: Run check script
run: python ${{ github.action_path }}/check_contributors.py
- name: Run contributor check
run: python -m contrib_checker.github
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
Expand Down
Loading