Skip to content

Commit 8fd18fc

Browse files
authored
fix: switch to GraphQL for issue assignment and PR checks (hiero-ledger#1746)
Signed-off-by: MontyPokemon <59332150+MonaaEid@users.noreply.github.com>
1 parent 080b05d commit 8fd18fc

2 files changed

Lines changed: 36 additions & 23 deletions

File tree

.github/scripts/bot-issue-reminder-no-pr.sh

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,31 @@ echo "$ALL_ISSUES_JSON" | jq -c '.' | while read -r ISSUE_JSON; do
132132
fi
133133

134134
# Get assignment time (use the last assigned event)
135-
ASSIGN_TS=$(gh api "repos/$REPO/issues/$ISSUE/events" \
136-
--jq ".[] | select(.event==\"assigned\") | .created_at" \
137-
| tail -n1)
135+
if ! ASSIGN_TS=$(gh api graphql -f query="
136+
query {
137+
repository(owner: \"${REPO%/*}\", name: \"${REPO#*/}\") {
138+
issue(number: $ISSUE) {
139+
timelineItems(itemTypes: [ASSIGNED_EVENT], last: 1) {
140+
nodes {
141+
... on AssignedEvent {
142+
createdAt
143+
assignee {
144+
__typename
145+
... on User { login }
146+
}
147+
}
148+
}
149+
}
150+
}
151+
}
152+
}
153+
" --jq '.data.repository.issue.timelineItems.nodes[0].createdAt' 2>&1); then
154+
echo "[WARN] GraphQL query failed for issue #$ISSUE: $ASSIGN_TS. Skipping."
155+
continue
156+
fi
138157

139-
if [ -z "$ASSIGN_TS" ]; then
140-
echo "[WARN] No assignment event found. Skipping."
158+
if [ -z "$ASSIGN_TS" ] || [ "$ASSIGN_TS" = "null" ]; then
159+
echo "[WARN] No assignment event found for issue #$ISSUE. Skipping."
141160
continue
142161
fi
143162

@@ -148,24 +167,17 @@ echo "$ALL_ISSUES_JSON" | jq -c '.' | while read -r ISSUE_JSON; do
148167
echo "[INFO] Days since assignment: $DIFF_DAYS"
149168

150169
# Check if any open PRs are linked to this issue
151-
PR_NUMBERS=$(gh api \
152-
-H "Accept: application/vnd.github.mockingbird-preview+json" \
153-
"repos/$REPO/issues/$ISSUE/timeline" \
154-
--jq ".[]
155-
| select(.event == \"cross-referenced\")
156-
| select(.source.issue.pull_request != null)
157-
| .source.issue.number" 2>/dev/null || true)
158-
159-
OPEN_PR_FOUND=""
160-
if [ -n "$PR_NUMBERS" ]; then
161-
for PR_NUM in $PR_NUMBERS; do
162-
PR_STATE=$(gh pr view "$PR_NUM" --repo "$REPO" --json state --jq '.state' 2>/dev/null || true)
163-
if [ "$PR_STATE" = "OPEN" ]; then
164-
OPEN_PR_FOUND="$PR_NUM"
165-
break
166-
fi
167-
done
168-
fi
170+
OPEN_PR_FOUND=$(gh api graphql -f query="
171+
query {
172+
repository(owner: \"${REPO%/*}\", name: \"${REPO#*/}\") {
173+
issue(number: $ISSUE) {
174+
closedByPullRequestsReferences(first: 100, includeClosedPrs: false) {
175+
nodes { number state }
176+
}
177+
}
178+
}
179+
}
180+
" --jq '[.data.repository.issue.closedByPullRequestsReferences.nodes[] | select(.state == "OPEN") | .number] | first // empty' 2>&1) || true
169181

170182
if [ -n "$OPEN_PR_FOUND" ]; then
171183
echo "[KEEP] An OPEN PR #$OPEN_PR_FOUND is linked to this issue → skip reminder."

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
299299
- Fixed broken project structure link in `CONTRIBUTING.md` (#1664)
300300
- Refactor spam list update logic and remove unused pull request creation step `.github/scripts/update-spam-list.js` `.github/workflows/cron-update-spam-list.yml`.
301301
- Ensure all Query sub-class `execute()` function to correctly propagate the optional `timeout` parameter.
302+
- Refactor assignment time retrieval and open PR check to use GraphQL API instead of REST API `.github/scripts/bot-issue-reminder-no-pr.sh` (#1746)
302303

303304
### Removed
304305

0 commit comments

Comments
 (0)