fix: Tighten license autocommit bot to PRs, implement .licenseignore for ignoring specific files or directories

This commit is contained in:
2026-08-04 23:34:46 +01:00
parent 04935427a1
commit d2fb10ca44
4 changed files with 45 additions and 54 deletions
+27 -20
View File
@@ -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"
+18
View File
@@ -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
-17
View File
@@ -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 <https://www.gnu.org/licenses/>.
*/
@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";
-17
View File
@@ -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 <https://www.gnu.org/licenses/>.
*/
import { defineConfig, type UserConfig } from 'vite'
import preact from '@preact/preset-vite'
import tailwindcss from '@tailwindcss/vite'