Skip to content

Commit e8510ff

Browse files
Vishal VaibhavGitHub Enterprise
authored andcommitted
Missed instruction part of PR comments (#18)
* detailed info on pr comments * missed instructions part of pr * formatting issues * linting fixes * vela compatible * plugin source dir * debugging * dummy commit * dummy commit * skipping if thats a missed instructions * moved common to utils
1 parent 9133ee0 commit e8510ff

7 files changed

Lines changed: 162 additions & 43 deletions

File tree

.vela.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ build: &build
1818
check-pr-code-coverage: &check-pr-code-coverage
1919
image: alpine:latest
2020
environment:
21-
- PLUGIN_COVERAGE_FILE=./coverage.xml
22-
- PLUGIN_COVERAGE_TYPE=cobertura
23-
- PLUGIN_SOURCE_DIRS=git.target.com/searchoss/pull-request-code-coverage
21+
- PARAMETER_COVERAGE_FILE=./coverage.xml
22+
- PARAMETER_COVERAGE_TYPE=cobertura
23+
- PARAMETER_SOURCE_DIRS=/vela/src/git.target.com/TargetOSS/pull-request-code-coverage
2424
- PLUGIN_RUN_DIR=bin
25-
- PLUGIN_GH_API_BASE_URL=https://git.target.com
25+
- PARAMETER_GH_API_BASE_URL=https://git.target.com
2626
secrets:
27-
- source: pull_request_api_key
27+
- source: github_pr_token
2828
target: plugin_gh_api_key
2929
commands:
3030
- apk --no-cache add ca-certificates git bash openssh-client
@@ -75,8 +75,6 @@ steps:
7575
- master
7676
event:
7777
- pull_request
78-
when:
79-
event: [pull_request]
8078

8179
- name: docker-pull-request
8280
image: docker.target.com/vela-plugins/docker:v0.2.3-1
@@ -119,4 +117,7 @@ secrets:
119117
key: tap/vela-secrets/ARTIFACTORY_SVCPEJKN001_BINREPO
120118
engine: native
121119
type: shared
120+
- name: github_pr_token
121+
engine: native
122+
type: repo
122123

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ module git.target.com/searchoss/pull-request-code-coverage
33
go 1.13
44

55
require (
6-
github.com/konsorten/go-windows-terminal-sequences v1.0.1
7-
github.com/nicksnyder/go-i18n v1.10.1
86
github.com/pkg/errors v0.9.1
97
github.com/sirupsen/logrus v1.2.0
10-
github.com/stretchr/testify v1.2.2
8+
github.com/stretchr/testify v1.4.0
119

1210
)

go.sum

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,61 @@
1-
git.target.com/searchoss/pull-request-code-coverage v0.0.0-20200404215431-8064a445bf4c h1:Z0rjclOT23umt1IOd9wvwBxzNYEmRhAz9ElEj1UmHrM=
2-
git.target.com/searchoss/pull-request-code-coverage v0.0.0-20200404215431-8064a445bf4c/go.mod h1:1KzCU08X6A2gF4AQDeA1jXUhWfbjr3SdqK+skf5jRFU=
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
32
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
43
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
5+
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
6+
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
7+
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
8+
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
9+
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
10+
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
11+
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
12+
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
13+
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
14+
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
15+
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
16+
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
17+
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
18+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
19+
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
20+
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
21+
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
522
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
6-
github.com/nicksnyder/go-i18n v1.10.1/go.mod h1:e4Di5xjP9oTVrC6y3C7C0HoSYXjSbhh/dU0eUV32nB4=
7-
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
23+
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
24+
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
25+
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
26+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
27+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
28+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
29+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
30+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
831
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
932
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1033
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1134
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1235
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
1336
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
37+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1438
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
1539
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1640
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
1741
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
42+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
43+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
44+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
45+
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
46+
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
47+
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
48+
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
1849
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
1950
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
20-
golang.org/x/crypto v0.0.0-20181106171534-e4dc69e5b2fd h1:VtIkGDhk0ph3t+THbvXHfMZ8QHgsBO39Nh52+74pq7w=
21-
golang.org/x/crypto v0.0.0-20181106171534-e4dc69e5b2fd/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
2251
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
2352
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
24-
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8 h1:YoY1wS6JYVRpIfFngRf2HHo9R9dAne3xbkGOQ5rJXjU=
25-
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
53+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
54+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
55+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
56+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
57+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2658
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
27-
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
59+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
60+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
61+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

internal/plugin/reporter/github_pr.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ func (s *GithubPullRequest) createCommentBody(changedLinesWithCoverage domain.So
9090
if len(modules) > 0 {
9191
summaryLines = append(summaryLines, fmt.Sprintf("*Modules: %v*\n\n", strings.Join(modules, ", ")))
9292
}
93+
var missedInstructions string
94+
95+
for _, r := range changedLinesWithCoverage {
96+
if r.MissedInstructionCount > 0 {
97+
missedInstructions += fmt.Sprintf("--- %v\n", lineDescription(r.SourceLine))
98+
missedInstructions += fmt.Sprintf("%v\n", r.LineValue)
99+
}
100+
}
93101

94102
summaryLines = append(summaryLines, generateSummaryLines(changedLinesWithCoverage, func(linesWithDataCount int, linesWithoutDataCount int, covered int, missed int) []string {
95103
totalLines := linesWithDataCount + linesWithoutDataCount
@@ -105,7 +113,16 @@ func (s *GithubPullRequest) createCommentBody(changedLinesWithCoverage domain.So
105113

106114
return result
107115
})...)
108-
summary := strings.Join(summaryLines, "")
116+
117+
var summary string
118+
if missedInstructions == "" {
119+
summary = strings.Join(summaryLines, "")
120+
} else {
121+
122+
summaryWithoutInstructions := strings.Join(summaryLines, "")
123+
summary = summaryWithoutInstructions + "\n<details><summary>Missed Instructions summary</summary>\n\n" + "```\n" + missedInstructions + "```" +
124+
"\n</details>"
125+
}
109126

110127
data := map[string]string{
111128
"body": summary,

internal/plugin/reporter/simple.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package reporter
22

33
import (
44
"fmt"
5+
56
"io"
67
"log"
7-
"strings"
88

99
"git.target.com/searchoss/pull-request-code-coverage/internal/plugin/domain"
1010
)
@@ -27,7 +27,7 @@ func (s *Simple) Write(changedLinesWithCoverage domain.SourceLineCoverageReport)
2727
s.printf("Missed Instructions:\n")
2828
for _, r := range changedLinesWithCoverage {
2929
if r.MissedInstructionCount > 0 {
30-
s.printf("--- %v\n", s.lineDescription(r.SourceLine))
30+
s.printf("--- %v\n", lineDescription(r.SourceLine))
3131
s.printf("%v\n", r.LineValue)
3232
}
3333
}
@@ -92,18 +92,3 @@ func (s *Simple) print(str string) {
9292
log.Panic(err)
9393
}
9494
}
95-
96-
func (s *Simple) lineDescription(l domain.SourceLine) string {
97-
rawFileNameParts := []string{
98-
l.Module, l.SrcDir, l.Pkg, l.FileName,
99-
}
100-
101-
fileNameParts := []string{}
102-
for _, part := range rawFileNameParts {
103-
if len(part) > 0 {
104-
fileNameParts = append(fileNameParts, part)
105-
}
106-
}
107-
108-
return fmt.Sprintf("%v:%v", strings.Join(fileNameParts, "/"), l.LineNumber)
109-
}

internal/plugin/reporter/utils.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package reporter
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"git.target.com/searchoss/pull-request-code-coverage/internal/plugin/domain"
8+
)
9+
10+
func lineDescription(l domain.SourceLine) string {
11+
rawFileNameParts := []string{
12+
l.Module, l.SrcDir, l.Pkg, l.FileName,
13+
}
14+
15+
var fileNameParts []string
16+
for _, part := range rawFileNameParts {
17+
if len(part) > 0 {
18+
fileNameParts = append(fileNameParts, part)
19+
}
20+
}
21+
22+
return fmt.Sprintf("%v:%v", strings.Join(fileNameParts, "/"), l.LineNumber)
23+
}

internal/plugin/runner_test.go

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,22 @@ Lines Without Coverage Data -> 92% (2216)
117117
Lines With Coverage Data -> 8% (182)
118118
Covered Instructions -> **97%** (177)
119119
Missed Instructions -> 3% (5)
120-
`,
120+
121+
<details><summary>Missed Instructions summary</summary>
122+
123+
` + "```" + `
124+
--- internal/plugin/runner.go:72
125+
func GetCoverageReportLoader(coverageType string, sourceDir string) coverage.Loader {
126+
--- main.go:10
127+
err := plugin.NewRunner().Run(os.LookupEnv, os.Stdin, os.Stdout)
128+
--- main.go:12
129+
if err != nil {
130+
--- main.go:13
131+
log.WithFields(log.Fields{
132+
--- main.go:17
133+
os.Exit(1)
134+
` +
135+
"```\n</details>",
121136
})
122137

