Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose project name as an environment variable #577

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/events/runtime/run_step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command string, pa
"PULL_NUM": fmt.Sprintf("%d", ctx.Pull.Num),
"PULL_AUTHOR": ctx.Pull.Author,
"USER_NAME": ctx.User.Username,
"PROJECT_NAME": ctx.ProjectName,
nikovirtala marked this conversation as resolved.
Show resolved Hide resolved
}

finalEnvVars := baseEnvVars
Expand Down
7 changes: 4 additions & 3 deletions server/events/runtime/run_step_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func TestRunStepRunner_Run(t *testing.T) {
},
{
Command: "echo workspace=$WORKSPACE version=$ATLANTIS_TERRAFORM_VERSION dir=$DIR planfile=$PLANFILE",
ExpOut: "workspace=myworkspace version=0.11.0 dir=$DIR planfile=$DIR/myworkspace.tfplan\n",
ExpOut: "workspace=myworkspace version=0.11.0 dir=$DIR planfile=$DIR/myproject-myworkspace.tfplan\n",
},
{
Command: "echo base_repo_name=$BASE_REPO_NAME base_repo_owner=$BASE_REPO_OWNER head_repo_name=$HEAD_REPO_NAME head_repo_owner=$HEAD_REPO_OWNER head_branch_name=$HEAD_BRANCH_NAME base_branch_name=$BASE_BRANCH_NAME pull_num=$PULL_NUM pull_author=$PULL_AUTHOR",
ExpOut: "base_repo_name=basename base_repo_owner=baseowner head_repo_name=headname head_repo_owner=headowner head_branch_name=add-feat base_branch_name=master pull_num=2 pull_author=acme\n",
Command: "echo base_repo_name=$BASE_REPO_NAME base_repo_owner=$BASE_REPO_OWNER head_repo_name=$HEAD_REPO_NAME head_repo_owner=$HEAD_REPO_OWNER head_branch_name=$HEAD_BRANCH_NAME base_branch_name=$BASE_BRANCH_NAME pull_num=$PULL_NUM pull_author=$PULL_AUTHOR project_name=$PROJECT_NAME",
ExpOut: "base_repo_name=basename base_repo_owner=baseowner head_repo_name=headname head_repo_owner=headowner head_branch_name=add-feat base_branch_name=master pull_num=2 pull_author=acme project_name=myproject\n",
},
{
Command: "echo user_name=$USER_NAME",
Expand Down Expand Up @@ -87,6 +87,7 @@ func TestRunStepRunner_Run(t *testing.T) {
Workspace: "myworkspace",
RepoRelDir: "mydir",
TerraformVersion: projVersion,
ProjectName: "myproject",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ProjectName isn't always set, I'd like to test both cases. Can you make ProjectName part of the cases anonymous struct:

	cases := []struct {
		Command string
                 ProjectName string
		ExpOut  string
		ExpErr  string
	}{

(you'll also have to move the initialization of ctx to inside the t.Run() func)

And then you can test the case when it is and isn't set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully understand what you're looking for, and I (kind of) managed to implement it as well, but the implementation is not too DRY (two set of cases, two context declarations, and two loops to execute the tests), since my experience of programming, especially in golang, is closer to 0 than 100.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully understand what you're looking for, and I (kind of) managed to implement it as well, but the implementation is not too DRY (two set of cases, two context declarations, and two loops to execute the tests), since my experience of programming, especially in golang, is closer to 0 than 100.

All good, I've made a small change to your work here: #578 and will merge it from there

}
for _, c := range cases {
t.Run(c.Command, func(t *testing.T) {
Expand Down