warren830 commented on code in PR #1968:
URL: https://github.com/apache/incubator-devlake/pull/1968#discussion_r882304201


##########
plugins/gitlab/models/migrationscripts/archived/issue.go:
##########
@@ -0,0 +1,33 @@
+package archived
+
+import (
+       "github.com/apache/incubator-devlake/models/migrationscripts/archived"
+       "time"
+)
+
+type GitlabIssue struct {
+       GitlabId        int    `gorm:"primaryKey"`
+       ProjectId       int    `gorm:"index"`
+       Number          int    `gorm:"index;comment:Used in API requests ex. 
api/repo/1/issue/<THIS_NUMBER>"`
+       State           string `gorm:"type:varchar(255)"`
+       Title           string
+       Body            string
+       Priority        string `gorm:"type:varchar(255)"`
+       Type            string `gorm:"type:varchar(100)"`
+       Status          string `gorm:"type:varchar(255)"`
+       AssigneeId      int
+       AssigneeName    string `gorm:"type:varchar(255)"`
+       LeadTimeMinutes uint
+       Url             string `gorm:"type:varchar(255)"`
+       ClosedAt        *time.Time
+       GitlabCreatedAt time.Time
+       GitlabUpdatedAt time.Time `gorm:"index"`
+       Severity        string    `gorm:"type:varchar(255)"`
+       Component       string    `gorm:"type:varchar(255)"`
+       TimeEstimate    int64
+       TotalTimeSpent  int64
+       archived.NoPKModel
+}
+func (GitlabIssue) TableName() string {
+       return "_tool_gitlab_issues"
+}

Review Comment:
   move all code of this file to update_schemas20220525, and delete this file



##########
plugins/gitlab/models/migrationscripts/archived/issue_label.go:
##########
@@ -0,0 +1,15 @@
+package archived
+
+import (
+       "github.com/apache/incubator-devlake/models/migrationscripts/archived"
+)
+
+type GitlabIssueLabel struct {
+       IssueId   int    `gorm:"primaryKey;autoIncrement:false"`
+       LabelName string `gorm:"primaryKey;type:varchar(255)"`
+       archived.NoPKModel
+}
+
+func (GitlabIssueLabel) TableName() string{
+       return "_tool_gitlab_issue_labels"
+}

Review Comment:
   move all code of this file to update_schemas20220525, and delete this file