123138
propGetter.AssertExpectations(t)
@@ -172,7 +187,22 @@ Lines Without Coverage Data -> 92% (2216)
172187
Lines With Coverage Data -> 8% (182)
173188
Covered Instructions -> **97%** (177)
174189
Missed Instructions -> 3% (5)
175-
`,
190+
191+
<details><summary>Missed Instructions summary</summary>
192+
193+
` + "```" + `
194+
--- internal/plugin/runner.go:72
195+
func GetCoverageReportLoader(coverageType string, sourceDir string) coverage.Loader {
196+
--- main.go:10
197+
err := plugin.NewRunner().Run(os.LookupEnv, os.Stdin, os.Stdout)
198+
--- main.go:12
199+
if err != nil {
200+
--- main.go:13
201+
log.WithFields(log.Fields{
202+
--- main.go:17
203+
os.Exit(1)
204+
` +
205+
"```\n</details>",
176206
})
177207

178208
propGetter.AssertExpectations(t)
@@ -220,7 +250,14 @@ Lines Without Coverage Data -> 78% (7)
220250
Lines With Coverage Data -> 22% (2)
221251
Covered Instructions -> **73%** (8)
222252
Missed Instructions -> 27% (3)
223-
`,
253+
254+
<details><summary>Missed Instructions summary</summary>
255+
256+
` + "```" + `
257+
--- category-search/src/main/java/com/tgt/CategorySearchApplication.java:52
258+
System.out.print("Something");
259+
` +
260+
"```\n</details>",
224261
})
225262

