Skip to content

Commit

Permalink
Merge branch 'main' into remove_allow_repo_config
Browse files Browse the repository at this point in the history
  • Loading branch information
GenPage authored Dec 12, 2023
2 parents 20d8546 + 95c5fe0 commit f07635a
Show file tree
Hide file tree
Showing 16 changed files with 335 additions and 56 deletions.
2 changes: 2 additions & 0 deletions runatlantis.io/docs/using-atlantis.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ Runs `terraform apply` for the plan that matches the directory/project/workspace
::: tip
If no directory/project/workspace is specified, ex. `atlantis apply`, this command will apply **all unapplied plans from this pull request**.
This includes all projects that have been planned manually with `atlantis plan` `-p`/`-d`/`-w` since the last autoplan or `atlantis plan` command.
For Atlantis commands to work, Atlantis needs to know the location where the plan file is. For that, you can use $PLANFILE which will contain the path of the plan file to be used in your custom steps. i.e `terraform plan -out $PLANFILE`
:::


### Examples
```bash
# Runs apply for all unapplied plans from this pull request.
Expand Down
38 changes: 36 additions & 2 deletions server/controllers/templates/web_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"html/template"
"io"
"time"

"github.com/runatlantis/atlantis/server/jobs"
)

//go:generate pegomock generate --package mocks -o mocks/mock_template_writer.go TemplateWriter
Expand Down Expand Up @@ -50,7 +52,9 @@ type ApplyLockData struct {

// IndexData holds the data for rendering the index page
type IndexData struct {
Locks []LockIndexData
Locks []LockIndexData
PullToJobMapping []jobs.PullInfoWithJobIDs

ApplyLock ApplyLockData
AtlantisVersion string
// CleanedBasePath is the path Atlantis is accessible at externally. If
Expand Down Expand Up @@ -113,8 +117,8 @@ var IndexTemplate = template.Must(template.New("index.html.tmpl").Parse(`
<br>
<section>
<p class="title-heading small"><strong>Locks</strong></p>
{{ if .Locks }}
{{ $basePath := .CleanedBasePath }}
{{ if .Locks }}
<div class="lock-grid">
<div class="lock-header">
<span>Repository</span>
Expand Down Expand Up @@ -151,6 +155,36 @@ var IndexTemplate = template.Must(template.New("index.html.tmpl").Parse(`
<p class="placeholder">No locks found.</p>
{{ end }}
</section>
<br>
<br>
<br>
<section>
<p class="title-heading small"><strong>Jobs</strong></p>
{{ if .PullToJobMapping }}
<div class="pulls-grid">
<div class="lock-header">
<span>Repository</span>
<span>Project</span>
<span>Workspace</span>
<span>Jobs</span>
</div>
{{ range .PullToJobMapping }}
<div class="pulls-row">
<span class="pulls-element">{{.Pull.RepoFullName}} #{{.Pull.PullNum}}</span>
<span class="pulls-element"><code>{{.Pull.Path}}</code></span>
<span class="pulls-element"><code>{{.Pull.Workspace}}</code></span>
<span class="pulls-element">
{{ range .JobIDInfos }}
<div><a href="{{ $basePath }}{{ .JobIDUrl }}" target="_blank">{{ .TimeFormatted }}</a></div>
{{ end }}
</span>
</div>
{{ end }}
</div>
{{ else }}
<p class="placeholder">No jobs found.</p>
{{ end }}
</section>
<div id="applyLockMessageModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
Expand Down
5 changes: 5 additions & 0 deletions server/core/config/valid/global_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ func (g GlobalCfg) MergeProjectCfg(log logging.SimpleLogging, repoID string, pro
if proj.ApplyRequirements != nil {
log.Debug("overriding server-defined %s with repo settings: [%s]", ApplyRequirementsKey, strings.Join(proj.ApplyRequirements, ","))
applyReqs = proj.ApplyRequirements

// Preserve policies_passed req if policy check is enabled
if policyCheck {
applyReqs = append(applyReqs, PoliciesPassedCommandReq)
}
}
case ImportRequirementsKey:
if proj.ImportRequirements != nil {
Expand Down
63 changes: 63 additions & 0 deletions server/core/config/valid/global_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,69 @@ repos:
CustomPolicyCheck: false,
},
},
"repo-side apply reqs should include non-overrideable 'policies_passed' req when overridden and policies enabled": {
gCfg: `
repos:
- id: /.*/
allowed_overrides: [apply_requirements]
apply_requirements: [approved]
policy_check: true
`,
repoID: "github.com/owner/repo",
proj: valid.Project{
Dir: ".",
Workspace: "default",
PlanRequirements: []string{},
ApplyRequirements: []string{"mergeable"},
ImportRequirements: []string{},
},
repoWorkflows: nil,
exp: valid.MergedProjectCfg{
PlanRequirements: []string{},
ApplyRequirements: []string{"mergeable", "policies_passed"},
ImportRequirements: []string{},
Workflow: defaultWorkflow,
RepoRelDir: ".",
Workspace: "default",
Name: "",
AutoplanEnabled: false,
PolicySets: emptyPolicySets,
RepoLocking: true,
CustomPolicyCheck: false,
PolicyCheck: true,
},
},
"repo-side apply reqs should not include non-overrideable 'policies_passed' req when overridden and policies disabled": {
gCfg: `
repos:
- id: /.*/
allowed_overrides: [apply_requirements]
apply_requirements: [approved]
`,
repoID: "github.com/owner/repo",
proj: valid.Project{
Dir: ".",
Workspace: "default",
PlanRequirements: []string{},
ApplyRequirements: []string{"mergeable"},
ImportRequirements: []string{},
},
repoWorkflows: nil,
exp: valid.MergedProjectCfg{
PlanRequirements: []string{},
ApplyRequirements: []string{"mergeable"},
ImportRequirements: []string{},
Workflow: defaultWorkflow,
RepoRelDir: ".",
Workspace: "default",
Name: "",
AutoplanEnabled: false,
PolicySets: emptyPolicySets,
RepoLocking: true,
CustomPolicyCheck: false,
PolicyCheck: false,
},
},
"repo-side import reqs win out if allowed": {
gCfg: `
repos:
Expand Down
2 changes: 1 addition & 1 deletion server/events/command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ func TestRunUnlockCommandDoesntRetrieveLabelsIfDisableUnlockLabelNotSet(t *testi

ch.RunCommentCommand(testdata.GithubRepo, &testdata.GithubRepo, nil, testdata.User, testdata.Pull.Num, &events.CommentCommand{Name: command.Unlock})

vcsClient.VerifyWasNotCalled().GetPullLabels(testdata.GithubRepo, modelPull)
vcsClient.VerifyWasCalled(Never()).GetPullLabels(testdata.GithubRepo, modelPull)
}

func TestRunAutoplanCommand_DeletePlans(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion server/events/project_command_builder_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ workflows:
Pull: pull,
ProjectName: "",
PlanRequirements: []string{"policies_passed"},
ApplyRequirements: []string{},
ApplyRequirements: []string{"policies_passed"},
ImportRequirements: []string{"policies_passed"},
RepoConfigVersion: 3,
RePlanCmd: "atlantis plan -d project1 -w myworkspace -- flag",
Expand Down
11 changes: 7 additions & 4 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,17 @@ func (g *GitlabClient) PullIsMergeable(repo models.Repo, pull models.PullRequest

allowSkippedPipeline := project.AllowMergeOnSkippedPipeline && isPipelineSkipped

ok, err := g.SupportsDetailedMergeStatus()
supportsDetailedMergeStatus, err := g.SupportsDetailedMergeStatus()
if err != nil {
return false, err
}

if ((ok && (mr.DetailedMergeStatus == "mergeable" || mr.DetailedMergeStatus == "ci_still_running")) ||
//nolint:staticcheck // SA1019 this check ensures compatibility with older gitlab versions
(!ok && mr.MergeStatus == "can_be_merged")) &&
if ((supportsDetailedMergeStatus &&
(mr.DetailedMergeStatus == "mergeable" ||
mr.DetailedMergeStatus == "ci_still_running" ||
mr.DetailedMergeStatus == "ci_must_pass")) ||
(!supportsDetailedMergeStatus &&
mr.MergeStatus == "can_be_merged")) && //nolint:staticcheck // Need to reference deprecated field for backwards compatibility
mr.ApprovalsBeforeMerge <= 0 &&
mr.BlockingDiscussionsResolved &&
!mr.WorkInProgress &&
Expand Down
Loading

0 comments on commit f07635a

Please sign in to comment.