##########
plugins/gitlab/tasks/issue_extractor.go:
##########
@@ -0,0 +1,195 @@
+package tasks
+
+import (
+       "encoding/json"
+       "github.com/apache/incubator-devlake/plugins/core"
+
+       "github.com/apache/incubator-devlake/plugins/gitlab/models"
+       "github.com/apache/incubator-devlake/plugins/helper"
+)
+
+var ExtractApiIssuesMeta = core.SubTaskMeta{
+       Name:             "extractApiIssues",
+       EntryPoint:       ExtractApiIssues,
+       EnabledByDefault: true,
+       Description:      "Extract raw Issues data into tool layer table 
gitlab_issues",
+}
+
+type IssuesResponse struct {
+       ProjectId    int `json:"id"`

Review Comment:
   should be `json:project_id`



##########
plugins/gitlab/tasks/issue_extractor.go:
##########
@@ -0,0 +1,195 @@
+package tasks
+
+import (
+       "encoding/json"
+       "github.com/apache/incubator-devlake/plugins/core"
+
+       "github.com/apache/incubator-devlake/plugins/gitlab/models"
+       "github.com/apache/incubator-devlake/plugins/helper"
+)
+
+var ExtractApiIssuesMeta = core.SubTaskMeta{
+       Name:             "extractApiIssues",
+       EntryPoint:       ExtractApiIssues,
+       EnabledByDefault: true,
+       Description:      "Extract raw Issues data into tool layer table 
gitlab_issues",
+}
+
+type IssuesResponse struct {
+       ProjectId    int `json:"id"`
+       Milestone    struct {
+               Due_date        string
+               Project_id      int
+               State           string
+               Description string
+               Iid             int
+               Id                      int
+               Title           string
+               CreatedAt helper.Iso8601Time
+               UpdatedAt helper.Iso8601Time
+       }
+       Author struct{
+               State           string
+               WebUrl          string
+               AvatarUrl       string
+               Username        string
+               Id                      int
+               Name            string
+       }
+       Description     string
+       State                   string
+       Iid                     int
+       Assignees []struct {
+               AvatarUrl       string
+               WebUrl          string
+               State           string
+               Username        string
+               Id                      int
+               Name            string
+       }
+       Assignee *struct {
+               AvatarUrl       string
+               WebUrl          string
+               State           string
+               Username        string
+               Id                      int
+               Name            string
+       }
+       Type                            string
+       Labels                          []string `json:"labels"`
+       UpVotes                         int
+       DownVotes                       int
+       MergeRequestsCount      int
+       Id                                      int
+       Title                   string
+       GitlabUpdatedAt helper.Iso8601Time  `json:"updated_at"`
+       GitlabCreatedAt helper.Iso8601Time  `json:"created_at"`
+       GitlabClosedAt  *helper.Iso8601Time `json:"closed_at"`
+       ClosedBy struct{
+               State           string
+               WebUrl          string
+               AvatarUrl       string
+               Username        string
+               Id                      int
+               Name            string
+       }
+       UserNotesCount int
+       DueDate helper.Iso8601Time
+       WebUrl string   `json:"web_url"`
+       References struct {
+               Short           string
+               Relative        string
+               Full            string
+       }
+       TimeStats struct {
+               TimeEstimate            int64
+               TotalTimeSpent          int64
+               HumanTimeEstimate       string
+               HumanTotalTimeSpent string
+       }
+       HasTasks                bool
+       TaskStatus              string
+       Confidential    bool
+       DiscussionLocked bool
+       IssueType               string
+       Serverity               string
+       Links struct {
+               Self            string  `json:"url"`
+               Notes           string
+               AwardEmoji      string
+               Project         string
+       }
+       TaskCompletionStatus struct {
+               Count                   int
+               CompletedCount  int
+       }
+
+}
+
+func ExtractApiIssues(taskCtx core.SubTaskContext) error {
+       data := taskCtx.GetData().(*GitlabTaskData)
+
+       extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+               RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+                       Ctx: taskCtx,
+                       /*
+                               This struct will be JSONEncoded and stored into 
database along with raw data itself, to identity minimal
+                               set of data to be process, for example, we 
process JiraIssues by Board
+                       */
+                       Params: GitlabApiParams{
+                               ProjectId: data.Options.ProjectId,
+                       },
+                       /*
+                               Table store raw data
+                       */
+                       Table: RAW_ISSUE_TABLE,
+               },
+               Extract: func(row *helper.RawData) ([]interface{}, error) {
+                       body := &IssuesResponse{}
+                       err := json.Unmarshal(row.Data, body)
+                       if err != nil {
+                               return nil, err
+                       }
+                       // need to extract 2 kinds of entities here
+                       if body.ProjectId == 0 {
+                               return nil, nil
+                       }
+                       ////If this is a pr, ignore
+                       //if body.PullRequest.Url != "" {
+                       //      return nil, nil
+                       //}
+                       //If this is not Issue, ignore
+                       if body.IssueType != "ISSUE" {
+                               return nil, nil
+                       }
+                       results := make([]interface{}, 0, 2)
+                       gitlabIssue, err := convertGitlabIssue(body, 
data.Options.ProjectId)
+                       if err != nil {
+                               return nil, err
+                       }
+
+                       for _, label := range body.Labels {
+                               results = append(results, 
&models.GitlabIssueLabel{
+                                       IssueId:   gitlabIssue.GitlabId,
+                                       LabelName: label,
+                               })
+
+                       }
+                       results = append(results, gitlabIssue)
+
+                       return results, nil
+               },
+       })
+
+       if err != nil {
+               return err
+       }
+
+       return extractor.Execute()
+}
+func convertGitlabIssue(issue *IssuesResponse, projectId int) 
(*models.GitlabIssue, error) {
+       gitlabIssue := &models.GitlabIssue{
+               GitlabId:        issue.Id,
+               ProjectId:       projectId,
+               Number:          issue.Iid,
+               State:           issue.State,
+               Title:           issue.Title,
+               Body:            issue.Description,
+               Url:             issue.Links.Self,
+               ClosedAt:        helper.Iso8601TimeToTime(issue.GitlabClosedAt),

Review Comment:
   this seems not right



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to