From 4037e5e5d64734a7f240e761522086aeb12d619d Mon Sep 17 00:00:00 2001 From: Pulkit Kathuria Date: Wed, 14 Feb 2024 21:14:32 +0900 Subject: [PATCH] support type of PR comment --- app/models/type.go | 8 +++++++- app/pkg/pr.go | 6 +++--- app/pkg/pr_handler.go | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/type.go b/app/models/type.go index ea3b67d..2c1cf8c 100644 --- a/app/models/type.go +++ b/app/models/type.go @@ -93,8 +93,12 @@ func (t *Type) GetAllTypesFor(orgName string, repoName string) ([]Type, error) { return ret, err } -func (t *Type) GetBranchTypesFor(orgName string, repoName string, branches []string) ([]Type, error) { +func (t *Type) GetBranchTypesFor(orgName string, repoName string, branches []string, typeName string) ([]Type, error) { var ret []Type + andWhereType := "" + if typeName != "" { + andWhereType = "AND t.name = @typeName" + } query := `SELECT t.* FROM types t LEFT JOIN @@ -109,6 +113,7 @@ func (t *Type) GetBranchTypesFor(orgName string, repoName string, branches []str r.name = @repoName AND c.branch_name IN @branches + ` + andWhereType + ` GROUP BY t.id LIMIT @limit` @@ -116,6 +121,7 @@ func (t *Type) GetBranchTypesFor(orgName string, repoName string, branches []str sql.Named("orgName", orgName), sql.Named("repoName", repoName), sql.Named("branches", branches), + sql.Named("typeName", typeName), sql.Named("limit", SAFE_LIMIT_TYPES)). Scan(&ret).Error if err != nil { diff --git a/app/pkg/pr.go b/app/pkg/pr.go index 9d93b1b..0a58f1e 100644 --- a/app/pkg/pr.go +++ b/app/pkg/pr.go @@ -30,8 +30,8 @@ func (p *PR) Get(req *PRRequest, types []models.Type) (string, error) { Header: []string{"Type", req.BaseBranch, req.Branch}, Rows: [][]string{}, } - urls := []string{} - chUrls := []string{} + urls := []string{} // stores urls for bar charts for comparison of base and branch + chUrls := []string{} // stores urls for commit history trends (line charts) mdText.H4("CoverItUp Report") mdText.PlainText("") @@ -124,7 +124,7 @@ func (p *PR) UpOrDown(baseScore *float64, branchScore *float64) string { func (p *PR) TypesChangedSince(req *PRRequest) ([]models.Type, error) { typesChanged := []models.Type{} - types, err := p.typeModel.GetBranchTypesFor(req.Org, req.Repo, []string{req.BaseBranch, req.Branch}) + types, err := p.typeModel.GetBranchTypesFor(req.Org, req.Repo, []string{req.BaseBranch, req.Branch}, req.Type) if err != nil { return typesChanged, err } diff --git a/app/pkg/pr_handler.go b/app/pkg/pr_handler.go index bf3517d..56b4e55 100644 --- a/app/pkg/pr_handler.go +++ b/app/pkg/pr_handler.go @@ -25,6 +25,7 @@ type PRRequest struct { BaseBranch string `json:"base_branch" query:"base_branch" validate:"required,ascii" message:"ascii base_branch is required"` PRNum int `json:"pr_num" query:"pr_num"` Theme string `json:"theme" query:"theme" default:"light" validate:"oneof=light dark" message:"theme must be light or dark"` + Type string `json:"type" query:"type" validate:"ascii" message:"ascii type is required"` host string scheme string