From 372a8049d73c3d81bc46d6a77d7c904a614aea08 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Wed, 23 Jul 2025 09:15:02 +0200 Subject: [PATCH] Use `@actions/github` instead of `@octokit/core`. --- dist/cleanup/index.js | 45 +++++++++++++++++-------------------------- dist/main/index.js | 45 +++++++++++++++++-------------------------- package-lock.json | 1 - package.json | 1 - src/utils.ts | 45 ++++++++++++++++--------------------------- 5 files changed, 53 insertions(+), 84 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 3946ae8..58035be 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -79190,24 +79190,15 @@ exports.setNativeImageOption = setNativeImageOption; const c = __importStar(__nccwpck_require__(7242)); const core = __importStar(__nccwpck_require__(7484)); const github = __importStar(__nccwpck_require__(3228)); -const httpClient = __importStar(__nccwpck_require__(4844)); const semver = __importStar(__nccwpck_require__(2088)); const tc = __importStar(__nccwpck_require__(3472)); const fs = __importStar(__nccwpck_require__(9896)); const exec_1 = __nccwpck_require__(5236); const fs_1 = __nccwpck_require__(9896); -const core_1 = __nccwpck_require__(1897); const crypto_1 = __nccwpck_require__(6982); const path_1 = __nccwpck_require__(6928); const os_1 = __nccwpck_require__(857); -// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP) -const baseUrl = 'https://api.github.com'; -const GitHubDotCom = core_1.Octokit.defaults({ - baseUrl, - request: { - agent: new httpClient.HttpClient().getAgent(baseUrl) - } -}); +const utils_1 = __nccwpck_require__(8006); async function exec(commandLine, args, options) { const exitCode = await (0, exec_1.exec)(commandLine, args, options); if (exitCode !== 0) { @@ -79215,18 +79206,14 @@ async function exec(commandLine, args, options) { } } async function getLatestRelease(repo) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/releases/latest', { owner: c.GRAALVM_GH_USER, repo })).data; } async function getContents(repo, path) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { owner: c.GRAALVM_GH_USER, repo, @@ -79234,9 +79221,7 @@ async function getContents(repo, path) { })).data; } async function getTaggedRelease(owner, repo, tag) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { owner, repo, @@ -79244,9 +79229,7 @@ async function getTaggedRelease(owner, repo, tag) { })).data; } async function getMatchingTags(owner, repo, tagPrefix) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/git/matching-refs/tags/{tagPrefix}', { owner, repo, @@ -79314,15 +79297,23 @@ function toSemVer(version) { function isPREvent() { return process.env[c.ENV_GITHUB_EVENT_NAME] === c.EVENT_NAME_PULL_REQUEST; } -function getGitHubToken() { - return core.getInput(c.INPUT_GITHUB_TOKEN); +function getOctokit() { + /* Set up GitHub instance manually because @actions/github does not allow unauthenticated access */ + const GitHubWithPlugins = utils_1.GitHub.plugin(); + const token = core.getInput(c.INPUT_GITHUB_TOKEN); + if (token) { + return new GitHubWithPlugins({ auth: `token ${token}` }); + } + else { + return new GitHubWithPlugins(); /* unauthenticated */ + } } async function findExistingPRCommentId(bodyStartsWith) { if (!isPREvent()) { throw new Error('Not a PR event.'); } const context = github.context; - const octokit = github.getOctokit(getGitHubToken()); + const octokit = getOctokit(); try { const comments = await octokit.paginate(octokit.rest.issues.listComments, { ...context.repo, @@ -79342,7 +79333,7 @@ async function updatePRComment(content, commentId) { throw new Error('Not a PR event.'); } try { - await github.getOctokit(getGitHubToken()).rest.issues.updateComment({ + await getOctokit().rest.issues.updateComment({ ...github.context.repo, comment_id: commentId, body: content @@ -79358,7 +79349,7 @@ async function createPRComment(content) { } const context = github.context; try { - await github.getOctokit(getGitHubToken()).rest.issues.createComment({ + await getOctokit().rest.issues.createComment({ ...context.repo, issue_number: context.payload.pull_request?.number, body: content diff --git a/dist/main/index.js b/dist/main/index.js index 83082bc..3f2a75d 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -80484,24 +80484,15 @@ exports.setNativeImageOption = setNativeImageOption; const c = __importStar(__nccwpck_require__(7242)); const core = __importStar(__nccwpck_require__(7484)); const github = __importStar(__nccwpck_require__(3228)); -const httpClient = __importStar(__nccwpck_require__(4844)); const semver = __importStar(__nccwpck_require__(2088)); const tc = __importStar(__nccwpck_require__(3472)); const fs = __importStar(__nccwpck_require__(9896)); const exec_1 = __nccwpck_require__(5236); const fs_1 = __nccwpck_require__(9896); -const core_1 = __nccwpck_require__(1897); const crypto_1 = __nccwpck_require__(6982); const path_1 = __nccwpck_require__(6928); const os_1 = __nccwpck_require__(857); -// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP) -const baseUrl = 'https://api.github.com'; -const GitHubDotCom = core_1.Octokit.defaults({ - baseUrl, - request: { - agent: new httpClient.HttpClient().getAgent(baseUrl) - } -}); +const utils_1 = __nccwpck_require__(8006); async function exec(commandLine, args, options) { const exitCode = await (0, exec_1.exec)(commandLine, args, options); if (exitCode !== 0) { @@ -80509,18 +80500,14 @@ async function exec(commandLine, args, options) { } } async function getLatestRelease(repo) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/releases/latest', { owner: c.GRAALVM_GH_USER, repo })).data; } async function getContents(repo, path) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { owner: c.GRAALVM_GH_USER, repo, @@ -80528,9 +80515,7 @@ async function getContents(repo, path) { })).data; } async function getTaggedRelease(owner, repo, tag) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { owner, repo, @@ -80538,9 +80523,7 @@ async function getTaggedRelease(owner, repo, tag) { })).data; } async function getMatchingTags(owner, repo, tagPrefix) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/git/matching-refs/tags/{tagPrefix}', { owner, repo, @@ -80608,15 +80591,23 @@ function toSemVer(version) { function isPREvent() { return process.env[c.ENV_GITHUB_EVENT_NAME] === c.EVENT_NAME_PULL_REQUEST; } -function getGitHubToken() { - return core.getInput(c.INPUT_GITHUB_TOKEN); +function getOctokit() { + /* Set up GitHub instance manually because @actions/github does not allow unauthenticated access */ + const GitHubWithPlugins = utils_1.GitHub.plugin(); + const token = core.getInput(c.INPUT_GITHUB_TOKEN); + if (token) { + return new GitHubWithPlugins({ auth: `token ${token}` }); + } + else { + return new GitHubWithPlugins(); /* unauthenticated */ + } } async function findExistingPRCommentId(bodyStartsWith) { if (!isPREvent()) { throw new Error('Not a PR event.'); } const context = github.context; - const octokit = github.getOctokit(getGitHubToken()); + const octokit = getOctokit(); try { const comments = await octokit.paginate(octokit.rest.issues.listComments, { ...context.repo, @@ -80636,7 +80627,7 @@ async function updatePRComment(content, commentId) { throw new Error('Not a PR event.'); } try { - await github.getOctokit(getGitHubToken()).rest.issues.updateComment({ + await getOctokit().rest.issues.updateComment({ ...github.context.repo, comment_id: commentId, body: content @@ -80652,7 +80643,7 @@ async function createPRComment(content) { } const context = github.context; try { - await github.getOctokit(getGitHubToken()).rest.issues.createComment({ + await getOctokit().rest.issues.createComment({ ...context.repo, issue_number: context.payload.pull_request?.number, body: content diff --git a/package-lock.json b/package-lock.json index 5612ad0..bcc2969 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,6 @@ "@actions/io": "^1.1.3", "@actions/tool-cache": "^2.0.2", "@github/dependency-submission-toolkit": "^2.0.5", - "@octokit/core": "^5.2.0", "@octokit/types": "^14.1.0", "semver": "^7.7.2", "uuid": "^11.1.0" diff --git a/package.json b/package.json index b48f0cf..32fa642 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "@actions/http-client": "^2.2.3", "@actions/io": "^1.1.3", "@actions/tool-cache": "^2.0.2", - "@octokit/core": "^5.2.0", "@octokit/types": "^14.1.0", "@github/dependency-submission-toolkit": "^2.0.5", "semver": "^7.7.2", diff --git a/src/utils.ts b/src/utils.ts index c4edcd5..e071a9a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,25 +1,15 @@ import * as c from './constants' import * as core from '@actions/core' import * as github from '@actions/github' -import * as httpClient from '@actions/http-client' import * as semver from 'semver' import * as tc from '@actions/tool-cache' import * as fs from 'fs' import { ExecOptions, exec as e } from '@actions/exec' import { readFileSync, readdirSync } from 'fs' -import { Octokit } from '@octokit/core' import { createHash } from 'crypto' import { join } from 'path' import { tmpdir } from 'os' - -// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP) -const baseUrl = 'https://api.github.com' -const GitHubDotCom = Octokit.defaults({ - baseUrl, - request: { - agent: new httpClient.HttpClient().getAgent(baseUrl) - } -}) +import { GitHub } from '@actions/github/lib/utils' export async function exec(commandLine: string, args?: string[], options?: ExecOptions | undefined): Promise { const exitCode = await e(commandLine, args, options) @@ -29,9 +19,7 @@ export async function exec(commandLine: string, args?: string[], options?: ExecO } export async function getLatestRelease(repo: string): Promise { - const githubToken = getGitHubToken() - const options = githubToken.length > 0 ? { auth: githubToken } : {} - const octokit = new GitHubDotCom(options) + const octokit = getOctokit() return ( await octokit.request('GET /repos/{owner}/{repo}/releases/latest', { owner: c.GRAALVM_GH_USER, @@ -41,9 +29,7 @@ export async function getLatestRelease(repo: string): Promise { - const githubToken = getGitHubToken() - const options = githubToken.length > 0 ? { auth: githubToken } : {} - const octokit = new GitHubDotCom(options) + const octokit = getOctokit() return ( await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { owner: c.GRAALVM_GH_USER, @@ -58,9 +44,7 @@ export async function getTaggedRelease( repo: string, tag: string ): Promise { - const githubToken = getGitHubToken() - const options = githubToken.length > 0 ? { auth: githubToken } : {} - const octokit = new GitHubDotCom(options) + const octokit = getOctokit() return ( await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { owner, @@ -75,9 +59,7 @@ export async function getMatchingTags( repo: string, tagPrefix: string ): Promise { - const githubToken = getGitHubToken() - const options = githubToken.length > 0 ? { auth: githubToken } : {} - const octokit = new GitHubDotCom(options) + const octokit = getOctokit() return ( await octokit.request('GET /repos/{owner}/{repo}/git/matching-refs/tags/{tagPrefix}', { owner, @@ -156,8 +138,15 @@ export function isPREvent(): boolean { return process.env[c.ENV_GITHUB_EVENT_NAME] === c.EVENT_NAME_PULL_REQUEST } -function getGitHubToken(): string { - return core.getInput(c.INPUT_GITHUB_TOKEN) +function getOctokit(): InstanceType { + /* Set up GitHub instance manually because @actions/github does not allow unauthenticated access */ + const GitHubWithPlugins = GitHub.plugin() + const token = core.getInput(c.INPUT_GITHUB_TOKEN) + if (token) { + return new GitHubWithPlugins({ auth: `token ${token}` }) + } else { + return new GitHubWithPlugins() /* unauthenticated */ + } } export async function findExistingPRCommentId(bodyStartsWith: string): Promise { @@ -166,7 +155,7 @@ export async function findExistingPRCommentId(bodyStartsWith: string): Promise { } const context = github.context try { - await github.getOctokit(getGitHubToken()).rest.issues.createComment({ + await getOctokit().rest.issues.createComment({ ...context.repo, issue_number: context.payload.pull_request?.number as number, body: content