dosubot[bot] commented on issue #7510:
URL:
https://github.com/apache/incubator-devlake/issues/7510#issuecomment-2129047501
<!-- Greeting -->
@michelengelen Hello there! I'm Dosu, a bot here to help you with bug fixes,
answer your questions, and guide you on becoming a contributor. I'm here to
assist you while you wait for a human maintainer.
<!-- Answer -->
To ensure that issues with removed labels are not included in the results
when querying for issues by label in GitHub, you need to filter the issues
based on their current labels. The provided code does not explicitly show how
to filter out issues with removed labels. However, you can modify the
`ExtractApiIssues` function to include this logic.
Here is an example of how you can modify the `ExtractApiIssues` function to
filter out issues that do not have the desired labels:
```go
func ExtractApiIssues(taskCtx plugin.SubTaskContext) errors.Error {
data := taskCtx.GetData().(*GithubTaskData)
config := data.Options.ScopeConfig
issueRegexes, err := NewIssueRegexes(config)
if err != nil {
return nil
}
extractor, err := api.NewApiExtractor(api.ApiExtractorArgs{
RawDataSubTaskArgs: api.RawDataSubTaskArgs{
Ctx: taskCtx,
Params: GithubApiParams{
ConnectionId: data.Options.ConnectionId,
Name: data.Options.Name,
},
Table: RAW_ISSUE_TABLE,
},
Extract: func(row *api.RawData) ([]interface{}, errors.Error) {
body := &IssuesResponse{}
err := errors.Convert(json.Unmarshal(row.Data, body))
if err != nil {
return nil, err
}
if body.GithubId == 0 || body.PullRequest.Url != "" {
return nil, nil
}
results := make([]interface{}, 0, 2)
desiredLabel := "status: waiting for maintainer" // Replace with
the label you are interested in
hasDesiredLabel := false
for _, label := range body.Labels {
if label.Name == desiredLabel {
hasDesiredLabel = true
break
}
}
if hasDesiredLabel {
githubIssue, err := convertGithubIssue(body,
data.Options.ConnectionId, data.Options.GithubId)
if err != nil {
return nil, err
}
githubLabels, err := convertGithubLabels(issueRegexes, body,
githubIssue)
if err != nil {
return nil, err
}
results = append(results, githubLabels...)
results = append(results, githubIssue)
if body.Assignee != nil {
githubIssue.AssigneeId = body.Assignee.Id
githubIssue.AssigneeName = body.Assignee.Login
relatedUser, err := convertAccount(body.Assignee,
data.Options.GithubId, data.Options.ConnectionId)
if err != nil {
return nil, err
}
results = append(results, relatedUser)
}
for _, assignee := range body.Assignees {
issueAssignee := &models.GithubIssueAssignee{
ConnectionId: githubIssue.ConnectionId,
IssueId: githubIssue.GithubId,
RepoId: githubIssue.RepoId,
AssigneeId: assignee.Id,
AssigneeName: assignee.Login,
}
results = append(results, issueAssignee)
}
if body.User != nil {
githubIssue.AuthorId = body.User.Id
githubIssue.AuthorName = body.User.Login
relatedUser, err := convertAccount(body.User,
data.Options.GithubId, data.Options.ConnectionId)
if err != nil {
return nil, err
}
results = append(results, relatedUser)
}
}
return results, nil
},
})
if err != nil {
return err
}
return extractor.Execute()
}
```
In this modified `ExtractApiIssues` function, the code iterates through each
issue and checks if it has the desired label. If it does, the issue is
processed and added to the results. This ensures that only issues with the
specified label are included in the results
<sup>[[1]](https://github.com/apache/incubator-devlake/blob/main/backend/plugins/github_graphql/tasks/issue_collector.go)</sup><sup>[[2]](https://github.com/apache/incubator-devlake/blob/main/backend/plugins/github_graphql/tasks/issue_extractor.go)</sup><sup>[[3]](https://github.com/apache/incubator-devlake/blob/main/backend/plugins/github/tasks/issue_extractor.go)</sup>.
<!-- Dosu Comment Footer -->
<details open>
<summary>
#### Details
</summary>
**About Dosu**
This response is meant to be useful and save you time. It is **not meant to
be a precise solution**, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is
irrelevant.
</details>
*To continue the conversation, mention @dosu.*
--
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]