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 # 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) [![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/core": "^1.11.1",
"@actions/github": "^6.0.1", "@actions/github": "^6.0.1",
"@octokit/rest": "^22.0.0", "@octokit/rest": "^22.0.0",
"gitea-js": "^1.23.0",
"strip-ansi": "^7.1.0" "strip-ansi": "^7.1.0"
}, },
"devDependencies": { "devDependencies": {
@@ -4126,6 +4127,12 @@
"url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" "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": { "node_modules/glob-parent": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",
@@ -9493,6 +9500,11 @@
"resolve-pkg-maps": "^1.0.0" "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": { "glob-parent": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", "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/core": "^1.11.1",
"@actions/github": "^6.0.1", "@actions/github": "^6.0.1",
"@octokit/rest": "^22.0.0", "@octokit/rest": "^22.0.0",
"gitea-js": "^1.23.0",
"strip-ansi": "^7.1.0" "strip-ansi": "^7.1.0"
}, },
"devDependencies": { "devDependencies": {

View File

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

View File

@@ -1,20 +1,28 @@
import * as core from '@actions/core' 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 assignees: string[] | undefined
let labels: string[] | undefined let labels: number[] | undefined
if (core.getInput('issue_assignees')) { if (core.getInput('issue_assignees')) {
assignees = core.getInput('issue_assignees').replace(/\s+/g, '').split(',') assignees = core.getInput('issue_assignees').replace(/\s+/g, '').split(',')
} }
if (core.getInput('issue_labels')) { if (core.getInput('issue_labels')) {
labels = core labels = [];
.getInput('issue_labels') const labelNames = core
.split(',') .getInput('issue_labels')
.map((label) => label.trim()) .split(',')
.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 { return {
title: core.getInput('issue_title'), title: core.getInput('issue_title'),
body, body,
@@ -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( export async function getExistingIssueNumber(
getIssues: GetIssuesFunc, issues: HttpResponse<Issue[], any>,
repo: { repo: {
owner: string owner: string
repo: string repo: string
} }
): Promise<number | null> { ): Promise<number | null> {
const { data: issues } = await getIssues({ issues.data.forEach(iss => {
...repo, if (iss.title == core.getInput('issue_title')) {
state: 'open' return iss.number;
}
}) })
return null;
const iss = issues
.filter((i) => i.title === core.getInput('issue_title'))
.shift()
return iss?.number ?? null
} }

View File

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