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

Add policy check summary in wrapped messages #2452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion server/events/markdown_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type planSuccessData struct {

type policyCheckSuccessData struct {
models.PolicyCheckSuccess
PolicyCheckSummary string
}

type projectResultTmplData struct {
Expand Down Expand Up @@ -199,7 +200,7 @@ func (m *MarkdownRenderer) renderProjectResults(results []command.ProjectResult,
numPlanSuccesses++
} else if result.PolicyCheckSuccess != nil {
if m.shouldUseWrappedTmpl(vcsHost, result.PolicyCheckSuccess.PolicyCheckOutput) {
resultData.Rendered = m.renderTemplate(templates.Lookup("policyCheckSuccessWrapped"), policyCheckSuccessData{PolicyCheckSuccess: *result.PolicyCheckSuccess})
resultData.Rendered = m.renderTemplate(templates.Lookup("policyCheckSuccessWrapped"), policyCheckSuccessData{PolicyCheckSuccess: *result.PolicyCheckSuccess, PolicyCheckSummary: result.PolicyCheckSuccess.Summary()})
} else {
resultData.Rendered = m.renderTemplate(templates.Lookup("policyCheckSuccessUnwrapped"), policyCheckSuccessData{PolicyCheckSuccess: *result.PolicyCheckSuccess})
}
Expand Down
11 changes: 11 additions & 0 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,17 @@ type PolicyCheckSuccess struct {
HasDiverged bool
}

// Summary extracts one line summary of policy check.
func (p *PolicyCheckSuccess) Summary() string {
note := ""

r := regexp.MustCompile(`\d+ tests, \d+ passed, \d+ warnings, \d+ failures, \d+ exceptions`)
if match := r.FindString(p.PolicyCheckOutput); match != "" {
return note + match
}
return note
}

type VersionSuccess struct {
VersionOutput string
}
Expand Down
11 changes: 11 additions & 0 deletions server/events/models/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,17 @@ func TestAzureDevopsSplitRepoFullName(t *testing.T) {
})
}
}

func TestPolicyCheckSuccess_Summary(t *testing.T) {
pcs := models.PolicyCheckSuccess{
PolicyCheckOutput: `WARN - <redacted plan file> - main - example main package

20 tests, 19 passed, 1 warnings, 0 failures, 0 exceptions`,
}

Equals(t, "20 tests, 19 passed, 1 warnings, 0 failures, 0 exceptions", pcs.Summary())
}

func TestPullStatus_StatusCount(t *testing.T) {
ps := models.PullStatus{
Projects: []models.ProjectStatus{
Expand Down