Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
tranhl committed Dec 18, 2024
1 parent 5c95b2a commit 2813391
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 22 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ be done with the `perennial-branches` and `perennial-regex` inputs respectively:
Both inputs can be used at the same time. This action will merge the perennial
branches given into a single, de-duplicated list.

#### Skip Single Stacks
## Customization

### Skip Single Stacks

If you don't want the stack description to appear on pull requests which are not part of a stack, you can add `skip-single-stacks: true` to the job.

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ inputs:
skip-single-stacks:
required: false
default: false
history-limit:
required: false
default: 0

runs:
using: 'node20'
Expand Down
98 changes: 96 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@octokit/types": "^13.6.2",
"@types/node": "^20.11.30",
"@vercel/style-guide": "^5.2.0",
"editorconfig-checker": "5.1.8",
Expand Down
73 changes: 54 additions & 19 deletions src/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core'
import type * as github from '@actions/github'
import type { Endpoints } from '@octokit/types'
import { pullRequestSchema } from './types'
import type { PullRequest, Octokit } from './types'
import type { Config } from './config'
Expand All @@ -11,12 +12,27 @@ export const inputs = {

getSkipSingleStacks() {
core.startGroup('Inputs: Skip single stacks')
const input = core.getBooleanInput('skip-single-stacks', { required: false })
const input = core.getBooleanInput('skip-single-stacks', {
required: false,
trimWhitespace: true,
})
core.info(input.toString())
core.endGroup()
return input
},

getHistoryLimit() {
core.startGroup('Inputs: History limit')
const input = core.getInput('history-limit', {
required: false,
trimWhitespace: true,
})
const historyLimit = Number.parseInt(input, 10)
core.info(input)
core.endGroup()
return historyLimit
},

async getMainBranch(
octokit: Octokit,
config: Config | undefined,
Expand Down Expand Up @@ -117,24 +133,43 @@ export const inputs = {
},

async getPullRequests(octokit: Octokit, context: typeof github.context) {
const pullRequests = await octokit.paginate(
'GET /repos/{owner}/{repo}/pulls',
{
...context.repo,
state: 'all',
per_page: 100,
},
(response) =>
response.data.map(
(item): PullRequest => ({
number: item.number,
base: { ref: item.base.ref },
head: { ref: item.head.ref },
body: item.body ?? undefined,
state: item.state,
})
)
)
function toPullRequest(
item: Endpoints['GET /repos/{owner}/{repo}/pulls']['response']['data'][number]
): PullRequest {
return {
number: item.number,
base: { ref: item.base.ref },
head: { ref: item.head.ref },
body: item.body ?? undefined,
state: item.state,
}
}

const [openPullRequests, closedPullRequests] = await Promise.all([
octokit.paginate(
'GET /repos/{owner}/{repo}/pulls',
{
...context.repo,
state: 'open',
per_page: 100,
},
(response) => response.data.map(toPullRequest)
),

octokit.paginate(
'GET /repos/{owner}/{repo}/pulls',
{
...context.repo,
state: 'closed',
per_page: 100,
},
(response, done) => {
return response.data.map(toPullRequest)
}
),
])

const pullRequests = [...openPullRequests, ...closedPullRequests]
pullRequests.sort((a, b) => b.number - a.number)

core.startGroup('Inputs: Pull requests')
Expand Down

0 comments on commit 2813391

Please sign in to comment.