Skip to content

Commit 6f62099

Browse files
(feat) reduce freq of PR comments (#23)
1 parent 30f67bb commit 6f62099

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ Before using this action, enable Github Actions
178178
- uses: kevincobain2000/action-coveritup@v2
179179
with:
180180
pr_comment: true
181+
# optional
182+
## report only these types on PR comment, empty means all
183+
types: coverage,go-sec-issues,go-lint-errors
184+
# optional
185+
## report only these types after 1st comment
186+
# 1st comment will have all types or types specified in `types`
187+
# 2nd comment onwards will have only these types
188+
diff_types: coverage
181189
```
182190
183191
## Time taken

action.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ inputs:
1313
description: "Type of score"
1414
types:
1515
description: "Types to report on PR comment. If empty then it will report all types"
16+
diff_types:
17+
description: "Only types to report on PR comment after 1st comment. 1st comment will have all types"
1618
metric:
1719
description: "Metric of score"
1820
command:
@@ -154,7 +156,7 @@ runs:
154156
-x "${{ env.COVERITUP_HTTP_PROXY }}" \
155157
-H 'Content-Type: application/json' \
156158
-w "%{http_code}" \
157-
"${{env.COVERITUP_HOST}}/pr?org=${{github.repository_owner}}&repo=${{ github.event.repository.name }}&types=${{ inputs.types }}&theme=${{ inputs.theme }}&pr_num=${{ steps.pr-number-id.outputs.pr }}&branch=${{ env.BRANCH_OR_TAG_NAME }}&base_branch=${{ steps.branch-name.outputs.base_ref_branch }}" \
159+
"${{env.COVERITUP_HOST}}/pr?org=${{github.repository_owner}}&repo=${{ github.event.repository.name }}&types=${{ inputs.types }}&diff_types=${{ inputs.diff_types }}&theme=${{ inputs.theme }}&pr_num=${{ steps.pr-number-id.outputs.pr }}&branch=${{ env.BRANCH_OR_TAG_NAME }}&base_branch=${{ steps.branch-name.outputs.base_ref_branch }}" \
158160
-o comment_body.txt)
159161
echo "PR_HTTP_RESPONSE=$response" >> $GITHUB_ENV
160162

app/pkg/pr.go

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"os"
7+
"strings"
78

89
"github.com/fbiville/markdown-table-formatter/pkg/markdown"
910
"github.com/kevincobain2000/action-coveritup/models"
@@ -45,6 +46,17 @@ func (p *PR) Get(req *PRRequest, types []models.Type) (string, error) {
4546
commitHistoryImgUrls := []string{} // stores urls for commit history trends (line charts)
4647
userHistoryImgUrls := []string{} // stores urls for user history trends (line charts)
4748
mdText.H4("CoverItUp Report")
49+
// if it is not first PR, then only report the types that are different from diff_types
50+
if !isFirstPR && req.DiffTypes != "" {
51+
onlyReportTypes := []models.Type{}
52+
diffTypes := strings.Split(req.DiffTypes, ",")
53+
for _, t := range types {
54+
if Contains(diffTypes, t.Name) {
55+
onlyReportTypes = append(onlyReportTypes, t)
56+
}
57+
}
58+
types = onlyReportTypes
59+
}
4860

4961
for _, t := range types {
5062
y := make([]float64, 2)

app/pkg/pr_handler.go

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type PRRequest struct {
2626
PRNum int `json:"pr_num" query:"pr_num" validate:"required,numeric" message:"pr_num is required"`
2727
Theme string `json:"theme" query:"theme" default:"light" validate:"oneof=light dark" message:"theme must be light or dark"`
2828
Types string `json:"types" query:"types" validate:"ascii" message:"ascii types are required"`
29+
DiffTypes string `json:"diff_types" query:"diff_types" validate:"ascii" message:"ascii diff_types are required"`
2930

3031
host string
3132
scheme string

app/pkg/utils.go

+9
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,12 @@ func TrimStringFields(v interface{}) {
8282
}
8383
}
8484
}
85+
86+
func Contains(slice []string, item string) bool {
87+
for _, element := range slice {
88+
if element == item {
89+
return true
90+
}
91+
}
92+
return false
93+
}

0 commit comments

Comments
 (0)