fix: Tighten license autocommit bot to PRs, implement .licenseignore for ignoring specific files or directories
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user