klesh commented on code in PR #8820:
URL: 
https://github.com/apache/incubator-devlake/pull/8820#discussion_r3021309173


##########
backend/plugins/github_graphql/tasks/issue_collector.go:
##########
@@ -206,3 +231,95 @@ func CollectIssues(taskCtx plugin.SubTaskContext) 
errors.Error {
 
        return apiCollector.Execute()
 }
+
+func findMissingGithubIssues(requestedIssues map[int]missingGithubIssueRef, 
resolvedIssues []GraphqlQueryIssue) []missingGithubIssueRef {
+       if len(requestedIssues) == 0 {

Review Comment:
   Should we return on `len(requestedIssues) == len(resolvedIssues)` as well?



##########
backend/plugins/github_graphql/tasks/issue_collector.go:
##########
@@ -206,3 +231,95 @@ func CollectIssues(taskCtx plugin.SubTaskContext) 
errors.Error {
 
        return apiCollector.Execute()
 }
+
+func findMissingGithubIssues(requestedIssues map[int]missingGithubIssueRef, 
resolvedIssues []GraphqlQueryIssue) []missingGithubIssueRef {
+       if len(requestedIssues) == 0 {
+               return nil
+       }
+
+       resolvedNumbers := make(map[int]struct{}, len(resolvedIssues))
+       for _, issue := range resolvedIssues {
+               if issue.DatabaseId == 0 || issue.Number == 0 {
+                       continue
+               }
+               resolvedNumbers[issue.Number] = struct{}{}
+       }
+
+       missingIssues := make([]missingGithubIssueRef, 0)
+       for number, issue := range requestedIssues {
+               if _, ok := resolvedNumbers[number]; ok {
+                       continue
+               }
+               missingIssues = append(missingIssues, issue)
+       }
+       sort.Slice(missingIssues, func(i, j int) bool {
+               return missingIssues[i].Number < missingIssues[j].Number
+       })
+       return missingIssues
+}
+
+func cleanupMissingGithubIssues(db dal.Dal, logger log.Logger, issues 
[]missingGithubIssueRef) errors.Error {
+       var allErrors []error
+       for _, issue := range issues {
+               logger.Warn(nil, "GitHub issue #%d no longer resolves from the 
source API, deleting stale local data", issue.Number)
+               err := cleanupMissingGithubIssue(db, issue)
+               if err != nil {
+                       allErrors = append(allErrors, err)
+               }
+       }
+       return errors.Default.Combine(allErrors)
+}
+
+func cleanupMissingGithubIssue(db dal.Dal, issue missingGithubIssueRef) 
errors.Error {
+       deleteByIssueId := func(model any, table string) errors.Error {
+               err := db.Delete(model, dal.From(table), 
dal.Where("connection_id = ? AND issue_id = ?", issue.ConnectionId, 
issue.GithubId))

Review Comment:
   Is it possible to move an issue from one repository to another when both 
repos are already configured in Apache DevLake?



-- 
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