feat: add auto sync for COC across all repos
This commit is contained in:
parent
c9872316d8
commit
7e90153e3d
1 changed files with 75 additions and 0 deletions
75
.forgejo/workflows/coc.yml
Normal file
75
.forgejo/workflows/coc.yml
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
name: Sync Code of Conduct
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'CODE_OF_CONDUCT.md'
|
||||
|
||||
jobs:
|
||||
sync-coc:
|
||||
runs-on: debian-trixie
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Sync
|
||||
env:
|
||||
TOKEN: ${{ secrets.SPACEBOT_PAT }}
|
||||
CURRENT_REPO: ${{ github.event.repository.name }}
|
||||
SERVER_URL: ${{ github.server_url }}
|
||||
TARGET_OWNER: "spacebar"
|
||||
run: |
|
||||
API_URL="${SERVER_URL}/api/v1/orgs/${TARGET_OWNER}/repos?limit=50"
|
||||
REPOS=$(curl -s -o /tmp/repos.json -w "%{http_code}" -H "Authorization: token $TOKEN" "$API_URL")
|
||||
|
||||
if [ "$REPOS" != "200" ]; then
|
||||
API_URL="${SERVER_URL}/api/v1/users/${TARGET_OWNER}/repos?limit=50"
|
||||
curl -s -H "Authorization: token $TOKEN" "$API_URL" > /tmp/repos.json
|
||||
fi
|
||||
|
||||
REPO_LIST=$(jq -r '.[].name' /tmp/repos.json 2>/dev/null)
|
||||
|
||||
if [ -z "$REPO_LIST" ] || [ "$REPO_LIST" = "null" ]; then
|
||||
echo "Error: No repositories found or failed to fetch for owner: $TARGET_OWNER"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
B64_TOKEN=$(echo -n "spacebot:$TOKEN" | base64 | tr -d '\n')
|
||||
|
||||
for REPO in $REPO_LIST; do
|
||||
if [ "$REPO" = "$CURRENT_REPO" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Processing repository: $REPO"
|
||||
|
||||
if ! git -c "http.extraHeader=Authorization: Basic $B64_TOKEN" clone "${SERVER_URL}/${TARGET_OWNER}/${REPO}.git" temp_repo 2>/dev/null; then
|
||||
echo "Skipping $REPO: Unable to clone or access denied."
|
||||
continue
|
||||
fi
|
||||
|
||||
cp CODE_OF_CONDUCT.md temp_repo/CODE_OF_CONDUCT.md
|
||||
|
||||
cd temp_repo
|
||||
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
git config user.name "spacebot"
|
||||
git config user.email "spacebot@noreply.spbr.net"
|
||||
|
||||
git add CODE_OF_CONDUCT.md
|
||||
git commit -m "chore: update COC according to spacebar/Pqqaaaqqolicy changes"
|
||||
|
||||
if git -c "http.extraHeader=Authorization: Basic $B64_TOKEN" push origin main 2>/dev/null || git -c "http.extraHeader=Authorization: Basic $B64_TOKEN" push origin master 2>/dev/null; then
|
||||
echo "successfully updated $REPO"
|
||||
else
|
||||
echo "skipping $REPO: Push failed (L bozo)"
|
||||
fi
|
||||
else
|
||||
echo "no changes detected for $REPO"
|
||||
fi
|
||||
|
||||
cd ..
|
||||
rm -rf temp_repo
|
||||
done
|
||||
Loading…
Reference in a new issue