Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smac89 committed Nov 16, 2022
1 parent f5b8686 commit ad9e9bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as core from "@actions/core";
import { context } from "@actions/github";
import { Octokit as GitHub } from "@octokit/core";
import { context, getOctokit } from "@actions/github";
import SemVer from "semver/classes/semver";
import coerce from "semver/functions/coerce";
import semverGt from "semver/functions/gt";
Expand All @@ -9,6 +8,7 @@ import semverParse from "semver/functions/parse";
import valid from "semver/functions/valid";
import { GraphQlQueryRepository, LatestRelease, preferences, queryAllRefs, TaggedRelease } from ".";

type GitHub = ReturnType<typeof getOctokit>;

namespace Functions {

Expand Down Expand Up @@ -50,7 +50,7 @@ namespace Functions {
export function releaseTag(): SemVer {
let tagName: string | SemVer = context.payload.release?.tag_name;
if (isPreRelease()) {
tagName = coerce(tagName, { includePrerelease: true });
tagName = coerce(tagName);
}
return semverParse(tagName);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ namespace Functions {
* @param refName The name of the ref to use. ex tags/latest, heads/v1, etc
*/
async function createRef(github: GitHub, refName: string) {
const { data: matchingRefs } = await github.git.listMatchingRefs({
const { data: matchingRefs } = await github.rest.git.listMatchingRefs({
...context.repo,
ref: refName,
});
Expand All @@ -198,15 +198,15 @@ namespace Functions {

if (matchingRef !== undefined) {
core.info(`Updating ref: ${refName} to: ${process.env.GITHUB_SHA}`);
({ data: upstreamRef } = await github.git.updateRef({
({ data: upstreamRef } = await github.rest.git.updateRef({
...context.repo,
force: true,
ref: refName,
sha: process.env.GITHUB_SHA,
}));
} else {
core.info(`Creating ref: refs/${refName} for: ${process.env.GITHUB_SHA}`);
({ data: upstreamRef } = await github.git.createRef({
({ data: upstreamRef } = await github.rest.git.createRef({
...context.repo,
ref: `refs/${refName}`,
sha: process.env.GITHUB_SHA,
Expand Down
8 changes: 4 additions & 4 deletions tests/functions.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Octokit } from "@octokit/core";
import { getOctokit } from "@actions/github";

beforeEach(() => jest.resetModules());
afterEach(() => jest.restoreAllMocks());

describe("getPreferredRef()", () => {
it("Should be heads", () => {
it("Should be heads", async () => {
process.env.INPUT_PREFER_BRANCH_RELEASES = "true";
return import("src/functions").then(({ default: { getPreferredRef } }) =>
expect(getPreferredRef()).toBe("heads")
);
});

it("Should be tags", () => {
it("Should be tags", async () => {
process.env.INPUT_PREFER_BRANCH_RELEASES = "false";
return import("src/functions").then(({ default: { getPreferredRef } }) =>
expect(getPreferredRef()).toBe("tags")
Expand All @@ -24,7 +24,7 @@ describe("findLatestReleases()", () => {
process.env.GITHUB_REPOSITORY = "test/test";
});

const octokit = new Octokit();
const octokit = getOctokit("TEST_TOKEN");

it("Should find the latest release when only one release exists", async () => {
const currentTag = '3.0.1';
Expand Down

0 comments on commit ad9e9bd

Please sign in to comment.