name: Auto-format with Black
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: # Allow manual triggering
permissions:
contents: write
pull-requests: write
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Full git history is needed to get proper timestamps for the files
fetch-depth: 0
# Use specific token with appropriate permissions
token: ${{ secrets.GITHUB_TOKEN }}
# For pull requests, check out the head of the PR
ref: ${{ github.event.pull_request.head.ref }}
# For pull requests, we need the repository where the PR comes from
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black
- name: Configure git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Run Black formatter
run: |
black src tests
- name: Check for changes
id: git-check
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes (PR from same repo)
if: |
steps.git-check.outputs.changes == 'true' &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository
run: |
git add -A
git commit -m "🤖 Auto-format code with Black"
git push origin HEAD:${{ github.head_ref }}
- name: Commit and push changes (direct push)
if: |
steps.git-check.outputs.changes == 'true' &&
github.event_name != 'pull_request'
run: |
git add -A
git commit -m "🤖 Auto-format code with Black"
git push
# For pull requests from forks, create a pull request instead of direct push
- name: Create PR for fork
if: |
steps.git-check.outputs.changes == 'true' &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name != github.repository
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "🤖 Auto-format code with Black"
title: "🤖 Auto-format code with Black for PR #${{ github.event.pull_request.number }}"
body: |
This PR auto-formats the code with Black for PR #${{ github.event.pull_request.number }}.
The original PR needs to be updated to follow the project's coding style.
branch: auto-format-pr-${{ github.event.pull_request.number }}
base: ${{ github.head_ref }}
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Nazruden/mcp-openvision'
If you have feedback or need assistance with the MCP directory API, please join our Discord server