Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 41 additions & 16 deletions cmd/src/actions_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,40 +465,65 @@ query ActionRepos($query: String!) {
`
type Repository struct {
ID, Name string
DefaultBranch struct {
DefaultBranch *struct {
Name string
Target struct{ OID string }
}
}
var result struct {
Search struct {
Results struct {
Results []struct {
Typename string `json:"__typename"`
ID, Name string
DefaultBranch struct {
Name string
Target struct{ OID string }
Data struct {
Search struct {
Results struct {
Results []struct {
Typename string `json:"__typename"`
ID, Name string
DefaultBranch *struct {
Name string
Target struct{ OID string }
}
Repository Repository `json:"repository"`
}
Repository Repository `json:"repository"`
}
}
}
} `json:"data,omitempty"`

Errors []struct {
Message string
Path []interface{}
} `json:"errors,omitempty"`
}

if err := (&apiRequest{
query: query,
vars: map[string]interface{}{
"query": scopeQuery,
},
result: &result,
// Do not unpack errors and return error. Instead we want to go through
// the results and check whether they're complete.
// If we don't do this and the query returns an error for _one_
// repository because that is still cloning, we don't get any repositories.
// Instead we simply want to skip those repositories that are still
// being cloned.
dontUnpackErrors: true,
result: &result,
}).do(); err != nil {
return nil, nil, err

// Ignore exitCodeError with error == nil, because we explicitly set
// dontUnpackErrors, which can lead to an empty exitCodeErr being
// returned.
exitCodeErr, ok := err.(*exitCodeError)
if !ok {
return nil, nil, err
}
if exitCodeErr.error != nil {
return nil, nil, exitCodeErr
}
}

skipped := []string{}
reposByID := map[string]ActionRepo{}
for _, searchResult := range result.Search.Results.Results {
for _, searchResult := range result.Data.Search.Results.Results {

var repo Repository
if searchResult.Repository.ID != "" {
repo = searchResult.Repository
Expand All @@ -510,8 +535,8 @@ query ActionRepos($query: String!) {
}
}

if repo.DefaultBranch.Name == "" {
skipped = append(skipped, repo.Name)
if repo.DefaultBranch == nil || repo.DefaultBranch.Name == "" {
skipped = append(skipped, searchResult.Repository.Name)
continue
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/src/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ type exitCodeError struct {
exitCode int
}

func (e *exitCodeError) Error() string {
if e.error != nil {
return fmt.Sprintf("%s (exit code: %d)", e.error, e.exitCode)
}
return fmt.Sprintf("exit code: %d", e.exitCode)
}

const (
graphqlErrorsExitCode = 2
)
Expand Down