likyh commented on code in PR #2416:
URL: https://github.com/apache/incubator-devlake/pull/2416#discussion_r931875378
##########
plugins/github/tasks/issue_extractor.go:
##########
@@ -59,170 +45,6 @@ type IssuesResponse struct {
GithubUpdatedAt helper.Iso8601Time `json:"updated_at"`
}
-func ExtractApiIssues(taskCtx core.SubTaskContext) error {
- data := taskCtx.GetData().(*GithubTaskData)
- config := data.Options.TransformationRules
- var issueSeverityRegex *regexp.Regexp
- var issueComponentRegex *regexp.Regexp
- var issuePriorityRegex *regexp.Regexp
- var issueTypeBugRegex *regexp.Regexp
- var issueTypeRequirementRegex *regexp.Regexp
- var issueTypeIncidentRegex *regexp.Regexp
- var issueSeverity = config.IssueSeverity
- var err error
- if len(issueSeverity) > 0 {
- issueSeverityRegex, err = regexp.Compile(issueSeverity)
- if err != nil {
- return fmt.Errorf("regexp Compile issueSeverity
failed:[%s] stack:[%s]", err.Error(), debug.Stack())
- }
- }
- var issueComponent = config.IssueComponent
- if len(issueComponent) > 0 {
- issueComponentRegex, err = regexp.Compile(issueComponent)
- if err != nil {
- return fmt.Errorf("regexp Compile issueComponent
failed:[%s] stack:[%s]", err.Error(), debug.Stack())
- }
- }
- var issuePriority = config.IssuePriority
- if len(issuePriority) > 0 {
- issuePriorityRegex, err = regexp.Compile(issuePriority)
- if err != nil {
- return fmt.Errorf("regexp Compile issuePriority
failed:[%s] stack:[%s]", err.Error(), debug.Stack())
- }
- }
- var issueTypeBug = config.IssueTypeBug
- if len(issueTypeBug) > 0 {
- issueTypeBugRegex, err = regexp.Compile(issueTypeBug)
- if err != nil {
- return fmt.Errorf("regexp Compile issueTypeBug
failed:[%s] stack:[%s]", err.Error(), debug.Stack())
- }
- }
- var issueTypeRequirement = config.IssueTypeRequirement
- if len(issueTypeRequirement) > 0 {
- issueTypeRequirementRegex, err =
regexp.Compile(issueTypeRequirement)
- if err != nil {
- return fmt.Errorf("regexp Compile issueTypeRequirement
failed:[%s] stack:[%s]", err.Error(), debug.Stack())
- }
- }
- var issueTypeIncident = config.IssueTypeIncident
- if len(issueTypeIncident) > 0 {
- issueTypeIncidentRegex, err = regexp.Compile(issueTypeIncident)
- if err != nil {
- return fmt.Errorf("regexp Compile issueTypeIncident
failed:[%s] stack:[%s]", err.Error(), debug.Stack())
- }
- }
-
- 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: GithubApiParams{
- ConnectionId: data.Options.ConnectionId,
- Owner: data.Options.Owner,
- Repo: data.Options.Repo,
- },
- /*
- 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.GithubId == 0 {
- return nil, nil
- }
- //If this is a pr, ignore
- if body.PullRequest.Url != "" {
- return nil, nil
- }
- results := make([]interface{}, 0, 2)
- githubIssue, err := convertGithubIssue(body,
data.Options.ConnectionId, data.Repo.GithubId)
- if err != nil {
- return nil, err
- }
- if body.Assignee != nil {
- githubIssue.AssigneeId = body.Assignee.Id
- githubIssue.AssigneeName = body.Assignee.Login
- relatedUser, err := convertUser(body.Assignee,
data.Options.ConnectionId)
- if err != nil {
- return nil, err
- }
- results = append(results, relatedUser)
- }
- if body.User != nil {
- githubIssue.AuthorId = body.User.Id
- githubIssue.AuthorName = body.User.Login
- relatedUser, err := convertUser(body.User,
data.Options.ConnectionId)
- if err != nil {
- return nil, err
- }
- results = append(results, relatedUser)
- }
- for _, label := range body.Labels {
- results = append(results,
&models.GithubIssueLabel{
- ConnectionId: data.Options.ConnectionId,
- IssueId: githubIssue.GithubId,
- LabelName: label.Name,
- })
- if issueSeverityRegex != nil {
- groups :=
issueSeverityRegex.FindStringSubmatch(label.Name)
- if len(groups) > 0 {
- githubIssue.Severity = groups[1]
- }
- }
-
- if issueComponentRegex != nil {
- groups :=
issueComponentRegex.FindStringSubmatch(label.Name)
- if len(groups) > 0 {
- githubIssue.Component =
groups[1]
- }
- }
-
- if issuePriorityRegex != nil {
- groups :=
issuePriorityRegex.FindStringSubmatch(label.Name)
- if len(groups) > 0 {
- githubIssue.Priority = groups[1]
- }
- }
-
- if issueTypeBugRegex != nil {
- if ok :=
issueTypeBugRegex.MatchString(label.Name); ok {
- githubIssue.Type = ticket.BUG
- }
- }
-
- if issueTypeRequirementRegex != nil {
- if ok :=
issueTypeRequirementRegex.MatchString(label.Name); ok {
- githubIssue.Type =
ticket.REQUIREMENT
- }
- }
-
- if issueTypeIncidentRegex != nil {
- if ok :=
issueTypeIncidentRegex.MatchString(label.Name); ok {
- githubIssue.Type =
ticket.INCIDENT
- }
- }
- }
- results = append(results, githubIssue)
-
- return results, nil
- },
- })
-
- if err != nil {
- return err
- }
-
- return extractor.Execute()
-}
func convertGithubIssue(issue *IssuesResponse, connectionId uint64,
repositoryId int) (*models.GithubIssue, error) {
Review Comment:
yeah~ you are 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]