Skip to content

Commit f928a20

Browse files
committed
feat(dash): enhance feature detail information
1 parent fd0d3fd commit f928a20

File tree

1 file changed

+63
-14
lines changed

1 file changed

+63
-14
lines changed

internal/dash_impl.go

+63-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"os"
7+
"strconv"
78
"strings"
89
"text/template"
910

@@ -58,9 +59,9 @@ var (
5859
🎯 Milestone Desc : {{.milestoneDesc}}
5960
🤡 Feature Branch : {{.featureBranch}}
6061
👽 Milestone URL : {{.milestoneWebURL}}
61-
🎠 Merge Requests :
6262
`
63-
_featureDetailTblHeader = []string{"🎠MR#Flow", "✈️MR#WebURL", "🎯Issue#Title", "✈️Issue#URL"}
63+
_featureDetailTblHeader = []string{"MR#Src", "MR#Target", "MR#WebURL", "Issue#IID", "Issue#Desc"}
64+
_featureDetailIssueTblHeader = []string{"Issue#IID", "Issue#Title", "Issue#Desc", "Issue#WebURL"}
6465
)
6566

6667
func init() {
@@ -94,7 +95,10 @@ func (d dashImpl) fillContextWithProject() error {
9495
return fmt.Errorf("could not match project(%s) from remote: %v", projectName, err)
9596
}
9697

97-
// FeatureDetail get feature detail of current project
98+
// FeatureDetail get feature detail of current project:
99+
// * basic information to current milestone.
100+
// * all merge request and its related issue created in current milestone.
101+
// * all issues created in current milestone with web url.
98102
func (d dashImpl) FeatureDetail(featureBranchName string) ([]byte, error) {
99103
if featureBranchName == "" {
100104
featureBranchName, _ = d.gitOperator.CurrentBranch()
@@ -142,11 +146,18 @@ func (d dashImpl) FeatureDetail(featureBranchName string) ([]byte, error) {
142146

143147
// rework issue
144148
issueCache := make(map[int]*repository.IssueDO)
145-
for _, v := range issues {
149+
issueTblData := make([][]string, len(issues))
150+
for idx, v := range issues {
146151
issueCache[v.IssueIID] = v
152+
issueTblData[idx] = []string{
153+
strconv.Itoa(v.IssueIID),
154+
v.Title,
155+
v.Desc,
156+
v.WebURL,
157+
}
147158
}
148159

149-
tblData := make([][]string, len(mrs))
160+
mrTblData := make([][]string, len(mrs))
150161
for idx, mr := range mrs {
151162
issue, ok := issueCache[mr.IssueIID]
152163
if !ok {
@@ -158,18 +169,18 @@ func (d dashImpl) FeatureDetail(featureBranchName string) ([]byte, error) {
158169
issue = new(repository.IssueDO)
159170
}
160171

161-
tblData[idx] = []string{
162-
//strconv.Itoa(mr.MergeRequestID), // MR-ID
163-
fmt.Sprintf("%s🇨🇳 %s", mr.SourceBranch, mr.TargetBranch), // mr action
164-
mr.WebURL, // MR-URL
165-
issue.Title, // issue.Name
166-
issue.WebURL, // issue.IssueURL
172+
mrTblData[idx] = []string{
173+
mr.SourceBranch, //
174+
mr.TargetBranch, //
175+
mr.WebURL, // MR-URL
176+
strconv.Itoa(issue.IssueIID), // issue.issueIID
177+
issue.Desc, // issue.Title
167178
}
168179
}
169180

170181
log.
171-
WithFields(log.Fields{"tblData": tblData}).
172-
Debug("tblData is conducted")
182+
WithFields(log.Fields{"mrTblData": mrTblData}).
183+
Debug("mrTblData is conducted")
173184

174185
data := map[string]interface{}{
175186
"projectTitle": d.ctx.Project.Name,
@@ -186,11 +197,49 @@ func (d dashImpl) FeatureDetail(featureBranchName string) ([]byte, error) {
186197
return nil, errors.Wrap(err, "detailTpl.Execute")
187198
}
188199

200+
buf.WriteString("All Merge Requests:\n")
201+
202+
// output all merge request into table
189203
w := tablewriter.NewWriter(buf)
190204
w.SetHeader(_featureDetailTblHeader)
191-
w.AppendBulk(tblData)
205+
w.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
206+
w.SetAlignment(tablewriter.ALIGN_LEFT)
207+
for _, row := range mrTblData {
208+
// if master merge request
209+
if row[1] == types.MasterBranch.String() {
210+
w.Rich(row, []tablewriter.Colors{
211+
{tablewriter.Bold, tablewriter.FgHiRedColor},
212+
{tablewriter.Bold, tablewriter.FgHiRedColor},
213+
{},
214+
{tablewriter.Bold, tablewriter.FgBlackColor},
215+
})
216+
continue
217+
}
218+
219+
if row[1] == types.TestBranch.String() {
220+
w.Rich(row, []tablewriter.Colors{
221+
{tablewriter.Bold, tablewriter.FgHiGreenColor},
222+
{tablewriter.Bold, tablewriter.FgHiGreenColor},
223+
{},
224+
{tablewriter.Bold, tablewriter.FgBlackColor},
225+
})
226+
continue
227+
}
228+
229+
w.Append(row)
230+
}
192231
w.Render()
193232

233+
buf.WriteString("All Issues:\n")
234+
235+
// output all issues into detail
236+
w2 := tablewriter.NewWriter(buf)
237+
w2.SetHeader(_featureDetailIssueTblHeader)
238+
w2.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
239+
w2.SetAlignment(tablewriter.ALIGN_LEFT)
240+
w2.AppendBulk(issueTblData)
241+
w2.Render()
242+
194243
return buf.Bytes(), nil
195244
}
196245

0 commit comments

Comments
 (0)