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

(feat) reduce freq of PR comments #23

Merged
merged 1 commit into from
Sep 5, 2024
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ Before using this action, enable Github Actions
- uses: kevincobain2000/action-coveritup@v2
with:
pr_comment: true
# optional
## report only these types on PR comment, empty means all
types: coverage,go-sec-issues,go-lint-errors
# optional
## report only these types after 1st comment
# 1st comment will have all types or types specified in `types`
# 2nd comment onwards will have only these types
diff_types: coverage
```

## Time taken
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ inputs:
description: "Type of score"
types:
description: "Types to report on PR comment. If empty then it will report all types"
diff_types:
description: "Only types to report on PR comment after 1st comment. 1st comment will have all types"
metric:
description: "Metric of score"
command:
Expand Down Expand Up @@ -154,7 +156,7 @@ runs:
-x "${{ env.COVERITUP_HTTP_PROXY }}" \
-H 'Content-Type: application/json' \
-w "%{http_code}" \
"${{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 }}" \
"${{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 }}" \
-o comment_body.txt)
echo "PR_HTTP_RESPONSE=$response" >> $GITHUB_ENV

Expand Down
12 changes: 12 additions & 0 deletions app/pkg/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/fbiville/markdown-table-formatter/pkg/markdown"
"github.com/kevincobain2000/action-coveritup/models"
Expand Down Expand Up @@ -45,6 +46,17 @@ func (p *PR) Get(req *PRRequest, types []models.Type) (string, error) {
commitHistoryImgUrls := []string{} // stores urls for commit history trends (line charts)
userHistoryImgUrls := []string{} // stores urls for user history trends (line charts)
mdText.H4("CoverItUp Report")
// if it is not first PR, then only report the types that are different from diff_types
if !isFirstPR && req.DiffTypes != "" {
onlyReportTypes := []models.Type{}
diffTypes := strings.Split(req.DiffTypes, ",")
for _, t := range types {
if Contains(diffTypes, t.Name) {
onlyReportTypes = append(onlyReportTypes, t)
}
}
types = onlyReportTypes
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust 🔥

}

for _, t := range types {
y := make([]float64, 2)
Expand Down
1 change: 1 addition & 0 deletions app/pkg/pr_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type PRRequest struct {
PRNum int `json:"pr_num" query:"pr_num" validate:"required,numeric" message:"pr_num is required"`
Theme string `json:"theme" query:"theme" default:"light" validate:"oneof=light dark" message:"theme must be light or dark"`
Types string `json:"types" query:"types" validate:"ascii" message:"ascii types are required"`
DiffTypes string `json:"diff_types" query:"diff_types" validate:"ascii" message:"ascii diff_types are required"`

host string
scheme string
Expand Down
9 changes: 9 additions & 0 deletions app/pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ func TrimStringFields(v interface{}) {
}
}
}

func Contains(slice []string, item string) bool {
for _, element := range slice {
if element == item {
return true
}
}
return false
}
Loading