|
| 1 | +name: 'List Pull Requests' |
| 2 | +description: 'list and put output pull requests' |
| 3 | +inputs: |
| 4 | + owner: |
| 5 | + description: 'The repository owner' |
| 6 | + required: true |
| 7 | + repository: |
| 8 | + description: 'The repository name' |
| 9 | + required: true |
| 10 | + token: |
| 11 | + description: 'The GitHub token used to create an authenticated client' |
| 12 | + default: ${{ github.token }} |
| 13 | + required: false |
| 14 | + labels: |
| 15 | + description: 'The labels on pull requests' |
| 16 | + required: false |
| 17 | + default: '' |
| 18 | + hours: |
| 19 | + description: 'Pull requests created within this many hours will be listed' |
| 20 | + required: false |
| 21 | + default: '' |
| 22 | +outputs: |
| 23 | + result: |
| 24 | + description: 'Pull requests to be listed' |
| 25 | + value: ${{ steps.list-pr.outputs.result }} |
| 26 | +runs: |
| 27 | + using: "composite" |
| 28 | + steps: |
| 29 | + # See https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests |
| 30 | + - name: List PRs |
| 31 | + uses: actions/github-script@v7 |
| 32 | + id: list-pr |
| 33 | + with: |
| 34 | + token: ${{ inputs.token }} |
| 35 | + result-encoding: string |
| 36 | + script: | |
| 37 | + const resp = await github.rest.pulls.list({ |
| 38 | + owner: '${{ inputs.owner }}', |
| 39 | + repo: '${{ inputs.repository }}', |
| 40 | + state: 'open', |
| 41 | + sort: 'created', |
| 42 | + per_page: 100 |
| 43 | + }).catch( |
| 44 | + e => { |
| 45 | + core.setFailed(e.message) |
| 46 | + } |
| 47 | + ); |
| 48 | +
|
| 49 | + const pr_numbers = resp.data.map(pr => pr.number); |
| 50 | + core.info(`prs: ${pr_numbers.join(",")}`); |
| 51 | +
|
| 52 | + const prs = resp.data.map(pr => { |
| 53 | + return { |
| 54 | + number: pr.number, |
| 55 | + title: pr.title, |
| 56 | + body: pr.body, |
| 57 | + state: pr.state, |
| 58 | + draft: pr.draft, |
| 59 | + created_at: pr.created_at, |
| 60 | + updated_at: pr.updated_at, |
| 61 | + closed_at: pr.closed_at, |
| 62 | + merged_at: pr.merged_at, |
| 63 | + html_url: pr.html_url, |
| 64 | + base: pr.base.ref, |
| 65 | + head: pr.head.ref, |
| 66 | + labels: pr.labels.map(label => label.name) |
| 67 | + }; |
| 68 | + }); |
0 commit comments