diff --git a/.github/workflows/webhook-commit.yml b/.github/workflows/webhook-commit.yml index 5e01c9c..d7cfd33 100644 --- a/.github/workflows/webhook-commit.yml +++ b/.github/workflows/webhook-commit.yml @@ -4,14 +4,8 @@ on: push: branches: - '**' - pull_request: - types: [closed] jobs: - # ────────────────────────────────────────────────────────────── - # Job 1: Per-commit notifications — only for direct pushes, - # NOT for pushes that belong to an open pull request. - # ────────────────────────────────────────────────────────────── discord_commit_notify: if: github.event_name == 'push' && github.event.pull_request == null runs-on: ubuntu-latest @@ -20,6 +14,7 @@ jobs: REPO: ${{ github.repository }} GITHUB_EVENT_PATH: ${{ github.event_path }} REF: ${{ github.ref }} + GITHUB_TOKEN: ${{ github.token }} steps: - name: Checkout (optional) uses: actions/checkout@v4 @@ -50,7 +45,7 @@ jobs: cat > /tmp/discord_payload.py <<'PY' import os, json, datetime, time - + sha = os.environ.get('SHA', '') msg = os.environ.get('COMMIT_MSG', '').strip().replace('\r', '') author = os.environ.get('AUTHOR', 'unknown') @@ -59,7 +54,7 @@ jobs: branch = os.environ.get('BRANCH', '') short_sha = sha[:7] if sha else "(no sha)" commit_url = f"https://github.com/{repo}/commit/{sha}" if sha else "" - + try: if timestamp: dt = datetime.datetime.fromisoformat(timestamp.replace('Z', '+00:00')) @@ -68,11 +63,11 @@ jobs: unix_time = int(time.time()) except Exception: unix_time = int(time.time()) - + lines = msg.split("\n", 1) title = lines[0].strip() if lines and lines[0].strip() != "" else "(no title)" body = lines[1].strip() if len(lines) > 1 else "" - + embed = { "author": { "name": author, @@ -89,7 +84,7 @@ jobs: ], "color": 7506394 } - + print(json.dumps({"embeds": [embed]}, ensure_ascii=False)) PY @@ -101,6 +96,18 @@ jobs: author_email=$(echo "$commit_json" | jq -r '.author.email // empty') timestamp=$(echo "$commit_json" | jq -r '.timestamp // empty') + # Skip commits that are associated with a PR + pr_count=$(curl -s \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$REPO/commits/$sha/pulls" \ + | jq 'if type == "array" then length else 0 end') + + if [ "$pr_count" -gt 0 ]; then + echo "Skipping commit $sha — associated with a PR" + continue + fi + if [ -n "$author_username" ]; then author="$author_username" elif [ -n "$author_name" ]; then