Skip to content

Commit

Permalink
fix: export only related iterations if not exporting all issues (#5983)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfwn authored Jul 14, 2023
1 parent 7e7a4e3 commit a6b8732
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/apps/dop/providers/issue/core/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,20 @@ func (i *IssueService) createDataForFulfillForExport(req *pb.ExportExcelIssueReq
return nil, fmt.Errorf("failed to page issues, err: %v", err)
}
data.ExportOnly.Issues = issues
// get total
_, projectIssueTotalNum, err := i.db.PagingIssues(pb.PagingIssueRequest{
ProjectID: data.ProjectID,
PageNo: 1,
PageSize: 1,
External: req.External,
OnlyIdResult: true,
}, false)
if err != nil {
return nil, fmt.Errorf("failed to get project issues total num, err: %v", err)
}
if uint64(len(issues)) >= projectIssueTotalNum {
data.ExportOnly.AllProjectIssues = true
}
data.ExportOnly.IsDownloadTemplate = req.IsDownloadTemplate
data.ExportOnly.FileNameWithExt = "issue-export.xlsx"
// propertyRelation map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type DataForFulfill struct {
}

type DataForFulfillExportOnly struct {
AllProjectIssues bool
FileNameWithExt string
Issues []*pb.Issue
IsDownloadTemplate bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import (
type DataForFulfillImportOnlyBaseInfo struct {
OriginalErdaPlatform string // get from dop conf.DiceClusterName()
OriginalErdaProjectID uint64
AllProjectIssues bool
}

func (data DataForFulfill) genBaseInfoSheet() (excel.Rows, error) {
// only one row, k=meta, v=JSON(dataForFulfillImportOnlyBaseInfo)
meta := DataForFulfillImportOnlyBaseInfo{
OriginalErdaPlatform: conf.DiceClusterName(),
OriginalErdaProjectID: data.ProjectID,
AllProjectIssues: data.ExportOnly.AllProjectIssues,
}
b, err := json.Marshal(&meta)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ import (
)

func (data DataForFulfill) genIterationSheet() (excel.Rows, error) {
// if AllProjectIssues=true, then export all iterations
// otherwise, just export iterations related to issues
relatedIterationMapByID := make(map[int64]struct{})
if !data.ExportOnly.AllProjectIssues {
for _, issue := range data.ExportOnly.Issues {
relatedIterationMapByID[issue.IterationID] = struct{}{}
}
}

var lines excel.Rows
// title: iteration id, iteration name, iteration info (JSON)
title := excel.Row{
Expand All @@ -41,6 +50,12 @@ func (data DataForFulfill) genIterationSheet() (excel.Rows, error) {
if iteration.ID <= 0 {
continue
}
if !data.ExportOnly.AllProjectIssues {
// only related iteration need to be exported
if _, ok := relatedIterationMapByID[int64(iteration.ID)]; !ok {
continue
}
}
b, err := json.Marshal(iteration)
if err != nil {
return nil, fmt.Errorf("failed to marshal iteration info, iteration id: %d, err: %v", iteration.ID, err)
Expand Down

0 comments on commit a6b8732

Please sign in to comment.