From 537174131a9b6024d82d1f5b3cf4585d6b38868c Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 28 Jan 2026 16:29:31 +0100 Subject: [PATCH] replace direct octokit deps with @actions/github types Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/git.test.ts | 47 +++++++++++++++++++++++-------------------- package.json | 2 -- src/git.ts | 7 ++----- src/types/github.ts | 5 +++-- yarn.lock | 2 -- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index da495bb..54d5ad8 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -16,7 +16,7 @@ import {beforeEach, describe, expect, it, jest} from '@jest/globals'; -import {Git} from '../src/git'; +import {Git as GitMocked} from '../src/git'; import {Exec} from '../src/exec'; import {ExecOutput} from '@actions/exec'; @@ -46,7 +46,7 @@ describe('context', () => { exitCode: 0 }); }); - const ctx = await Git.context(); + const ctx = await GitMocked.context(); expect(ctx.ref).toEqual('refs/heads/test'); expect(ctx.sha).toEqual('test-sha'); }); @@ -56,7 +56,7 @@ describe('isInsideWorkTree', () => { it('have been called', async () => { const execSpy = jest.spyOn(Exec, 'getExecOutput'); try { - await Git.isInsideWorkTree(); + await GitMocked.isInsideWorkTree(); } catch { // noop } @@ -69,9 +69,12 @@ describe('isInsideWorkTree', () => { describe('remoteSha', () => { it('returns sha using git ls-remote', async () => { - expect(await Git.remoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head')).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa'); + expect(await GitMocked.remoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head')).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa'); }); it('returns sha using github api', async () => { + jest.resetModules(); + jest.unmock('@actions/github'); + const {Git} = await import('../src/git'); expect(await Git.remoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head', process.env.GITHUB_TOKEN)).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa'); }); }); @@ -80,7 +83,7 @@ describe('remoteURL', () => { it('have been called', async () => { const execSpy = jest.spyOn(Exec, 'getExecOutput'); try { - await Git.remoteURL(); + await GitMocked.remoteURL(); } catch { // noop } @@ -111,7 +114,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/heads/test'); }); @@ -135,7 +138,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/tags/8.0.0'); }); @@ -159,7 +162,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/tags/8.0.0'); }); @@ -183,7 +186,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/pull/221/merge'); }); @@ -207,7 +210,7 @@ describe('ref', () => { }); }); - await expect(Git.ref()).rejects.toThrow('Cannot find detached HEAD ref in "wrong, HEAD, tag: 8.0.0"'); + await expect(GitMocked.ref()).rejects.toThrow('Cannot find detached HEAD ref in "wrong, HEAD, tag: 8.0.0"'); }); it('returns mocked detached branch ref', async () => { @@ -229,7 +232,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/heads/test'); }); @@ -253,7 +256,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/heads/feature-branch'); }); @@ -280,7 +283,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/heads/main'); }); @@ -307,7 +310,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/heads/main'); }); @@ -337,7 +340,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/heads/feature'); }); @@ -370,7 +373,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/tags/v1.0.0'); }); @@ -403,7 +406,7 @@ describe('ref', () => { }); }); - await expect(Git.ref()).rejects.toThrow('Cannot infer ref from detached HEAD'); + await expect(GitMocked.ref()).rejects.toThrow('Cannot infer ref from detached HEAD'); }); it('handles remote ref without branch pattern when inferring from remote', async () => { @@ -431,7 +434,7 @@ describe('ref', () => { }); }); - const ref = await Git.ref(); + const ref = await GitMocked.ref(); expect(ref).toEqual('refs/remotes/unusual-format'); }); @@ -441,7 +444,7 @@ describe('fullCommit', () => { it('have been called', async () => { const execSpy = jest.spyOn(Exec, 'getExecOutput'); try { - await Git.fullCommit(); + await GitMocked.fullCommit(); } catch { // noop } @@ -456,7 +459,7 @@ describe('shortCommit', () => { it('have been called', async () => { const execSpy = jest.spyOn(Exec, 'getExecOutput'); try { - await Git.shortCommit(); + await GitMocked.shortCommit(); } catch { // noop } @@ -471,7 +474,7 @@ describe('tag', () => { it('have been called', async () => { const execSpy = jest.spyOn(Exec, 'getExecOutput'); try { - await Git.tag(); + await GitMocked.tag(); } catch { // noop } @@ -484,7 +487,7 @@ describe('tag', () => { describe('getCommitDate', () => { it('head', async () => { - const date = await Git.commitDate('HEAD'); + const date = await GitMocked.commitDate('HEAD'); await expect(date).toBeInstanceOf(Date); }); }); diff --git a/package.json b/package.json index e6b3969..a4f65de 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,6 @@ "@actions/io": "^2.0.0", "@actions/tool-cache": "^3.0.1", "@azure/storage-blob": "^12.29.1", - "@octokit/core": "^7.0.6", - "@octokit/plugin-rest-endpoint-methods": "^17.0.0", "@sigstore/bundle": "^4.0.0", "@sigstore/sign": "^4.1.0", "@sigstore/tuf": "^4.0.1", diff --git a/src/git.ts b/src/git.ts index b69f50b..7fb9fe6 100644 --- a/src/git.ts +++ b/src/git.ts @@ -16,9 +16,6 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; -import {Octokit} from '@octokit/core'; -import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'; - import {Exec} from './exec.js'; import {GitHub} from './github.js'; @@ -47,9 +44,9 @@ export class Git { // if we have a token and this is a GitHub repo we can use the GitHub API if (token && repoMatch) { core.setSecret(token); - const octokit = new (Octokit.plugin(restEndpointMethods).defaults({ + const octokit = github.getOctokit(token, { baseUrl: GitHub.apiURL - }))({auth: token}); + }); const [owner, repoName] = repoMatch.slice(1, 3); try { return ( diff --git a/src/types/github.ts b/src/types/github.ts index af184ef..9b4e77d 100644 --- a/src/types/github.ts +++ b/src/types/github.ts @@ -16,7 +16,7 @@ import * as core from '@actions/core'; import {AnnotationProperties} from '@actions/core'; -import {components as OctoOpenApiTypes} from '@octokit/openapi-types'; +import type {getOctokit} from '@actions/github'; import {JwtPayload} from 'jwt-decode'; import {BakeDefinition} from './buildx/bake.js'; @@ -39,7 +39,8 @@ export interface GitHubContentOpts { path: string; } -export type GitHubRepo = OctoOpenApiTypes['schemas']['repository']; +type Octokit = ReturnType; +export type GitHubRepo = Awaited>['data']; export interface GitHubActionsRuntimeToken extends JwtPayload { ac?: string; diff --git a/yarn.lock b/yarn.lock index b9c3668..b7d7490 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1200,8 +1200,6 @@ __metadata: "@eslint/compat": "npm:^2.0.0" "@eslint/eslintrc": "npm:^3.3.3" "@eslint/js": "npm:^9.39.2" - "@octokit/core": "npm:^7.0.6" - "@octokit/plugin-rest-endpoint-methods": "npm:^17.0.0" "@sigstore/bundle": "npm:^4.0.0" "@sigstore/rekor-types": "npm:^4.0.0" "@sigstore/sign": "npm:^4.1.0"