Skip to content

Commit 892174d

Browse files
feat(git-config): allow data.coder_workspace.me.owner_email to be blank (#222)
1 parent 24e50e2 commit 892174d

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

git-config/main.test.ts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
runTerraformApply,
4+
runTerraformInit,
5+
testRequiredVariables,
6+
} from "../test";
7+
8+
describe("git-config", async () => {
9+
await runTerraformInit(import.meta.dir);
10+
11+
testRequiredVariables(import.meta.dir, {
12+
agent_id: "foo",
13+
});
14+
15+
it("can run apply allow_username_change and allow_email_change disabled", async () => {
16+
const state = await runTerraformApply(import.meta.dir, {
17+
agent_id: "foo",
18+
allow_username_change: "false",
19+
allow_email_change: "false",
20+
});
21+
22+
const resources = state.resources;
23+
expect(resources).toHaveLength(3);
24+
expect(resources).toMatchObject([
25+
{ type: "coder_workspace", name: "me" },
26+
{ type: "coder_env", name: "git_author_name" },
27+
{ type: "coder_env", name: "git_commmiter_name" },
28+
]);
29+
});
30+
31+
it("can run apply allow_email_change enabled", async () => {
32+
const state = await runTerraformApply(import.meta.dir, {
33+
agent_id: "foo",
34+
allow_email_change: "true",
35+
});
36+
37+
const resources = state.resources;
38+
expect(resources).toHaveLength(5);
39+
expect(resources).toMatchObject([
40+
{ type: "coder_parameter", name: "user_email" },
41+
{ type: "coder_parameter", name: "username" },
42+
{ type: "coder_workspace", name: "me" },
43+
{ type: "coder_env", name: "git_author_name" },
44+
{ type: "coder_env", name: "git_commmiter_name" },
45+
]);
46+
});
47+
48+
it("can run apply allow_email_change enabled", async () => {
49+
const state = await runTerraformApply(
50+
import.meta.dir,
51+
{
52+
agent_id: "foo",
53+
allow_username_change: "false",
54+
allow_email_change: "false",
55+
},
56+
{ CODER_WORKSPACE_OWNER_EMAIL: "foo@emai.com" },
57+
);
58+
59+
const resources = state.resources;
60+
expect(resources).toHaveLength(5);
61+
expect(resources).toMatchObject([
62+
{ type: "coder_workspace", name: "me" },
63+
{ type: "coder_env", name: "git_author_email" },
64+
{ type: "coder_env", name: "git_author_name" },
65+
{ type: "coder_env", name: "git_commmiter_email" },
66+
{ type: "coder_env", name: "git_commmiter_name" },
67+
]);
68+
});
69+
});

git-config/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ resource "coder_env" "git_author_email" {
6565
agent_id = var.agent_id
6666
name = "GIT_AUTHOR_EMAIL"
6767
value = coalesce(try(data.coder_parameter.user_email[0].value, ""), data.coder_workspace.me.owner_email)
68+
count = data.coder_workspace.me.owner_email != "" ? 1 : 0
6869
}
6970

7071
resource "coder_env" "git_commmiter_email" {
7172
agent_id = var.agent_id
7273
name = "GIT_COMMITTER_EMAIL"
7374
value = coalesce(try(data.coder_parameter.user_email[0].value, ""), data.coder_workspace.me.owner_email)
75+
count = data.coder_workspace.me.owner_email != "" ? 1 : 0
7476
}

test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ export const testRequiredVariables = (
171171
export const runTerraformApply = async (
172172
dir: string,
173173
vars: Record<string, string>,
174+
env: Record<string, string> = {},
174175
): Promise<TerraformState> => {
175176
const stateFile = `${dir}/${crypto.randomUUID()}.tfstate`;
176-
const env = {};
177177
Object.keys(vars).forEach((key) => (env[`TF_VAR_${key}`] = vars[key]));
178178
const proc = spawn(
179179
[

0 commit comments

Comments
 (0)