Skip to content

Commit 0b5603f

Browse files
shouichiGenPage
authored andcommitted
feat: add PULL_URL to environment variables
Background: It is convenient to have the PR URL available so that we can link the PR that triggers the infrastructure changes from the audit logging system. For example, the google cloud provider adds user-supplied justification into google cloud audit logging via `CLOUDSDK_CORE_REQUEST_REASON` environment variable. https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#request_reason
1 parent 684f2fa commit 0b5603f

9 files changed

+15
-6
lines changed

runatlantis.io/docs/custom-workflows.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ Or a custom command
467467
* `BASE_BRANCH_NAME` - Name of the base branch of the pull request (the branch that the pull request is getting merged into)
468468
* `PROJECT_NAME` - Name of the project configured in `atlantis.yaml`. If no project name is configured this will be an empty string.
469469
* `PULL_NUM` - Pull request number or ID, ex. `2`.
470+
* `PULL_URL` - Pull request URL, ex. `https://github.com/runatlantis/atlantis/pull/2`.
470471
* `PULL_AUTHOR` - Username of the pull request author, ex. `acme-user`.
471472
* `REPO_REL_DIR` - The relative path of the project in the repository. For example if your project is in `dir1/dir2/` then this will be set to `"dir1/dir2"`. If your project is at the root this will be `"."`.
472473
* `USER_NAME` - Username of the VCS user running command, ex. `acme-user`. During an autoplan, the user will be the Atlantis API user, ex. `atlantis`.

