Skip to content

Commit

Permalink
Merge pull request #339 from runatlantis/remove-refreshing
Browse files Browse the repository at this point in the history
Remove "Refreshing..." output from top of plan.
  • Loading branch information
lkysow authored Oct 30, 2018
2 parents 6af4d79 + 16cdcf1 commit 3b91492
Show file tree
Hide file tree
Showing 21 changed files with 98 additions and 143 deletions.
15 changes: 12 additions & 3 deletions server/events/markdown_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (m *MarkdownRenderer) renderProjectResults(results []ProjectResult, common
Failure: result.Failure,
})
} else if result.PlanSuccess != nil {
result.PlanSuccess.TerraformOutput = m.fmtDiff(result.PlanSuccess.TerraformOutput)
result.PlanSuccess.TerraformOutput = m.fmtPlan(result.PlanSuccess.TerraformOutput)
if m.shouldUseWrappedTmpl(vcsHost, result.PlanSuccess.TerraformOutput) {
resultData.Rendered = m.renderTemplate(planSuccessWrappedTmpl, *result.PlanSuccess)
} else {
Expand Down Expand Up @@ -166,12 +166,21 @@ func (m *MarkdownRenderer) shouldUseWrappedTmpl(vcsHost models.VCSHostType, outp
return strings.Count(output, "\n") > maxUnwrappedLines
}

// fmtDiff uses regex's to remove any leading whitespace in front of the
// fmtPlan uses regex's to remove any leading whitespace in front of the
// terraform output so that the diff syntax highlighting works. Example:
// " - aws_security_group_rule.allow_all" =>
// "- aws_security_group_rule.allow_all"
// We do it for +, ~ and -.
func (m *MarkdownRenderer) fmtDiff(tfOutput string) string {
// It also removes the "Refreshing..." preamble.
func (m *MarkdownRenderer) fmtPlan(tfOutput string) string {
// Plan output contains a lot of "Refreshing..." lines followed by a
// separator. We want to remove everything before that separator.
refreshSeparator := "------------------------------------------------------------------------\n"
sepIdx := strings.Index(tfOutput, refreshSeparator)
if sepIdx > -1 {
tfOutput = tfOutput[sepIdx+len(refreshSeparator):]
}

tfOutput = plusDiffRegex.ReplaceAllString(tfOutput, "+")
tfOutput = tildeDiffRegex.ReplaceAllString(tfOutput, "~")
return minusDiffRegex.ReplaceAllString(tfOutput, "-")
Expand Down
6 changes: 0 additions & 6 deletions server/events/markdown_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,6 @@ Terraform will perform the following actions:
<details><summary>Show Output</summary>
$$$diff
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Expand Down
6 changes: 6 additions & 0 deletions server/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ func assertCommentEquals(t *testing.T, expFile string, act string, repoDir strin
idRegex := regexp.MustCompile(`Creation complete after [0-9]+s \(ID: [0-9]+\)`)
act = idRegex.ReplaceAllString(act, "Creation complete after *s (ID: ******************)")

// Replace all null_resource.simple{n} with null_resource.simple because with
// multiple resources they might be created at different times and so the
// output is unordered.
resourceRegex := regexp.MustCompile(`null_resource\.simple\d:`)
act = resourceRegex.ReplaceAllString(act, "null_resource.simple:")

if string(exp) != act {
// If in CI, we write the diff to the console. Otherwise we write the diff
// to file so we can use our local diff viewer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ Ran Plan for 2 projects:
1. workspace: `default` dir: `production`

### 1. workspace: `default` dir: `staging`
<details><summary>Show Output</summary>

```diff
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Expand All @@ -30,19 +22,10 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d staging`
</details>

---
### 2. workspace: `default` dir: `production`
<details><summary>Show Output</summary>

```diff
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Expand All @@ -61,7 +44,6 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d production`
</details>

---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
Ran Plan in dir: `staging` workspace: `default`

<details><summary>Show Output</summary>

```diff
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Expand All @@ -27,7 +19,6 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d staging`
</details>

---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
Ran Plan in dir: `production` workspace: `default`

<details><summary>Show Output</summary>

```diff
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Expand All @@ -27,7 +19,6 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d production`
</details>

---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
Ran Plan in dir: `staging` workspace: `default`

<details><summary>Show Output</summary>

```diff
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Expand All @@ -27,7 +19,6 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d staging`
</details>

---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
Expand Down
18 changes: 0 additions & 18 deletions server/testfixtures/test-repos/simple-yaml/exp-output-autoplan.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ Ran Plan for 2 projects:
1. workspace: `staging` dir: `.`

### 1. workspace: `default` dir: `.`
<details><summary>Show Output</summary>

```diff
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Expand All @@ -30,19 +22,10 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -d .`
</details>

---
### 2. workspace: `staging` dir: `.`
<details><summary>Show Output</summary>

```diff
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Expand All @@ -61,7 +44,6 @@ Plan: 1 to add, 0 to change, 0 to destroy.
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url)
* :repeat: To **plan** this project again, comment:
* `atlantis plan -w staging`
</details>

---
* :fast_forward: To **apply** all unapplied plans from this pull request, comment:
Expand Down
18 changes: 16 additions & 2 deletions server/testfixtures/test-repos/simple/exp-output-apply-var-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,47 @@ Ran Apply for 2 projects:
1. workspace: `new_workspace` dir: `.`

### 1. workspace: `default` dir: `.`
<details><summary>Show Output</summary>

```diff
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:

var = default_workspace
workspace = default

```
</details>

---
### 2. workspace: `new_workspace` dir: `.`
<details><summary>Show Output</summary>

```diff
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:

var = new_workspace
workspace = new_workspace

```
</details>

---

Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
Ran Apply in dir: `.` workspace: `default`

<details><summary>Show Output</summary>

```diff
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:

var = default_workspace
workspace = default

```
</details>

Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
Ran Apply in dir: `.` workspace: `new_workspace`

<details><summary>Show Output</summary>

```diff
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:

var = new_workspace
workspace = new_workspace

```
</details>

Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
Ran Apply in dir: `.` workspace: `default`

<details><summary>Show Output</summary>

```diff
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:

var = overridden
workspace = default

```
</details>

9 changes: 8 additions & 1 deletion server/testfixtures/test-repos/simple/exp-output-apply.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
Ran Apply in dir: `.` workspace: `default`

<details><summary>Show Output</summary>

```diff
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creating...
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)
null_resource.simple: Creation complete after *s (ID: ******************)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:

var = default
workspace = default

```
</details>

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ Ran Plan in dir: `.` workspace: `new_workspace`
<details><summary>Show Output</summary>

```diff
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
Expand All @@ -18,7 +12,13 @@ Terraform will perform the following actions:

+ null_resource.simple
id: <computed>
Plan: 1 to add, 0 to change, 0 to destroy.

+ null_resource.simple2
id: <computed>

+ null_resource.simple3
id: <computed>
Plan: 3 to add, 0 to change, 0 to destroy.

```

Expand Down
Loading

0 comments on commit 3b91492

Please sign in to comment.