Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions backend/plugins/taiga/tasks/user_story_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ limitations under the License.
package tasks

import (
"fmt"

"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/models/domainlayer"
Expand Down Expand Up @@ -71,22 +73,41 @@ func ConvertUserStories(subtaskCtx plugin.SubTaskContext) errors.Error {
Convert: func(userStory *models.TaigaUserStory) ([]interface{}, errors.Error) {
var result []interface{}

// Map Taiga is_closed to DevLake standard status
status := "TODO"
if userStory.IsClosed {
status = "DONE"
}

issue := &ticket.Issue{
DomainEntity: domainlayer.DomainEntity{
Id: issueIdGen.Generate(userStory.ConnectionId, userStory.UserStoryId),
},
IssueKey: userStory.Subject,
IssueKey: fmt.Sprintf("#%d", userStory.Ref),
Title: userStory.Subject,
Type: "USER_STORY",
OriginalType: "User Story",
Status: userStory.Status,
Status: status,
OriginalStatus: userStory.Status,
CreatedDate: userStory.CreatedDate,
UpdatedDate: userStory.ModifiedDate,
ResolutionDate: userStory.FinishedDate,
AssigneeId: fmt.Sprintf("%d", userStory.AssignedTo),
AssigneeName: userStory.AssignedToName,
}

if userStory.TotalPoints > 0 {
issue.StoryPoint = &userStory.TotalPoints
}

// Calculate lead time: creation → resolution for closed stories
if userStory.IsClosed && issue.CreatedDate != nil && issue.ResolutionDate != nil {
leadTimeMinutes := uint(issue.ResolutionDate.Sub(*issue.CreatedDate).Minutes())
if leadTimeMinutes > 0 {
issue.LeadTimeMinutes = &leadTimeMinutes
}
}

result = append(result, issue)

boardIssue := &ticket.BoardIssue{
Expand Down
60 changes: 41 additions & 19 deletions backend/plugins/taiga/tasks/user_story_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tasks

import (
"encoding/json"
"time"

"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
Expand Down Expand Up @@ -56,24 +57,34 @@ func ExtractUserStories(taskCtx plugin.SubTaskContext) errors.Error {
StatusExtraInfo struct {
Name string `json:"name"`
} `json:"status_extra_info"`
CreatedDate string `json:"created_date"`
ModifiedDate string `json:"modified_date"`
FinishDate *string `json:"finish_date"`
AssignedTo *uint64 `json:"assigned_to"`
TotalPoints *float64 `json:"total_points"`
MilestoneId *uint64 `json:"milestone"`
Priority *int `json:"priority"`
IsBlocked bool `json:"is_blocked"`
IsClosed bool `json:"is_closed"`
CreatedDate *time.Time `json:"created_date"`
ModifiedDate *time.Time `json:"modified_date"`
FinishDate *time.Time `json:"finish_date"`
AssignedTo *uint64 `json:"assigned_to"`
AssignedToExtraInfo *struct {
FullNameDisplay string `json:"full_name_display"`
} `json:"assigned_to_extra_info"`
TotalPoints *float64 `json:"total_points"`
MilestoneId *uint64 `json:"milestone"`
MilestoneName *string `json:"milestone_name"`
Priority *int `json:"priority"`
IsBlocked bool `json:"is_blocked"`
BlockedNote string `json:"blocked_note"`
}
err := json.Unmarshal(row.Data, &apiUserStory)
if err != nil {
return nil, errors.Default.Wrap(err, "error unmarshalling user story")
}

var assignedTo uint64
var assignedToName string
if apiUserStory.AssignedTo != nil {
assignedTo = *apiUserStory.AssignedTo
}
if apiUserStory.AssignedToExtraInfo != nil {
assignedToName = apiUserStory.AssignedToExtraInfo.FullNameDisplay
}
var totalPoints float64
if apiUserStory.TotalPoints != nil {
totalPoints = *apiUserStory.TotalPoints
Expand All @@ -82,23 +93,34 @@ func ExtractUserStories(taskCtx plugin.SubTaskContext) errors.Error {
if apiUserStory.MilestoneId != nil {
milestoneId = *apiUserStory.MilestoneId
}
var milestoneName string
if apiUserStory.MilestoneName != nil {
milestoneName = *apiUserStory.MilestoneName
}
var priority int
if apiUserStory.Priority != nil {
priority = *apiUserStory.Priority
}

userStory := &models.TaigaUserStory{
ConnectionId: data.Options.ConnectionId,
ProjectId: data.Options.ProjectId,
UserStoryId: apiUserStory.Id,
Ref: apiUserStory.Ref,
Subject: apiUserStory.Subject,
Status: apiUserStory.StatusExtraInfo.Name,
AssignedTo: assignedTo,
TotalPoints: totalPoints,
MilestoneId: milestoneId,
Priority: priority,
IsBlocked: apiUserStory.IsBlocked,
ConnectionId: data.Options.ConnectionId,
ProjectId: data.Options.ProjectId,
UserStoryId: apiUserStory.Id,
Ref: apiUserStory.Ref,
Subject: apiUserStory.Subject,
Status: apiUserStory.StatusExtraInfo.Name,
IsClosed: apiUserStory.IsClosed,
CreatedDate: apiUserStory.CreatedDate,
ModifiedDate: apiUserStory.ModifiedDate,
FinishedDate: apiUserStory.FinishDate,
AssignedTo: assignedTo,
AssignedToName: assignedToName,
TotalPoints: totalPoints,
MilestoneId: milestoneId,
MilestoneName: milestoneName,
Priority: priority,
IsBlocked: apiUserStory.IsBlocked,
BlockedNote: apiUserStory.BlockedNote,
}

return []interface{}{userStory}, nil
Expand Down
Loading