elastic / elastic/ai-github-actions

[framework-best-practices] Paginate conflicted-PR detection query in get-prs-with-merge-conflicts action

Open
#773 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
11
Forks
16
Avg merge
22h 9m
Merged PRs (30d)
31

Description

## Framework / Library Best Practices Findings

### 1. Conflicted-PR detector reads only the first GraphQL page
**Library:** GitHub GraphQL API (used via `actions/github-script@v7`)

**Library feature:** Cursor pagination with `pageInfo { hasNextPage endCursor }` and `after:`.

**Current code:**
- `.github/actions/get-prs-with-merge-conflicts/action.yml:76-93`
- `.github/actions/get-prs-with-merge-conflicts/action.yml:96`

The action currently queries:
```graphql
pullRequests(first: 100, states: OPEN, orderBy: { field: UPDATED_AT, direction: DESC }) {
nodes { number isDraft mergeStateStatus authorAssociation author { login } labels(first: 50) { nodes { name } } }
}
```
and immediately processes only `result.repository.pullRequests.nodes`.

**What is wrong:** The logic is single-page only; it never requests `pageInfo` nor follows `endCursor`.

**Why it matters (medium):** In repositories with more than 100 open PRs, conflicted PRs outside the first page are silently ignored. That can cause conflict-remediation workflows to miss eligible PRs.

**Simplification:** Replace the single fetch with GraphQL cursor pagination:
- Request `pageInfo { hasNextPage endCursor }` on `pullRequests`
- Loop with `after: $cursor` until `hasNextPage` is false
- Aggregate all nodes before applying the existing filters (`isDraft`, labels, association, `mergeStateStatus == "DIRTY"`)

**Documentation:**
- https://docs.github.com/en/graphql/guides/using-pagination-in-the-graphql-api
- https://docs.github.com/en/graphql/reference/objects#pullrequestconnection

## Suggested Actions
- [ ] Update `.github/actions/get-prs-with-merge-conflicts/action.yml` to paginate `pullRequests` via cursor-based GraphQL pagination.
- [ ] Add a regression test/fixture for multi-page open PR sets (>100) to prevent future truncation regressions.

> [!NOTE]
>
> 🔒 Integrity filtering filtered 106 items
>
> Integrity filtering activated and filtered the following items during workflow execution.
> This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.
>
> - issue:elastic/ai-github-actions#556 (`issue_read`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#565 (`issue_read`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#665 (`issue_read`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#673 (`issue_read`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#714 (`issue_read`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#771 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#770 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#769 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#768 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#766 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#765 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#759 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#757 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#756 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#753 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - issue:elastic/ai-github-actions#752 (`list_issues`: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)
> - ... and 90 more items
>
>

---
[What is this?](https://ela.st/github-ai-tools) | [From workflow: Trigger Framework Best Practices](https://github.com/elastic/ai-github-actions/actions/runs/23440033769)

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.