-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (153 loc) · 6.23 KB
/
task-or-bug.yml
File metadata and controls
175 lines (153 loc) · 6.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Issue updated → dispatch to coding agent
on:
issues:
types:
- opened
- edited
- reopened
- assigned
- unassigned
permissions:
contents: read
issues: read
# Optional: set in Settings → Variables → Repository variables
# CODING_AGENT_USER = <agent-gh-handle> (leave empty to disable the assignee filter)
env:
CODING_AGENT_USER: ${{ vars.CODING_AGENT_USER }}
concurrency:
group: issue-${{ github.event.issue.number }}-dispatch
cancel-in-progress: true
jobs:
dispatch:
# Only members/maintainers/collaborators can trigger runs from a public repo
if: ${{ contains(fromJSON('["thejhh","heusalagroupbot"]'), github.actor) }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Determine issue type and assignment (Issue Types only)
id: meta
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # gh uses GH_TOKEN
CODING_AGENT_USER: ${{ env.CODING_AGENT_USER }}
run: |
set -euo pipefail
OWNER="${GITHUB_REPOSITORY%/*}"
REPO="${GITHUB_REPOSITORY#*/}"
NUMBER="${{ github.event.issue.number }}"
# Query: issue type + assignees (no labels)
RESP="$(gh api graphql \
-H 'GraphQL-Features: issue_types' \
-f owner="$OWNER" \
-f repo="$REPO" \
-F number="$NUMBER" \
-f query='
query($owner:String!, $repo:String!, $number:Int!) {
repository(owner:$owner, name:$repo) {
issue(number:$number) {
number
title
issueType { name }
assignees(first: 100) { nodes { login } }
}
}
}'
)"
TYPE="$(jq -r '.data.repository.issue.issueType.name // empty' <<< "$RESP")"
# Optional assignee filter
RAW_AGENT="${CODING_AGENT_USER:-}"
AGENT_CLEAN="$(tr -d '\n' <<< "${RAW_AGENT#@}" | tr '[:upper:]' '[:lower:]')"
if [[ -z "$AGENT_CLEAN" ]]; then
ASSIGNED_OK="true"
else
ASSIGNED_OK="$(
jq -r --arg agent "$AGENT_CLEAN" '
[.data.repository.issue.assignees.nodes[].login // empty
| ascii_downcase] | index($agent) | if .==null then "false" else "true" end
' <<< "$RESP"
)"
fi
# Type filter: only "Task" or "Bug"
case "$(tr '[:upper:]' '[:lower:]' <<< "${TYPE}")" in
bug|task) TYPE_OK="true" ;;
*) TYPE_OK="false" ;;
esac
SHOULD=$([[ "$TYPE_OK" == "true" && "$ASSIGNED_OK" == "true" ]] && echo true || echo false)
{
echo "issue_type=${TYPE}"
echo "assigned_ok=${ASSIGNED_OK}"
echo "type_ok=${TYPE_OK}"
echo "should_dispatch=${SHOULD}"
echo "agent_user=${AGENT_CLEAN}"
} >> "$GITHUB_OUTPUT"
- name: Log & skip if not eligible
if: ${{ steps.meta.outputs.should_dispatch != 'true' }}
run: |
echo "Issue #${{ github.event.issue.number }} not eligible for dispatch."
echo " issue_type='${{ steps.meta.outputs.issue_type }}' (type_ok=${{ steps.meta.outputs.type_ok }})"
echo " assigned_ok=${{ steps.meta.outputs.assigned_ok }} agent='${{ steps.meta.outputs.agent_user }}'"
echo " Note: This workflow requires GitHub Issue Types ('Task' or 'Bug')."
- name: Build payload
if: ${{ steps.meta.outputs.should_dispatch == 'true' }}
id: payload
env:
ISSUE_TYPE: ${{ steps.meta.outputs.issue_type }}
AGENT_USER: ${{ steps.meta.outputs.agent_user }}
ASSIGNED_OK: ${{ steps.meta.outputs.assigned_ok }}
run: |
jq -n \
--arg repo "${{ github.repository }}" \
--argjson issue ${{ github.event.issue.number }} \
--arg url "${{ github.event.issue.html_url }}" \
--arg title "${{ github.event.issue.title }}" \
--arg actor "${{ github.actor }}" \
--arg action "${{ github.event.action }}" \
--arg issue_type "${ISSUE_TYPE:-}" \
--arg agent_user "${AGENT_USER:-}" \
--arg assigned_ok "${ASSIGNED_OK:-}" \
'{event_type:"coding_agent_dispatch",
client_payload:{
repo:$repo,
issue:$issue,
issue_html_url:$url,
issue_title:$title,
issue_actor:$actor,
issue_action:$action,
issue_type:$issue_type,
agent_user:$agent_user,
assigned_ok:$assigned_ok
}}' \
> payload.json
- name: Preflight (token & target repo access)
if: ${{ steps.meta.outputs.should_dispatch == 'true' }}
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
TARGET="hyperifyio/aibuddy"
if [[ -z "${GH_TOKEN:-}" ]]; then
echo "::error title=Missing secret::AIBUDDY_DISPATCH_PAT is not set."
exit 1
fi
# Verify token can access the private repo
if ! gh api "repos/$TARGET" >/dev/null 2>err.txt; then
echo "::error title=Token cannot access target repo::$TARGET not accessible with provided token."
cat err.txt || true
exit 1
fi
# Validate payload JSON
jq -e . payload.json >/dev/null || {
echo "::error title=Invalid payload::payload.json is not valid JSON"
cat payload.json
exit 1
}
- name: Send repository_dispatch to aibuddy (gh api)
if: ${{ steps.meta.outputs.should_dispatch == 'true' }}
env:
GH_TOKEN: ${{ secrets.AIBUDDY_DISPATCH_PAT }}
run: |
set -euo pipefail
gh api repos/hyperifyio/aibuddy/dispatches \
--method POST \
-H "Accept: application/vnd.github+json" \
--input payload.json
echo "repository_dispatch sent for issue #${{ github.event.issue.number }} (type=${{ steps.meta.outputs.issue_type }}, agent='${{ steps.meta.outputs.agent_user }}')"