Skip to content

Commit

Permalink
add related issue when create issue by import (#2478)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey authored Oct 22, 2021
1 parent da613bd commit 6f09169
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apistructs/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@ func (s *Issue) SetRelatedIssueIDs(ids string) error {
return nil
}
idStrs := strings.Split(ids, ",")
dp := map[uint64]bool{}
relatedIssueIDs := make([]uint64, 0)
for _, id := range idStrs {
issueID, err := strconv.Atoi(id)
if err != nil {
return err
}
if dp[uint64(issueID)] {
continue
}
dp[uint64(issueID)] = true
relatedIssueIDs = append(relatedIssueIDs, uint64(issueID))
}
s.relatedIssueIDs = relatedIssueIDs
Expand Down
13 changes: 13 additions & 0 deletions modules/dop/services/issue/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,19 @@ func (svc *Issue) decodeFromExcelFile(req apistructs.IssueImportExcelRequest, r
allInstance []apistructs.IssuePropertyRelationCreateRequest
)
sheets, err := excel.Decode(r)
// filter empty row
sheetLst := make([][][]string, 0)
for _, rows := range sheets {
rowLst := make([][]string, 0)
for _, row := range rows {
if strings.Join(row, "") == "" {
continue
}
rowLst = append(rowLst, row)
}
sheetLst = append(sheetLst, rowLst)
}
sheets = sheetLst
if err != nil {
return nil, nil, nil, nil, nil, 0, fmt.Errorf("failed to decode excel, err: %v", err)
}
Expand Down
12 changes: 12 additions & 0 deletions modules/dop/services/issue/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ func (svc *Issue) storeExcel2DB(request apistructs.IssueImportExcelRequest, issu
falseReason = append(falseReason, "创建任务失败, err:"+err.Error())
continue
}
for _, issueRelated := range req.GetRelatedIssueIDs() {
relatedIssue, err := svc.db.GetIssue(int64(issueRelated))
if err != nil {
continue
}
if relatedIssue.ProjectID == request.ProjectID {
_ = svc.db.CreateIssueRelations(&dao.IssueRelation{
IssueID: issueRelated,
RelatedIssue: create.ID,
})
}
}
// 添加标签关联关系
labels, err := svc.bdl.ListLabelByNameAndProjectID(req.ProjectID, req.Labels)
if err != nil {
Expand Down

0 comments on commit 6f09169

Please sign in to comment.