Port to Gitea-js
Some checks failed
Check Transpiled JavaScript / Check dist/ (push) Failing after 1m11s
build-test / build (20, ubuntu-latest) (push) Failing after 34s
build-test / test (20, ubuntu-latest) (push) Failing after 16s
build-test / build (20, macos-latest) (push) Has been cancelled
build-test / build-on-windows (20) (push) Has been cancelled
build-test / test (20, macos-latest) (push) Has been cancelled

This commit is contained in:
Dark Steveneq
2026-01-20 09:43:56 +01:00
parent 36d8041811
commit 68352b848f
7 changed files with 53 additions and 56 deletions

View File

@@ -1,3 +1,6 @@
[!INFO]
This repo is a scuffed Gitea port of the [original](https://github.com/oke-py/npm-audit-action) project
# npm audit action
[![Coverage Status](https://coveralls.io/repos/github/oke-py/npm-audit-action/badge.svg?branch=main)](https://coveralls.io/github/oke-py/npm-audit-action?branch=main)

12
package-lock.json generated
View File

@@ -12,6 +12,7 @@
"@actions/core": "^1.11.1",
"@actions/github": "^6.0.1",
"@octokit/rest": "^22.0.0",
"gitea-js": "^1.23.0",
"strip-ansi": "^7.1.0"
},
"devDependencies": {
@@ -4126,6 +4127,12 @@
"url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
}
},
"node_modules/gitea-js": {
"version": "1.23.0",
"resolved": "https://registry.npmjs.org/gitea-js/-/gitea-js-1.23.0.tgz",
"integrity": "sha512-f4+UPoWgDetZeZ+Awo5iI1nVdO5bjxA8+2QCeLo3oYWUYxKyzLfXgbW1EPD635wb8hLgS0DRBu5XhtiuYKEeUA==",
"license": "MIT"
},
"node_modules/glob-parent": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",
@@ -9493,6 +9500,11 @@
"resolve-pkg-maps": "^1.0.0"
}
},
"gitea-js": {
"version": "1.23.0",
"resolved": "https://registry.npmjs.org/gitea-js/-/gitea-js-1.23.0.tgz",
"integrity": "sha512-f4+UPoWgDetZeZ+Awo5iI1nVdO5bjxA8+2QCeLo3oYWUYxKyzLfXgbW1EPD635wb8hLgS0DRBu5XhtiuYKEeUA=="
},
"glob-parent": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",

View File

@@ -37,6 +37,7 @@
"@actions/core": "^1.11.1",
"@actions/github": "^6.0.1",
"@octokit/rest": "^22.0.0",
"gitea-js": "^1.23.0",
"strip-ansi": "^7.1.0"
},
"devDependencies": {

View File

@@ -1,6 +0,0 @@
export interface IssueOption {
title: string
body: string
assignees?: string[]
labels?: string[]
}

View File

@@ -1,19 +1,27 @@
import * as core from '@actions/core'
import { IssueOption } from './interface.js'
import * as github from '@actions/github'
import { Api, CreateIssueOption, HttpResponse, Issue } from 'gitea-js'
export function getIssueOption(body: string): IssueOption {
export async function getIssueOption(api: Api<unknown>, body: string): Promise<CreateIssueOption> {
let assignees: string[] | undefined
let labels: string[] | undefined
let labels: number[] | undefined
if (core.getInput('issue_assignees')) {
assignees = core.getInput('issue_assignees').replace(/\s+/g, '').split(',')
}
if (core.getInput('issue_labels')) {
labels = core
labels = [];
const labelNames = core
.getInput('issue_labels')
.split(',')
.map((label) => label.trim())
.map((label) => label.trim());
(await api.repos.issueListLabels(github.context.repo.owner, github.context.repo.repo)).data.forEach(label => {
if (label.name && label.id && labelNames.includes(label.name)) {
labels?.push(label.id);
}
})
}
return {
title: core.getInput('issue_title'),
@@ -23,28 +31,17 @@ export function getIssueOption(body: string): IssueOption {
}
}
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,
issues: HttpResponse<Issue[], any>,
repo: {
owner: string
repo: string
}
): Promise<number | null> {
const { data: issues } = await getIssues({
...repo,
state: 'open'
})
const iss = issues
.filter((i) => i.title === core.getInput('issue_title'))
.shift()
return iss?.number ?? null
issues.data.forEach(iss => {
if (iss.title == core.getInput('issue_title')) {
return iss.number;
}
})
return null;
}

View File

@@ -1,11 +1,10 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import { Octokit } from '@octokit/rest'
import { Audit } from './audit.js'
import { IssueOption } from './interface.js'
import * as issue from './issue.js'
import * as pr from './pr.js'
import * as workdir from './workdir.js'
import { CreateIssueOption, giteaApi } from 'gitea-js'
export async function run(): Promise<void> {
try {
@@ -70,10 +69,11 @@ export async function run(): Promise<void> {
// vulnerabilities are found
// get GitHub information
const ctx = JSON.parse(core.getInput('github_context'))
const token: string = core.getInput('github_token', { required: true })
const octokit = new Octokit({
auth: token
const ctx = JSON.parse(core.getInput('gitea_context'))
const baseUrl: string = core.getInput('gitea_url', { required: true })
const token: string = core.getInput('gitea_token', { required: true })
const api = giteaApi(baseUrl, {
token: token
})
if (ctx.event_name === 'pull_request') {
@@ -84,7 +84,7 @@ export async function run(): Promise<void> {
if (createPRComments === 'true') {
await pr.createComment(
octokit,
api,
github.context.repo.owner,
github.context.repo.repo,
ctx.event.number,
@@ -107,28 +107,21 @@ export async function run(): Promise<void> {
// remove control characters and create a code block
const issueBody = audit.strippedStdout()
const option: IssueOption = issue.getIssueOption(issueBody)
const option: CreateIssueOption = await issue.getIssueOption(api, issueBody)
const existingIssueNumber =
core.getInput('dedupe_issues') === 'true'
? await issue.getExistingIssueNumber(
octokit.issues.listForRepo,
await api.repos.issueListIssues(github.context.repo.owner, github.context.repo.repo, {state: "all"}),
github.context.repo
)
: null
if (existingIssueNumber !== null) {
const { data: createdComment } = await octokit.issues.createComment({
...github.context.repo,
issue_number: existingIssueNumber,
body: option.body
})
core.debug(`comment ${createdComment.url}`)
const { data: createdComment } = await api.repos.issueCreateComment(github.context.repo.owner, github.context.repo.repo, existingIssueNumber, {body: option.body ?? ""})
core.debug(`comment ${createdComment.issue_url}`)
} else {
const { data: createdIssue } = await octokit.issues.create({
...github.context.repo,
...option
})
const { data: createdIssue } = await api.repos.issueCreateIssue(github.context.repo.owner, github.context.repo.repo, option)
core.debug(`#${createdIssue.number}`)
}
core.setFailed('This repo has some vulnerabilities')

View File

@@ -1,16 +1,13 @@
import { Octokit } from '@octokit/rest'
import { Api } from "gitea-js";
export async function createComment(
octokit: Octokit,
api: Api<unknown>,
owner: string,
repo: string,
prNumber: number,
body: string
): Promise<void> {
await octokit.issues.createComment({
owner,
repo,
issue_number: prNumber,
await api.repos.issueCreateComment(owner, repo, prNumber, {
body
})
});
}