Skip to content

Commit

Permalink
support type of PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Feb 14, 2024
1 parent 765d3ad commit 4037e5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/models/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -109,13 +113,15 @@ 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`

err := db.Db().Raw(query,
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 {
Expand Down
6 changes: 3 additions & 3 deletions app/pkg/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("")

Expand Down Expand Up @@ -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
}
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 @@ -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
Expand Down

0 comments on commit 4037e5e

Please sign in to comment.