@@ -1441,44 +1441,54 @@ func (p *Plugin) getReposByOrg(c *UserContext, w http.ResponseWriter, r *http.Re
14411441
14421442 opt := github.ListOptions {PerPage : 50 }
14431443
1444- org := r .URL .Query ().Get ("organization" )
1444+ orgString := r .URL .Query ().Get ("organization" )
14451445
1446- if org == "" {
1446+ if orgString == "" {
14471447 c .Log .Warnf ("Organization query param is empty" )
14481448 p .writeAPIError (w , & APIErrorResponse {Message : "Organization query is empty, must include organization name " , StatusCode : http .StatusBadRequest })
14491449 return
14501450 }
14511451
1452+ orgList := strings .Split (orgString , "," )
14521453 var allRepos []* github.Repository
1453- var err error
1454- var statusCode int
14551454
1456- // If an organization is the username of an authenticated user then return repos where the authenticated user is the owner
1457- if org == c .GHInfo .GitHubUsername {
1458- allRepos , err = p .getRepositoryList (c .Ctx , c .GHInfo , "" , githubClient , opt )
1459- if err != nil {
1460- c .Log .WithError (err ).Errorf ("Failed to list repositories" )
1461- p .writeAPIError (w , & APIErrorResponse {Message : "Failed to fetch repositories" , StatusCode : http .StatusInternalServerError })
1462- return
1455+ for _ , org := range orgList {
1456+ org = strings .TrimSpace (org )
1457+ if org == "" {
1458+ continue
14631459 }
1464- } else {
1465- allRepos , statusCode , err = p .getRepositoryListByOrg (c .Ctx , c .GHInfo , org , githubClient , opt )
1466- if err != nil {
1467- if statusCode == http .StatusNotFound {
1468- allRepos , err = p .getRepositoryList (c .Ctx , c .GHInfo , org , githubClient , opt )
1469- if err != nil {
1470- c .Log .WithError (err ).Errorf ("Failed to list repositories" )
1471- p .writeAPIError (w , & APIErrorResponse {Message : "Failed to fetch repositories" , StatusCode : http .StatusInternalServerError })
1472- return
1460+
1461+ var repos []* github.Repository
1462+ var err error
1463+ var statusCode int
1464+
1465+ // If an organization is the username of an authenticated user then return repos where the authenticated user is the owner
1466+ if org == c .GHInfo .GitHubUsername {
1467+ repos , err = p .getRepositoryList (c .Ctx , c .GHInfo , "" , githubClient , opt )
1468+ if err != nil {
1469+ c .Log .WithError (err ).Errorf ("Failed to list repositories for user %s" , org )
1470+ continue
1471+ }
1472+ } else {
1473+ repos , statusCode , err = p .getRepositoryListByOrg (c .Ctx , c .GHInfo , org , githubClient , opt )
1474+ if err != nil {
1475+ if statusCode == http .StatusNotFound {
1476+ repos , err = p .getRepositoryList (c .Ctx , c .GHInfo , org , githubClient , opt )
1477+ if err != nil {
1478+ c .Log .WithError (err ).Errorf ("Failed to list repositories for org/user %s" , org )
1479+ continue
1480+ }
1481+ } else {
1482+ c .Log .WithError (err ).Warnf ("Failed to list repositories for org %s" , org )
1483+ continue
14731484 }
1474- } else {
1475- c .Log .WithError (err ).Warnf ("Failed to list repositories" )
1476- p .writeAPIError (w , & APIErrorResponse {Message : "Failed to fetch repositories" , StatusCode : statusCode })
1477- return
14781485 }
14791486 }
1487+
1488+ allRepos = append (allRepos , repos ... )
14801489 }
1481- // Only send repositories which are part of the requested organization
1490+
1491+ // Only send repositories which are part of the requested organization(s)
14821492 type RepositoryResponse struct {
14831493 Name string `json:"name,omitempty"`
14841494 FullName string `json:"full_name,omitempty"`
0 commit comments