Skip to content

Commit

Permalink
Merge branch 'master' into feature/gh-716-cli-success-message
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-tschumak committed Jun 4, 2018
2 parents f77a039 + 097b5d2 commit 7b868c2
Show file tree
Hide file tree
Showing 64 changed files with 407 additions and 1,400 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ install: true
script:
# Unit-test and build server
- cd server/
- ./gradlew build --info
- ./gradlew --console=plain build --info
- cd ..

# Unit-test and build integration server
- cd github-integration/
- ./gradlew build --info
- ./gradlew --console=plain build --info
- cd ..

# Launch local zally server
- cd server/
- ./gradlew bootRun > /dev/null &
- ./gradlew --console=plain bootRun > /dev/null &
- echo $! > /tmp/zally_server.pid
- cd ..

Expand Down
505 changes: 3 additions & 502 deletions LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cli/zally/domain/violation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ type Violation struct {
Decription string `json:"description"`
ViolationType string `json:"violation_type"`
RuleLink string `json:"rule_link"`
Pointer string `json:"pointer"`
Paths []string `json:"paths"`
}
3 changes: 2 additions & 1 deletion cli/zally/domain/violations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestViolations(t *testing.T) {
mustViolation.RuleLink = "http://example.com/mustViolation"
mustViolation.ViolationType = "MUST"
mustViolation.Decription = "Must Description"
mustViolation.Pointer = "/pointer/1"
mustViolation.Paths = []string{"/path/one", "/path/two"}

var shouldViolation Violation
Expand All @@ -33,7 +34,7 @@ func TestViolations(t *testing.T) {
hintViolation.RuleLink = "http://example.com/hintViolation"
hintViolation.ViolationType = "HINT"
hintViolation.Decription = "Hint Description"
hintViolation.Paths = []string{"/path/seven", "/path/eight"}
hintViolation.Pointer = "/pointer/2"

var violationsCount ViolationsCount
violationsCount.Must = 1
Expand Down
10 changes: 8 additions & 2 deletions cli/zally/utils/formatters/markdown_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ func (f *MarkdownFormatter) formatViolation(violation *domain.Violation) string

fmt.Fprintf(&buffer, "### `%s` [%s](%s)\n\n", violation.ViolationType, violation.Title, violation.RuleLink)
fmt.Fprintf(&buffer, "> %s\n\n", violation.Decription)
for _, path := range violation.Paths {
fmt.Fprintf(&buffer, "- %s\n", path)

if violation.Pointer != "" {
fmt.Fprintf(&buffer, "- %s\n", violation.Pointer)
} else {
for _, path := range violation.Paths {
fmt.Fprintf(&buffer, "- %s\n", path)
}
}

fmt.Fprintf(&buffer, "\n")

return buffer.String()
Expand Down
38 changes: 32 additions & 6 deletions cli/zally/utils/formatters/markdown_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ func TestMarkdownFormatServerMessage(t *testing.T) {
func TestMarkdownFormatViolation(t *testing.T) {
var markdownFormatter MarkdownFormatter

t.Run("Converts violation to string in pretty format", func(t *testing.T) {
var violation domain.Violation
violation.Title = "Test Title"
violation.RuleLink = "http://example.com/violation"
violation.ViolationType = "MUST"
violation.Decription = "Test Description"

t.Run("Converts violation to string in pretty format with just paths", func(t *testing.T) {

var violation domain.Violation
violation.Title = "Test Title"
violation.RuleLink = "http://example.com/violation"
violation.ViolationType = "MUST"
violation.Decription = "Test Description"
violation.Paths = []string{"/path/one", "/path/two"}

actualResult := markdownFormatter.formatViolation(&violation)
Expand All @@ -143,6 +144,31 @@ func TestMarkdownFormatViolation(t *testing.T) {

tests.AssertEquals(t, expectedResult, actualResult)
})

t.Run("Converts violation to string in pretty format with paths and pointer", func(t *testing.T) {

violation.Pointer = "/pointer/1"

actualResult := markdownFormatter.formatViolation(&violation)
expectedResult := "### `MUST` [Test Title](http://example.com/violation)\n\n" +
"> Test Description\n\n" +
"- /pointer/1\n\n"

tests.AssertEquals(t, expectedResult, actualResult)
})

t.Run("Converts violation to string in pretty format with just pointer", func(t *testing.T) {

violation.Paths = nil

actualResult := markdownFormatter.formatViolation(&violation)
expectedResult := "### `MUST` [Test Title](http://example.com/violation)\n\n" +
"> Test Description\n\n" +
"- /pointer/1\n\n"

tests.AssertEquals(t, expectedResult, actualResult)
})

}

func TestMarkdownFormatHeader(t *testing.T) {
Expand Down
8 changes: 6 additions & 2 deletions cli/zally/utils/formatters/pretty_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ func (f *PrettyFormatter) formatViolation(violation *domain.Violation) string {
fmt.Fprintf(&buffer, "\t%s\n", violation.Decription)
fmt.Fprintf(&buffer, "\t%s\n", violation.RuleLink)

for _, path := range violation.Paths {
fmt.Fprintf(&buffer, "\t\t%s\n", path)
if violation.Pointer != "" {
fmt.Fprintf(&buffer, "\t\t%s\n", violation.Pointer)
} else {
for _, path := range violation.Paths {
fmt.Fprintf(&buffer, "\t\t%s\n", path)
}
}

fmt.Fprintf(&buffer, "\n")
Expand Down
39 changes: 33 additions & 6 deletions cli/zally/utils/formatters/pretty_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ func TestPrettyFormatServerMessage(t *testing.T) {
func TestPrettyFormatViolationInPrettyFormat(t *testing.T) {
prettyFormatter := NewPrettyFormatter(NewPrettyColorizer(true))

t.Run("Converts violation to string in pretty format", func(t *testing.T) {
var violation domain.Violation
violation.Title = "Test Title"
violation.RuleLink = "http://example.com/violation"
violation.ViolationType = "MUST"
violation.Decription = "Test Description"

t.Run("Converts violation to string in pretty format with just paths", func(t *testing.T) {

var violation domain.Violation
violation.Title = "Test Title"
violation.RuleLink = "http://example.com/violation"
violation.ViolationType = "MUST"
violation.Decription = "Test Description"
violation.Paths = []string{"/path/one", "/path/two"}

actualResult := prettyFormatter.formatViolation(&violation)
Expand All @@ -130,6 +131,32 @@ func TestPrettyFormatViolationInPrettyFormat(t *testing.T) {

tests.AssertEquals(t, expectedResult, actualResult)
})

t.Run("Converts violation to string in pretty format with paths and pointer", func(t *testing.T) {

violation.Pointer = "/pointer/1"

actualResult := prettyFormatter.formatViolation(&violation)
expectedResult := "\x1b[31mMUST\x1b[0m \x1b[31mTest Title\x1b[0m\n" +
"\tTest Description\n" +
"\thttp://example.com/violation\n" +
"\t\t/pointer/1\n\n"

tests.AssertEquals(t, expectedResult, actualResult)
})

t.Run("Converts violation to string in pretty format with just pointer", func(t *testing.T) {

violation.Paths = nil

actualResult := prettyFormatter.formatViolation(&violation)
expectedResult := "\x1b[31mMUST\x1b[0m \x1b[31mTest Title\x1b[0m\n" +
"\tTest Description\n" +
"\thttp://example.com/violation\n" +
"\t\t/pointer/1\n\n"

tests.AssertEquals(t, expectedResult, actualResult)
})
}

func TestPrettyFormatHeader(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ dependencies {
compile("org.zalando:twintip-spring-web:1.1.0")
compile("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
compile("com.typesafe:config:1.3.3")
compile("de.mpg.mpi-inf:javatools:1.0.1")

testCompile("net.jadler:jadler-core:1.3.0")
testCompile("net.jadler:jadler-jdk:1.3.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ private ViolationDTO toDto(Result violation) {
violation.getDescription(),
violation.getViolationType(),
violation.getRuleSet().url(violation.getRule()).toString(),
violation.getPaths()
violation.getPaths(),
violation.getPointer() == null ? null : violation.getPointer().toString()
);
}

Expand Down
27 changes: 1 addition & 26 deletions server/src/main/java/de/zalando/zally/dto/ViolationDTO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package de.zalando.zally.dto
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonInclude.Include
import de.zalando.zally.rule.api.Severity
import java.util.Arrays.asList

data class ViolationDTO(
var title: String? = null,
Expand All @@ -12,28 +11,4 @@ data class ViolationDTO(
var ruleLink: String? = null,
@JsonInclude(Include.NON_NULL) @Deprecated("Use `pointer` instead.") var paths: List<String>? = null,
@JsonInclude(Include.NON_NULL) var pointer: String? = null
) {
constructor(
title: String?,
description: String?,
violationType: Severity?,
ruleLink: String?,
vararg paths: String
) : this(title, description, violationType, ruleLink, asList(*paths))

@Deprecated("Use `pointer` instead.")
constructor(
title: String?,
description: String?,
violationType: Severity?,
ruleLink: String?,
paths: List<String>?
) : this(
title,
description,
violationType,
ruleLink,
if (paths?.size == 1) null else paths,
if (paths?.size == 1) paths[0] else null
)
}
)

This file was deleted.

This file was deleted.

0 comments on commit 7b868c2

Please sign in to comment.