|
| 1 | +--- |
| 2 | +safe-inputs: |
| 3 | + fetch-pr-data: |
| 4 | + description: "Fetches pull request data from GitHub using gh CLI. Returns JSON array of PRs with fields: number, title, author, headRefName, createdAt, state, url, body, labels, updatedAt, closedAt, mergedAt" |
| 5 | + inputs: |
| 6 | + repo: |
| 7 | + type: string |
| 8 | + description: "Repository in owner/repo format (defaults to current repository)" |
| 9 | + required: false |
| 10 | + search: |
| 11 | + type: string |
| 12 | + description: "Search query for filtering PRs (e.g., 'head:copilot/' for Copilot PRs)" |
| 13 | + required: false |
| 14 | + state: |
| 15 | + type: string |
| 16 | + description: "PR state filter: open, closed, merged, or all (default: all)" |
| 17 | + default: "all" |
| 18 | + limit: |
| 19 | + type: number |
| 20 | + description: "Maximum number of PRs to fetch (default: 100)" |
| 21 | + default: 100 |
| 22 | + days: |
| 23 | + type: number |
| 24 | + description: "Number of days to look back (default: 30)" |
| 25 | + default: 30 |
| 26 | + run: | |
| 27 | + # Fetch PR data using gh CLI |
| 28 | + REPO="${INPUT_REPO:-$GITHUB_REPOSITORY}" |
| 29 | + STATE="${INPUT_STATE:-all}" |
| 30 | + LIMIT="${INPUT_LIMIT:-100}" |
| 31 | + DAYS="${INPUT_DAYS:-30}" |
| 32 | + SEARCH="${INPUT_SEARCH:-}" |
| 33 | + |
| 34 | + # Calculate date N days ago (cross-platform) |
| 35 | + DATE_AGO=$(date -d "${DAYS} days ago" '+%Y-%m-%d' 2>/dev/null || date -v-${DAYS}d '+%Y-%m-%d') |
| 36 | + |
| 37 | + # Build search query |
| 38 | + QUERY="created:>=${DATE_AGO}" |
| 39 | + if [ -n "$SEARCH" ]; then |
| 40 | + QUERY="${SEARCH} ${QUERY}" |
| 41 | + fi |
| 42 | + |
| 43 | + # Fetch PRs |
| 44 | + gh pr list --repo "$REPO" \ |
| 45 | + --search "$QUERY" \ |
| 46 | + --state "$STATE" \ |
| 47 | + --json number,title,author,headRefName,createdAt,state,url,body,labels,updatedAt,closedAt,mergedAt \ |
| 48 | + --limit "$LIMIT" |
| 49 | + env: |
| 50 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 51 | +--- |
| 52 | +<!-- |
| 53 | +## PR Data Fetch Safe Input Tool |
| 54 | +
|
| 55 | +This shared workflow provides a `fetch-pr-data` safe-input tool that fetches pull request data from GitHub. |
| 56 | +
|
| 57 | +### Usage |
| 58 | +
|
| 59 | +Import this shared workflow to get access to the `fetch-pr-data` tool: |
| 60 | +
|
| 61 | +```yaml |
| 62 | +imports: |
| 63 | + - shared/pr-data-safe-input.md |
| 64 | +``` |
| 65 | +
|
| 66 | +The agent can then use the tool to fetch PR data: |
| 67 | +- `fetch-pr-data` with no arguments returns PRs from the last 30 days |
| 68 | +- `fetch-pr-data` with `search: "head:copilot/"` returns Copilot agent PRs |
| 69 | +- `fetch-pr-data` with `state: "merged"` returns only merged PRs |
| 70 | +
|
| 71 | +### Parameters |
| 72 | +
|
| 73 | +| Parameter | Type | Default | Description | |
| 74 | +|-----------|------|---------|-------------| |
| 75 | +| repo | string | current repo | Repository in owner/repo format | |
| 76 | +| search | string | - | Search query (e.g., "head:copilot/") | |
| 77 | +| state | string | all | PR state: open, closed, merged, all | |
| 78 | +| limit | number | 100 | Maximum PRs to return | |
| 79 | +| days | number | 30 | Days to look back | |
| 80 | +
|
| 81 | +### Output |
| 82 | +
|
| 83 | +Returns JSON array with PR objects containing: |
| 84 | +- number, title, author, headRefName |
| 85 | +- createdAt, updatedAt, closedAt, mergedAt |
| 86 | +- state, url, body, labels |
| 87 | +--> |
0 commit comments