226263
propGetter.AssertExpectations(t)
@@ -279,7 +316,14 @@ Lines Without Coverage Data -> 78% (7)
279316
Lines With Coverage Data -> 22% (2)
280317
Covered Instructions -> **73%** (8)
281318
Missed Instructions -> 27% (3)
282-
`,
319+
320+
<details><summary>Missed Instructions summary</summary>
321+
322+
` + "```" + `
323+
--- category-search/src/main/java/com/tgt/CategorySearchApplication.java:52
324+
System.out.print("Something");
325+
` +
326+
"```\n</details>",
283327
})
284328

285329
propGetter.AssertExpectations(t)
@@ -330,7 +374,15 @@ Lines Without Coverage Data -> 47% (7)
330374
Lines With Coverage Data -> 53% (8)
331375
Covered Instructions -> **88%** (42)
332376
Missed Instructions -> 12% (6)
333-
`,
377+
378+
<details><summary>Missed Instructions summary</summary>
379+
380+
` + "```" + `
381+
--- category-search/src/main/java/com/tgt/CategorySearchApplication.java:52
382+
System.out.print("Something");
383+
--- category-search/src/main/kotlin/com/tgt/SomeOtherClass.kt:12
384+
System.out.print("Something2");
385+
` + "```\n</details>",
334386
})
335387

336388
propGetter.AssertExpectations(t)
@@ -393,7 +445,16 @@ Lines Without Coverage Data -> 47% (7)
393445
Lines With Coverage Data -> 53% (8)
394446
Covered Instructions -> **88%** (42)
395447
Missed Instructions -> 12% (6)
396-
`,
448+
449+
<details><summary>Missed Instructions summary</summary>
450+
451+
` + "```" + `
452+
--- category-search/src/main/java/com/tgt/CategorySearchApplication.java:52
453+
System.out.print("Something");
454+
--- category-search/src/main/kotlin/com/tgt/SomeOtherClass.kt:12
455+
System.out.print("Something2");
456+
` +
457+
"```\n</details>",
397458
})
398459

399460
propGetter.AssertExpectations(t)

0 commit comments

Comments
 (0)