forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries_project.go
More file actions
63 lines (47 loc) · 1.46 KB
/
queries_project.go
File metadata and controls
63 lines (47 loc) · 1.46 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package api
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"github.com/cli/cli/internal/ghinstance"
"github.com/cli/cli/internal/ghrepo"
)
func (c Client) projectREST(url string) ([]byte, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/vnd.github.inertia-preview+json; charset=utf-8")
resp, err := c.http.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode == 404 {
return nil, &NotFoundError{errors.New("pull request not found")}
} else if resp.StatusCode != 200 {
return nil, HandleHTTPError(resp)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return data, nil
}
func (c Client) GetProject(baseRepo ghrepo.Interface, projectID int) ([]byte, error) {
url := fmt.Sprintf("%sprojects/%d", ghinstance.RESTPrefix(baseRepo.RepoHost()), projectID)
return c.projectREST(url)
}
func (c Client) GetProjectColumns(baseRepo ghrepo.Interface, projectID int) ([]byte, error) {
url := fmt.Sprintf("%sprojects/%d/columns",
ghinstance.RESTPrefix(baseRepo.RepoHost()), projectID)
return c.projectREST(url)
}
func (c Client) GetProjectCards(baseRepo ghrepo.Interface, columnID int) ([]byte, error) {
url := fmt.Sprintf("%sprojects/columns/%d/cards",
ghinstance.RESTPrefix(baseRepo.RepoHost()), columnID)
return c.projectREST(url)
}
func (c Client) GetProjectCardContent(contentURL string) ([]byte, error) {
return c.projectREST(contentURL)
}