Files
npm-audit-action/src/issue.ts

51 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-12-09 21:31:55 +09:00
import * as core from '@actions/core'
import { IssueOption } from './interface.js'
2019-12-09 21:31:55 +09:00
export function getIssueOption(body: string): IssueOption {
let assignees: string[] | undefined
let labels: string[] | undefined
if (core.getInput('issue_assignees')) {
assignees = core.getInput('issue_assignees').replace(/\s+/g, '').split(',')
}
if (core.getInput('issue_labels')) {
2021-10-08 21:20:06 +09:00
labels = core
.getInput('issue_labels')
.split(',')
2025-05-05 06:20:37 +00:00
.map((label) => label.trim())
}
2019-12-09 21:31:55 +09:00
return {
title: core.getInput('issue_title'),
body,
assignees,
labels
2019-12-09 21:31:55 +09:00
}
}
export type GetIssuesFunc = (options: {
owner: string
repo: string
state: 'open' | 'closed' | 'all' | undefined
[key: string]: string | undefined // Allow additional properties
}) => Promise<{ data: Array<{ title: string; number: number }> }>
export async function getExistingIssueNumber(
getIssues: GetIssuesFunc,
repo: {
owner: string
repo: string
}
): Promise<number | null> {
const { data: issues } = await getIssues({
...repo,
state: 'open'
})
const iss = issues
2025-05-05 06:20:37 +00:00
.filter((i) => i.title === core.getInput('issue_title'))
.shift()
return iss?.number ?? null
}