Skip to content

Commit

Permalink
fix: expire inputs (abcxyz#43)
Browse files Browse the repository at this point in the history
To use [github.repository
context](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context)(The
owner and repository name. For example, octocat/Hello-World.) in the
caller workflow, make it easier for caller.
Below is an example caller
```
  close_pr:
    permissions:
      pull-requests: 'write'
    uses: 'abcxyz/access-on-demand/.github/workflows/expire.yml@main'
    with:
      repo: '${{ github.repository }}'
```
  • Loading branch information
sqin2019 authored Jun 20, 2023
1 parent cee65a3 commit dfe2515
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/expire.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ name: 'expire'
on:
workflow_call:
inputs:
owner:
description: 'The GitHub organization or repository owner.'
type: 'string'
required: true
repo:
description: 'The repository name.'
description: 'The owner and repository name. For example, Codertocat/Hello-World'
type: 'string'
required: true
expiryHours:
Expand All @@ -29,11 +25,17 @@ jobs:
result-encoding: 'string'
retries: 3
script: |-
const parts = String('${{ inputs.repo }}').split('/')
if (parts.length != 2) {
core.setFailed(`Input repo "${{ inputs.repo }}" is not in the right format "<owner>/<name>"`);
}
const repoOwner = parts[0]
const repoName = parts[1]
const cutoffMs = ${{ inputs.expiryHours }} * 60 * 60 * 1000
const now = new Date();
const pulls = await github.rest.pulls.list({
owner: '${{ inputs.owner }}',
repo: '${{ inputs.repo }}',
owner: repoOwner,
repo: repoName,
state: 'open',
per_page: 100,
});
Expand All @@ -46,8 +48,8 @@ jobs:
pulls.data.forEach(async (pull) => {
const files = await github.rest.pulls.listFiles({
owner: '${{ inputs.owner }}',
repo: '${{ inputs.repo }}',
owner: repoOwner,
repo: repoName,
pull_number: pull['number'],
})
Expand All @@ -64,8 +66,8 @@ jobs:
core.info(`Closing #${pull['number']} (${pull['title']})`);
await github.rest.pulls.update({
owner: '${{ inputs.owner }}',
repo: '${{ inputs.repo }}',
owner: repoOwner,
repo: repoName,
pull_number: pull['number'],
state: 'closed',
});
Expand Down

0 comments on commit dfe2515

Please sign in to comment.