runatlantis.io/docs/post-workflow-hooks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ command](custom-workflows.html#custom-run-command).
7171
* `HEAD_COMMIT` - The sha256 that points to the head of the branch that is being pull requested into the base. If the pull request is from Bitbucket Cloud the string will only be 12 characters long because Bitbucket Cloud truncates its commit IDs.
7272
* `BASE_BRANCH_NAME` - Name of the base branch of the pull request (the branch that the pull request is getting merged into)
7373
* `PULL_NUM` - Pull request number or ID, ex. `2`.
74+
* `PULL_URL` - Pull request URL, ex. `https://github.com/runatlantis/atlantis/pull/2`.
7475
* `PULL_AUTHOR` - Username of the pull request author, ex. `acme-user`.
7576
* `DIR` - The absolute path to the root of the cloned repository.
7677
* `USER_NAME` - Username of the VCS user running command, ex. `acme-user`. During an autoplan, the user will be the Atlantis API user, ex. `atlantis`.

runatlantis.io/docs/pre-workflow-hooks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ command](custom-workflows.html#custom-run-command).
5555
* `HEAD_COMMIT` - The sha256 that points to the head of the branch that is being pull requested into the base. If the pull request is from Bitbucket Cloud the string will only be 12 characters long because Bitbucket Cloud truncates its commit IDs.
5656
* `BASE_BRANCH_NAME` - Name of the base branch of the pull request (the branch that the pull request is getting merged into)
5757
* `PULL_NUM` - Pull request number or ID, ex. `2`.
58+
* `PULL_URL` - Pull request URL, ex. `https://github.com/runatlantis/atlantis/pull/2`.
5859
* `PULL_AUTHOR` - Username of the pull request author, ex. `acme-user`.
5960
* `DIR` - The absolute path to the root of the cloned repository.
6061
* `USER_NAME` - Username of the VCS user running command, ex. `acme-user`. During an autoplan, the user will be the Atlantis API user, ex. `atlantis`.

server/core/runtime/post_workflow_hook_runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (wh DefaultPostWorkflowHookRunner) Run(ctx models.WorkflowHookCommandContex
3939
"HEAD_REPO_OWNER": ctx.HeadRepo.Owner,
4040
"PULL_AUTHOR": ctx.Pull.Author,
4141
"PULL_NUM": fmt.Sprintf("%d", ctx.Pull.Num),
42+
"PULL_URL": ctx.Pull.URL,
4243
"USER_NAME": ctx.User.Username,
4344
"OUTPUT_STATUS_FILE": outputFilePath,
4445
}

server/core/runtime/post_workflow_hook_runner_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func TestPostWorkflowHookRunner_Run(t *testing.T) {
5151
ExpErr: "exit status 127: running \"lkjlkj\" in",
5252
},
5353
{
54-
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 head_commit=$HEAD_COMMIT base_branch_name=$BASE_BRANCH_NAME pull_num=$PULL_NUM pull_author=$PULL_AUTHOR",
55-
ExpOut: "base_repo_name=basename base_repo_owner=baseowner head_repo_name=headname head_repo_owner=headowner head_branch_name=add-feat head_commit=12345abcdef base_branch_name=main pull_num=2 pull_author=acme\n",
54+
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 head_commit=$HEAD_COMMIT base_branch_name=$BASE_BRANCH_NAME pull_num=$PULL_NUM pull_url=$PULL_URL pull_author=$PULL_AUTHOR",
55+
ExpOut: "base_repo_name=basename base_repo_owner=baseowner head_repo_name=headname head_repo_owner=headowner head_branch_name=add-feat head_commit=12345abcdef base_branch_name=main pull_num=2 pull_url=https://github.com/runatlantis/atlantis/pull/2 pull_author=acme\n",
5656
},
5757
{
5858
Command: "echo user_name=$USER_NAME",
@@ -92,6 +92,7 @@ func TestPostWorkflowHookRunner_Run(t *testing.T) {
9292
},
9393
Pull: models.PullRequest{
9494
Num: 2,
95+
URL: "https://github.com/runatlantis/atlantis/pull/2",
9596
HeadBranch: "add-feat",
9697
HeadCommit: "12345abcdef",
9798
BaseBranch: "main",

server/core/runtime/pre_workflow_hook_runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (wh DefaultPreWorkflowHookRunner) Run(ctx models.WorkflowHookCommandContext
3939
"HEAD_REPO_OWNER": ctx.HeadRepo.Owner,
4040
"PULL_AUTHOR": ctx.Pull.Author,
4141
"PULL_NUM": fmt.Sprintf("%d", ctx.Pull.Num),
42+
"PULL_URL": ctx.Pull.URL,
4243
"USER_NAME": ctx.User.Username,
4344
"OUTPUT_STATUS_FILE": outputFilePath,
4445
}

server/core/runtime/pre_workflow_hook_runner_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func TestPreWorkflowHookRunner_Run(t *testing.T) {
5151
ExpErr: "exit status 127: running \"lkjlkj\" in",
5252
},
5353
{
54-
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 head_commit=$HEAD_COMMIT base_branch_name=$BASE_BRANCH_NAME pull_num=$PULL_NUM pull_author=$PULL_AUTHOR",
55-
ExpOut: "base_repo_name=basename base_repo_owner=baseowner head_repo_name=headname head_repo_owner=headowner head_branch_name=add-feat head_commit=12345abcdef base_branch_name=main pull_num=2 pull_author=acme\n",
54+
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 head_commit=$HEAD_COMMIT base_branch_name=$BASE_BRANCH_NAME pull_num=$PULL_NUM pull_url=$PULL_URL pull_author=$PULL_AUTHOR",
55+
ExpOut: "base_repo_name=basename base_repo_owner=baseowner head_repo_name=headname head_repo_owner=headowner head_branch_name=add-feat head_commit=12345abcdef base_branch_name=main pull_num=2 pull_url=https://github.com/runatlantis/atlantis/pull/2 pull_author=acme\n",
5656
},
5757
{
5858
Command: "echo user_name=$USER_NAME",
@@ -92,6 +92,7 @@ func TestPreWorkflowHookRunner_Run(t *testing.T) {
9292
},
9393
Pull: models.PullRequest{
9494
Num: 2,
95+
URL: "https://github.com/runatlantis/atlantis/pull/2",
9596
HeadBranch: "add-feat",
9697
HeadCommit: "12345abcdef",
9798
BaseBranch: "main",

server/core/runtime/run_step_runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (r *RunStepRunner) Run(ctx command.ProjectContext, command string, path str
5353
"PROJECT_NAME": ctx.ProjectName,
5454
"PULL_AUTHOR": ctx.Pull.Author,
5555
"PULL_NUM": fmt.Sprintf("%d", ctx.Pull.Num),
56+
"PULL_URL": ctx.Pull.URL,
5657
"REPO_REL_DIR": ctx.RepoRelDir,
5758
"USER_NAME": ctx.User.Username,
5859
"WORKSPACE": ctx.Workspace,

server/core/runtime/run_step_runner_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func TestRunStepRunner_Run(t *testing.T) {
7171
ExpOut: "workspace=myworkspace version=0.11.0 dir=$DIR planfile=$DIR/my::project::name-myworkspace.tfplan showfile=$DIR/my::project::name-myworkspace.json project=my/project/name\n",
7272
},
7373
{
74-
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 head_commit=$HEAD_COMMIT base_branch_name=$BASE_BRANCH_NAME pull_num=$PULL_NUM pull_author=$PULL_AUTHOR repo_rel_dir=$REPO_REL_DIR",
75-
ExpOut: "base_repo_name=basename base_repo_owner=baseowner head_repo_name=headname head_repo_owner=headowner head_branch_name=add-feat head_commit=12345abcdef base_branch_name=main pull_num=2 pull_author=acme repo_rel_dir=mydir\n",
74+
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 head_commit=$HEAD_COMMIT base_branch_name=$BASE_BRANCH_NAME pull_num=$PULL_NUM pull_url=$PULL_URL pull_author=$PULL_AUTHOR repo_rel_dir=$REPO_REL_DIR",
75+
ExpOut: "base_repo_name=basename base_repo_owner=baseowner head_repo_name=headname head_repo_owner=headowner head_branch_name=add-feat head_commit=12345abcdef base_branch_name=main pull_num=2 pull_url=https://github.com/runatlantis/atlantis/pull/2 pull_author=acme repo_rel_dir=mydir\n",
7676
},
7777
{
7878
Command: "echo user_name=$USER_NAME",
@@ -130,6 +130,7 @@ func TestRunStepRunner_Run(t *testing.T) {
130130
},
131131
Pull: models.PullRequest{
132132
Num: 2,
133+
URL: "https://github.com/runatlantis/atlantis/pull/2",
133134
HeadBranch: "add-feat",
134135
HeadCommit: "12345abcdef",
135136
BaseBranch: "main",

0 commit comments

Comments
 (0)