From d2fb10ca44a7f2d5c381aa6dccf86ae3d9d0fff7 Mon Sep 17 00:00:00 2001 From: Admin <1+admin@noreply.git.dcntrlized.org> Date: Tue, 4 Aug 2026 23:34:46 +0100 Subject: [PATCH] fix: Tighten license autocommit bot to PRs, implement .licenseignore for ignoring specific files or directories --- .gitea/workflows/license.yml | 47 +++++++++++++++++++++--------------- .licenseignore | 18 ++++++++++++++ src/frontend/src/index.css | 17 ------------- src/frontend/vite.config.ts | 17 ------------- 4 files changed, 45 insertions(+), 54 deletions(-) create mode 100644 .licenseignore diff --git a/.gitea/workflows/license.yml b/.gitea/workflows/license.yml index 8d284af..0ae4acc 100644 --- a/.gitea/workflows/license.yml +++ b/.gitea/workflows/license.yml @@ -40,22 +40,15 @@ jobs: - name: Add AGPL-3.0 headers run: | - /tmp/addlicense \ - -f .license-header.tpl \ - -c "Dcntrlized" \ - -y "$(date +%Y)" \ - -ignore "node_modules/**" \ - -ignore ".agents/**" \ - -ignore ".impeccable/**" \ - -ignore ".vscode/**" \ - -ignore "src/frontend/src/components/ui/**" \ - -ignore "**/*.md" \ - -ignore "**/*.json" \ - -ignore "**/*.yaml" \ - -ignore "**/*.yml" \ - -ignore "**/*.lock" \ - -ignore "**/*.sum" \ - . + set -e + set -- -f .license-header.tpl -c "Dcntrlized" -y "$(date +%Y)" + while IFS= read -r line; do + case "$line" in + "" | \#*) continue ;; + esac + set -- "$@" -ignore "$line" + done < .licenseignore + /tmp/addlicense "$@" . - name: Commit and push changes env: @@ -82,13 +75,28 @@ jobs: echo "commit_sha=$SHA" >> "$GITHUB_ENV" - name: Comment on pull request - if: gitea.event_name == 'pull_request' && env.no_changes == 'false' + if: env.no_changes == 'false' env: TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ gitea.event.pull_request.number }} COMMIT_SHA: ${{ env.commit_sha }} COMMIT_URL: "${{ gitea.server_url }}/${{ gitea.repository }}/commit/${{ env.commit_sha }}" run: | + set -e + SERVER="${{ gitea.server_url }}" + REPO="${{ gitea.repository }}" + if [ "${{ gitea.event_name }}" = "pull_request" ]; then + PR_NUMBER="${{ gitea.event.pull_request.number }}" + else + OWNER="${REPO%%/*}" + BRANCH="${{ gitea.ref_name }}" + PR_NUMBER="$(curl -sS -H "Authorization: token ${TOKEN}" \ + "${SERVER}/api/v1/repos/${REPO}/pulls?state=open&limit=50" \ + | jq -r --arg b "$BRANCH" 'map(select(.head.ref == $b))[0].number // empty')" + if [ -z "$PR_NUMBER" ]; then + echo "No open pull request for branch ${BRANCH}; skipping comment." + exit 0 + fi + fi cat > /tmp/pr-comment.md <<'EOF' ## Uh oh! Unlicensed code detected! @@ -103,9 +111,8 @@ jobs: EOF sed -i "s|COMMIT_SHA|${COMMIT_SHA}|g; s|COMMIT_URL|${COMMIT_URL}|g" /tmp/pr-comment.md BODY="$(jq -n --rawfile b /tmp/pr-comment.md '{body:$b}')" - SERVER="${{ gitea.server_url }}" curl -sS -X POST \ - "${SERVER}/api/v1/repos/${{ gitea.repository }}/issues/${PR_NUMBER}/comments" \ + "${SERVER}/api/v1/repos/${REPO}/issues/${PR_NUMBER}/comments" \ -H "Authorization: token ${TOKEN}" \ -H "Content-Type: application/json" \ -d "$BODY" diff --git a/.licenseignore b/.licenseignore new file mode 100644 index 0000000..e3fa327 --- /dev/null +++ b/.licenseignore @@ -0,0 +1,18 @@ +# addlicense ignore patterns (doublestar globs, full relative paths). +# Blank lines and lines starting with # are skipped. No negation (!) support. + +**/node_modules/** +.agents/** +.impeccable/** +.vscode/** +src/frontend/src/components/ui/** +**/*.md +**/*.json +**/*.yaml +**/*.yml +**/*.lock +**/*.sum + +.licenseignore +src/frontend/src/index.css +src/frontend/vite.config.ts diff --git a/src/frontend/src/index.css b/src/frontend/src/index.css index cbb77b5..b429412 100644 --- a/src/frontend/src/index.css +++ b/src/frontend/src/index.css @@ -1,20 +1,3 @@ -/** - * Copyright (C) 2026 Dcntrlized - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - @import "tailwindcss"; @import "tw-animate-css"; @import "shadcn/tailwind.css"; diff --git a/src/frontend/vite.config.ts b/src/frontend/vite.config.ts index 546e985..71b90e0 100644 --- a/src/frontend/vite.config.ts +++ b/src/frontend/vite.config.ts @@ -1,20 +1,3 @@ -/** - * Copyright (C) 2026 Dcntrlized - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - import { defineConfig, type UserConfig } from 'vite' import preact from '@preact/preset-vite' import tailwindcss from '@tailwindcss/vite'