(taskCtx plugin.SubTaskContext)
| 79 | } |
| 80 | |
| 81 | func ExtractApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error { |
| 82 | rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PULL_REQUEST_TABLE) |
| 83 | config := data.Options.ScopeConfig |
| 84 | var labelTypeRegex *regexp.Regexp |
| 85 | var labelComponentRegex *regexp.Regexp |
| 86 | var prType = config.PrType |
| 87 | var err error |
| 88 | if len(prType) > 0 { |
| 89 | labelTypeRegex, err = regexp.Compile(prType) |
| 90 | if err != nil { |
| 91 | return errors.Default.Wrap(err, "regexp Compile prType failed") |
| 92 | } |
| 93 | } |
| 94 | var prComponent = config.PrComponent |
| 95 | if len(prComponent) > 0 { |
| 96 | labelComponentRegex, err = regexp.Compile(prComponent) |
| 97 | if err != nil { |
| 98 | return errors.Default.Wrap(err, "regexp Compile prComponent failed") |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | extractor, err := api.NewApiExtractor(api.ApiExtractorArgs{ |
| 103 | RawDataSubTaskArgs: *rawDataSubTaskArgs, |
| 104 | Extract: func(row *api.RawData) ([]interface{}, errors.Error) { |
| 105 | pullResponse := &GiteeApiPullResponse{} |
| 106 | err := errors.Convert(json.Unmarshal(row.Data, pullResponse)) |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | |
| 111 | // need to extract 2 kinds of entities here |
| 112 | results := make([]interface{}, 0, 1) |
| 113 | if pullResponse.GiteeId == 0 { |
| 114 | return nil, nil |
| 115 | } |
| 116 | giteePr, err := convertGiteePullRequest(pullResponse, data.Options.ConnectionId, data.Repo.GiteeId) |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | for _, label := range pullResponse.Labels { |
| 121 | results = append(results, &models.GiteePullRequestLabel{ |
| 122 | ConnectionId: data.Options.ConnectionId, |
| 123 | PullId: giteePr.GiteeId, |
| 124 | LabelName: label.Name, |
| 125 | }) |
| 126 | // if pr.Type has not been set and prType is set in .env, process the below |
| 127 | if labelTypeRegex != nil && labelTypeRegex.MatchString(label.Name) { |
| 128 | giteePr.Type = label.Name |
| 129 | } |
| 130 | // if pr.Component has not been set and prComponent is set in .env, process |
| 131 | if labelComponentRegex != nil && labelComponentRegex.MatchString(label.Name) { |
| 132 | giteePr.Component = label.Name |
| 133 | } |
| 134 | } |
| 135 | results = append(results, giteePr) |
| 136 | |
| 137 | return results, nil |
| 138 | }, |
nothing calls this directly
no test coverage detected