From d365345f80442379851dcaedac40ee995518f314 Mon Sep 17 00:00:00 2001 From: Matheus P Agostinho Date: Mon, 20 May 2024 16:18:22 -0300 Subject: [PATCH] chore: fix test --- __tests__/main.spec.js | 12 ++++++++---- src/main.js | 5 ++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/__tests__/main.spec.js b/__tests__/main.spec.js index 194df2f..966aa84 100644 --- a/__tests__/main.spec.js +++ b/__tests__/main.spec.js @@ -1,5 +1,5 @@ import { getInput, setFailed } from '@actions/core' -import { context as _context } from '@actions/github' +import { context as githubContext } from '@actions/github' import { Octokit } from '@octokit/core' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -33,7 +33,13 @@ vi.mock('@actions/github', async importActual => { return { ...actual, context: { - ref: 'refs/heads/test-branch' + payload: { + pull_request: { + head: { + ref: 'test-branch' + } + } + } } } }) @@ -48,8 +54,6 @@ describe('GitHub Action', () => { } Octokit.mockImplementation(() => octokitMock) - - _context.ref = 'refs/heads/test-branch' }) afterEach(() => { diff --git a/src/main.js b/src/main.js index 7895c65..6be05a5 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,5 @@ import { getInput, setFailed, setOutput } from '@actions/core' -import { context } from '@actions/github' +import { context as githubContext } from '@actions/github' import { Octokit } from '@octokit/core' export async function listDeployments(octokit, owner, repo) { @@ -50,8 +50,7 @@ export async function run() { const owner = getInput('owner', { required: true }) const repo = getInput('repo', { required: true }) - const ref = context.ref - const branch = ref.replace('refs/heads/', '') + const branch = githubContext.payload.pull_request.head.ref console.log(`Branch: ${branch}`)