forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries_repo.go
More file actions
46 lines (38 loc) · 937 Bytes
/
queries_repo.go
File metadata and controls
46 lines (38 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package api
import (
"fmt"
"github.com/pkg/errors"
)
// Repository contains information about a GitHub repo
type Repository struct {
ID string
HasIssuesEnabled bool
}
// GitHubRepo looks up the node ID of a named repository
func GitHubRepo(client *Client, ghRepo Repo) (*Repository, error) {
owner := ghRepo.RepoOwner()
repo := ghRepo.RepoName()
query := `
query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
id
hasIssuesEnabled
}
}`
variables := map[string]interface{}{
"owner": owner,
"name": repo,
}
result := struct {
Repository Repository
}{}
err := client.GraphQL(query, variables, &result)
if err != nil || result.Repository.ID == "" {
newErr := fmt.Errorf("failed to determine repository ID for '%s/%s'", owner, repo)
if err != nil {
newErr = errors.Wrap(err, newErr.Error())
}
return nil, newErr
}
return &result.Repository, nil
}