-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ec6924
commit fa0ec06
Showing
13 changed files
with
166 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package danger | ||
|
||
type T struct { | ||
Results Results | ||
} | ||
|
||
func New() *T { | ||
return &T{ | ||
Results: Results{ | ||
Fails: []Violation{}, | ||
Messages: []Violation{}, | ||
Warnings: []Violation{}, | ||
Markdowns: []Violation{}, | ||
}, | ||
} | ||
} | ||
|
||
// Message adds the message to the Danger table. The only difference between | ||
// this and Warn is the emoji which shows in the table. | ||
func (s *T) Message(message string, file string, line int) { | ||
s.Results.Messages = append(s.Results.Messages, | ||
Violation{ | ||
Message: message, | ||
File: file, | ||
Line: line, | ||
}) | ||
} | ||
|
||
// Warn adds the message to the Danger table. The message highlights | ||
// low-priority issues, but does not fail the build. | ||
func (s *T) Warn(message string, file string, line int) { | ||
s.Results.Warnings = append(s.Results.Warnings, | ||
Violation{ | ||
Message: message, | ||
File: file, | ||
Line: line, | ||
}) | ||
} | ||
|
||
// Fail a build, outputting a specific reason for failing into an HTML table. | ||
func (s *T) Fail(message string, file string, line int) { | ||
s.Results.Fails = append(s.Results.Fails, | ||
Violation{ | ||
Message: message, | ||
File: file, | ||
Line: line, | ||
}) | ||
} | ||
|
||
// Markdown adds the message as raw markdown into the Danger comment, under the | ||
// table. | ||
func (s *T) Markdown(message string, file string, line int) { | ||
s.Results.Markdowns = append(s.Results.Markdowns, | ||
Violation{ | ||
Message: message, | ||
File: file, | ||
Line: line, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package danger_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/moolmanruan/danger-go" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMessage(t *testing.T) { | ||
d := danger.New() | ||
|
||
d.Message("a message", "", 0) | ||
|
||
require.Equal(t, | ||
[]danger.Violation{ | ||
{Message: "a message"}, | ||
}, | ||
d.Results.Messages) | ||
} | ||
|
||
func TestWarn(t *testing.T) { | ||
d := danger.New() | ||
|
||
d.Warn("a warning", "", 0) | ||
|
||
require.Equal(t, | ||
[]danger.Violation{ | ||
{Message: "a warning"}, | ||
}, | ||
d.Results.Warnings) | ||
} | ||
|
||
func TestFail(t *testing.T) { | ||
d := danger.New() | ||
d.Fail("a failure", "", 0) | ||
|
||
require.Equal(t, | ||
[]danger.Violation{ | ||
{Message: "a failure"}, | ||
}, | ||
d.Results.Fails) | ||
} | ||
|
||
func TestMarkdown(t *testing.T) { | ||
d := danger.New() | ||
|
||
d.Markdown("some markdown", "", 0) | ||
|
||
require.Equal(t, | ||
[]danger.Violation{ | ||
{Message: "some markdown"}, | ||
}, | ||
d.Results.Markdowns) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module danger-go/dangerfile | ||
|
||
go 1.19 | ||
|
||
require github.com/moolmanruan/danger-go v0.0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/moolmanruan/danger-go v0.0.2 h1:BGoqAgholwSWdZqzmxLjWSBLtLoDk+//L6FdpVUVcJ4= | ||
github.com/moolmanruan/danger-go v0.0.2/go.mod h1:JIzQHXs5iGbWszdpQfwuEiVPd0Ees93yjzDqBUMQl6c= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package danger_js | ||
package dangerJs | ||
|
||
type GitCommit struct { | ||
SHA string `json:"sha"` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package danger_js | ||
package dangerJs | ||
|
||
import "time" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package danger_js | ||
package dangerJs | ||
|
||
import "time" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters