Skip to content

Commit b040954

Browse files
Fix issue of repo/issue not listing when org lock has one invalid org among valid org list (#902)
* Fix issue of invalid repo not listing with orgs * fixed attach to issue modal
1 parent 2b912b1 commit b040954

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

server/plugin/api.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ func (p *Plugin) searchIssues(c *UserContext, w http.ResponseWriter, r *http.Req
855855
orgsList = []string{""}
856856
}
857857

858+
hasFetchedIssues := false
858859
for _, org := range orgsList {
859860
query := getIssuesSearchQuery(org, searchTerm)
860861
var result *github.IssuesSearchResult
@@ -868,11 +869,17 @@ func (p *Plugin) searchIssues(c *UserContext, w http.ResponseWriter, r *http.Req
868869
})
869870
if cErr != nil {
870871
c.Log.WithError(cErr).With(logger.LogContext{"query": query}).Warnf("Failed to search for issues")
871-
p.writeJSON(w, make([]*github.Issue, 0))
872-
return
873872
}
874873

875-
allIssues = append(allIssues, result.Issues...)
874+
if result != nil && len(result.Issues) > 0 {
875+
allIssues = append(allIssues, result.Issues...)
876+
hasFetchedIssues = true
877+
}
878+
}
879+
880+
if !hasFetchedIssues {
881+
p.writeJSON(w, make([]*github.Issue, 0))
882+
return
876883
}
877884

878885
p.writeJSON(w, allIssues)
@@ -1407,27 +1414,30 @@ func (p *Plugin) getRepositories(c *UserContext, w http.ResponseWriter, r *http.
14071414
}
14081415
} else {
14091416
orgsList := p.configuration.getOrganizations()
1417+
hasFetchedRepos := false
14101418
for _, org := range orgsList {
14111419
orgRepos, statusCode, err := p.getRepositoryListByOrg(c.Ctx, c.GHInfo, org, githubClient, opt)
14121420
if err != nil {
14131421
if statusCode == http.StatusNotFound {
14141422
orgRepos, err = p.getRepositoryList(c.Ctx, c.GHInfo, org, githubClient, opt)
14151423
if err != nil {
14161424
c.Log.WithError(err).Warnf("Failed to list repositories", "Organization", org)
1417-
p.writeAPIError(w, &APIErrorResponse{Message: "Failed to fetch repositories", StatusCode: http.StatusInternalServerError})
1418-
return
14191425
}
14201426
} else {
14211427
c.Log.WithError(err).Warnf("Failed to list repositories", "Organization", org)
1422-
p.writeAPIError(w, &APIErrorResponse{Message: "Failed to fetch repositories", StatusCode: http.StatusInternalServerError})
1423-
return
14241428
}
14251429
}
14261430

14271431
if len(orgRepos) > 0 {
14281432
allRepos = append(allRepos, orgRepos...)
1433+
hasFetchedRepos = true
14291434
}
14301435
}
1436+
1437+
if !hasFetchedRepos {
1438+
p.writeAPIError(w, &APIErrorResponse{Message: "Failed to fetch repositories", StatusCode: http.StatusInternalServerError})
1439+
return
1440+
}
14311441
}
14321442

14331443
repoResp := make([]RepoResponse, len(allRepos))

0 commit comments

Comments
 (0)