|
9 | 9 | branches: [main] |
10 | 10 | pull_request_target: # zizmor: ignore[dangerous-triggers] maintainer-owned external dispatch; no checkout or untrusted PR code execution |
11 | 11 | types: [opened, reopened, synchronize, ready_for_review, edited, labeled, unlabeled] |
| 12 | + pull_request_review: |
| 13 | + types: [submitted, edited, dismissed] |
| 14 | + pull_request_review_comment: |
| 15 | + types: [created, edited] |
12 | 16 |
|
13 | 17 | permissions: |
14 | 18 | contents: read |
|
53 | 57 | permission-issues: write |
54 | 58 | permission-pull-requests: read |
55 | 59 |
|
| 60 | + - name: Dispatch GitHub activity to ClawSweeper |
| 61 | + env: |
| 62 | + GH_TOKEN: ${{ steps.token.outputs.token }} |
| 63 | + TARGET_REPO: ${{ github.repository }} |
| 64 | + SOURCE_EVENT: ${{ github.event_name }} |
| 65 | + SOURCE_ACTION: ${{ github.event.action }} |
| 66 | + ACTOR: ${{ github.actor }} |
| 67 | + run: | |
| 68 | + set -euo pipefail |
| 69 | + if [ -z "$GH_TOKEN" ]; then |
| 70 | + echo "::notice::Skipping GitHub activity dispatch because no ClawSweeper app token is configured." |
| 71 | + exit 0 |
| 72 | + fi |
| 73 | + activity="$(jq -c \ |
| 74 | + --arg target_repo "$TARGET_REPO" \ |
| 75 | + --arg event_name "$SOURCE_EVENT" \ |
| 76 | + --arg source_action "$SOURCE_ACTION" \ |
| 77 | + --arg actor "$ACTOR" \ |
| 78 | + ' |
| 79 | + def body_excerpt(value): |
| 80 | + if (value // "" | type) == "string" then |
| 81 | + ((value // "") | gsub("\\s+"; " ") | .[0:1200]) |
| 82 | + else null end; |
| 83 | + { |
| 84 | + type: $event_name, |
| 85 | + repo: $target_repo, |
| 86 | + action: $source_action, |
| 87 | + actor: $actor, |
| 88 | + subject: |
| 89 | + if .pull_request then { |
| 90 | + kind: "pull_request", |
| 91 | + number: .pull_request.number, |
| 92 | + title: .pull_request.title, |
| 93 | + url: .pull_request.html_url, |
| 94 | + state: (if .pull_request.merged == true then "merged" else .pull_request.state end) |
| 95 | + } elif .issue then { |
| 96 | + kind: (if .issue.pull_request then "pull_request" else "issue" end), |
| 97 | + number: .issue.number, |
| 98 | + title: .issue.title, |
| 99 | + url: .issue.html_url, |
| 100 | + state: .issue.state |
| 101 | + } elif $event_name == "push" then { |
| 102 | + kind: "push", |
| 103 | + title: (.head_commit.message // .after // "push"), |
| 104 | + url: (.head_commit.url // .compare), |
| 105 | + state: .ref |
| 106 | + } else { |
| 107 | + kind: $event_name |
| 108 | + } end, |
| 109 | + comment: (if .comment then { |
| 110 | + id: .comment.id, |
| 111 | + url: .comment.html_url, |
| 112 | + body_excerpt: body_excerpt(.comment.body) |
| 113 | + } else null end), |
| 114 | + review: (if .review then { |
| 115 | + id: .review.id, |
| 116 | + state: .review.state, |
| 117 | + url: .review.html_url, |
| 118 | + body_excerpt: body_excerpt(.review.body) |
| 119 | + } else null end), |
| 120 | + review_comment: (if .comment and $event_name == "pull_request_review_comment" then { |
| 121 | + id: .comment.id, |
| 122 | + path: .comment.path, |
| 123 | + line: (.comment.line // .comment.original_line), |
| 124 | + url: .comment.html_url, |
| 125 | + body_excerpt: body_excerpt(.comment.body) |
| 126 | + } else null end), |
| 127 | + push: (if $event_name == "push" then { |
| 128 | + before: .before, |
| 129 | + after: .after, |
| 130 | + ref: .ref, |
| 131 | + compare: .compare, |
| 132 | + head_commit: .head_commit.id |
| 133 | + } else null end), |
| 134 | + delivery_id: (.comment.id // .review.id // .pull_request.head.sha // .issue.updated_at // .after // env.GITHUB_RUN_ID) |
| 135 | + } | del(.. | nulls) |
| 136 | + ' "$GITHUB_EVENT_PATH")" |
| 137 | + payload="$(jq -nc --argjson activity "$activity" \ |
| 138 | + '{event_type:"github_activity",client_payload:{activity:$activity}}')" |
| 139 | + if gh api repos/openclaw/clawsweeper/dispatches \ |
| 140 | + --method POST \ |
| 141 | + --input - <<< "$payload"; then |
| 142 | + echo "Dispatched GitHub activity to ClawSweeper." |
| 143 | + else |
| 144 | + echo "::warning::Skipping GitHub activity dispatch because the configured credential could not dispatch to openclaw/clawsweeper." |
| 145 | + fi |
| 146 | +
|
56 | 147 | - name: Dispatch exact ClawSweeper review |
57 | | - if: ${{ github.event_name != 'push' && github.event_name != 'issue_comment' }} |
| 148 | + if: ${{ github.event_name == 'issues' || github.event_name == 'pull_request_target' }} |
58 | 149 | env: |
59 | 150 | GH_TOKEN: ${{ steps.token.outputs.token }} |
60 | 151 | TARGET_REPO: ${{ github.repository }} |
|
0 commit comments