Elffuss BraidHub

kikocis/continue public

438b2c9c3ac0 · 2.6 KiBRawPermalink
1import { beforeEach, describe, expect, it } from "vitest";
2
3import { getGitHubActionsRepoUrl, isGitHubActions } from "./git.js";
4
5describe("git utilities - GitHub Actions detection", () => {
6 beforeEach(() => {
7 // Clear environment variables
8 delete process.env.GITHUB_ACTIONS;
9 delete process.env.GITHUB_REPOSITORY;
10 delete process.env.GITHUB_SERVER_URL;
11 });
12
13 describe("isGitHubActions", () => {
14 it("should return true when GITHUB_ACTIONS is 'true'", () => {
15 process.env.GITHUB_ACTIONS = "true";
16 expect(isGitHubActions()).toBe(true);
17 });
18
19 it("should return false when GITHUB_ACTIONS is not set", () => {
20 expect(isGitHubActions()).toBe(false);
21 });
22
23 it("should return false when GITHUB_ACTIONS is set to other values", () => {
24 process.env.GITHUB_ACTIONS = "false";
25 expect(isGitHubActions()).toBe(false);
26 });
27 });
28
29 describe("getGitHubActionsRepoUrl", () => {
30 it("should return null when not in GitHub Actions", () => {
31 expect(getGitHubActionsRepoUrl()).toBeNull();
32 });
33
34 it("should return null when GITHUB_REPOSITORY is not set", () => {
35 process.env.GITHUB_ACTIONS = "true";
36 expect(getGitHubActionsRepoUrl()).toBeNull();
37 });
38
39 it("should return GitHub URL with default server", () => {
40 process.env.GITHUB_ACTIONS = "true";
41 process.env.GITHUB_REPOSITORY = "owner/repo";
42
43 expect(getGitHubActionsRepoUrl()).toBe("https://github.com/owner/repo");
44 });
45
46 it("should return GitHub URL with custom server", () => {
47 process.env.GITHUB_ACTIONS = "true";
48 process.env.GITHUB_REPOSITORY = "owner/repo";
49 process.env.GITHUB_SERVER_URL = "https://github.enterprise.com";
50
51 expect(getGitHubActionsRepoUrl()).toBe(
52 "https://github.enterprise.com/owner/repo",
53 );
54 });
55 });
56
57 describe("getRepoUrl - GitHub Actions priority", () => {
58 it("should prioritize GitHub Actions environment variables", () => {
59 process.env.GITHUB_ACTIONS = "true";
60 process.env.GITHUB_REPOSITORY = "owner/repo";
61
62 // Since we can't easily mock git commands, we'll rely on the fact that
63 // GitHub Actions detection should take priority and return immediately
64 const result = getGitHubActionsRepoUrl();
65 expect(result).toBe("https://github.com/owner/repo");
66 });
67
68 it("should work with GitHub Enterprise Server", () => {
69 process.env.GITHUB_ACTIONS = "true";
70 process.env.GITHUB_REPOSITORY = "enterprise/repo";
71 process.env.GITHUB_SERVER_URL = "https://git.company.com";
72
73 const result = getGitHubActionsRepoUrl();
74 expect(result).toBe("https://git.company.com/enterprise/repo");
75 });
76 });
77});