Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of getRepositoryID #684

Merged
merged 2 commits into from
Feb 2, 2021
Merged
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
20 changes: 11 additions & 9 deletions github/util_v4_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ package github
import (
"context"
"encoding/base64"
"errors"

"github.com/shurcooL/githubv4"
)

func getRepositoryID(name string, meta interface{}) (githubv4.ID, error) {

// Interperet `name` as a node ID and return
exists, err := repositoryNodeIDExists(name, meta)
// Interpret `name` as a node ID
exists, nodeIDerr := repositoryNodeIDExists(name, meta)
if exists {
return githubv4.ID(name), nil
}
if err != nil {
Copy link
Contributor Author

@k24dizzle k24dizzle Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described here: #597 (comment) there are some repo names that are base64 decodable (wiki, abcdefgh) and as a result an error would be returned here. Instead of returning an error, go ahead and try finding the repo by repo name anyways as fallback logic.

return nil, err
}

// Resolve `name` to a node ID and return
// Could not find repo by node ID, interpret `name` as repo name
var query struct {
Repository struct {
ID githubv4.ID
Expand All @@ -30,9 +28,13 @@ func getRepositoryID(name string, meta interface{}) (githubv4.ID, error) {
}
ctx := context.Background()
client := meta.(*Owner).v4client
err = client.Query(ctx, &query, variables)
if err != nil {
return nil, err
nameErr := client.Query(ctx, &query, variables)
if nameErr != nil {
if nodeIDerr != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be failing nicely when branch protection doesn't exist

// Could not find repo by node ID or repo name, return both errors
return nil, errors.New(nodeIDerr.Error() + nameErr.Error())
}
return nil, nameErr
}

return query.Repository.ID, nil
Expand Down