Skip to content

Commit 824ef3a

Browse files
committed
fetch all project data
1 parent 3881d6e commit 824ef3a

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

api/queries_project.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@ import (
1010
"github.com/cli/cli/internal/ghrepo"
1111
)
1212

13-
func (c Client) GetProject(baseRepo ghrepo.Interface, projectID string) ([]byte, error) {
14-
url := fmt.Sprintf("%sprojects/%s",
15-
ghinstance.RESTPrefix(baseRepo.RepoHost()), projectID)
16-
13+
func (c Client) projectREST(url string) ([]byte, error) {
1714
req, err := http.NewRequest("GET", url, nil)
1815
if err != nil {
1916
return nil, err
2017
}
2118

22-
// TODO api() { gh api -H 'accept: application/vnd.github.inertia-preview+json' "$@"; }
2319
req.Header.Set("Accept", "application/vnd.github.inertia-preview+json; charset=utf-8")
2420

2521
resp, err := c.http.Do(req)
@@ -40,3 +36,24 @@ func (c Client) GetProject(baseRepo ghrepo.Interface, projectID string) ([]byte,
4036

4137
return data, nil
4238
}
39+
40+
func (c Client) GetProject(baseRepo ghrepo.Interface, projectID int) ([]byte, error) {
41+
url := fmt.Sprintf("%sprojects/%d", ghinstance.RESTPrefix(baseRepo.RepoHost()), projectID)
42+
43+
return c.projectREST(url)
44+
}
45+
46+
func (c Client) GetProjectColumns(baseRepo ghrepo.Interface, projectID int) ([]byte, error) {
47+
url := fmt.Sprintf("%sprojects/%d/columns",
48+
ghinstance.RESTPrefix(baseRepo.RepoHost()), projectID)
49+
50+
return c.projectREST(url)
51+
52+
}
53+
54+
func (c Client) GetProjectCards(baseRepo ghrepo.Interface, columnID int) ([]byte, error) {
55+
url := fmt.Sprintf("%sprojects/columns/%d/cards",
56+
ghinstance.RESTPrefix(baseRepo.RepoHost()), columnID)
57+
58+
return c.projectREST(url)
59+
}

pkg/cmd/project/project.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewCmdProject(f *cmdutil.Factory, runF func(*ProjectOptions) error) *cobra.
4949

5050
func projectRun(opts *ProjectOptions) error {
5151
// TODO interactively ask which project they want since these IDs are not easy to get
52-
projectID := "3514315"
52+
projectID := 3514315
5353

5454
c, err := opts.HttpClient()
5555
if err != nil {
@@ -69,14 +69,31 @@ func projectRun(opts *ProjectOptions) error {
6969

7070
fmt.Printf("DBG %#v\n", project)
7171

72+
for _, c := range project.Columns {
73+
fmt.Printf("DBG %s: %d cards\n", c.Name, len(c.Cards))
74+
}
75+
7276
return nil
7377
}
7478

79+
type Card struct {
80+
Note string
81+
ID int
82+
}
83+
84+
type Column struct {
85+
Name string
86+
ID int
87+
Cards []*Card
88+
}
89+
7590
type Project struct {
76-
Name string
91+
Name string
92+
ID int
93+
Columns []*Column
7794
}
7895

79-
func getProject(client *api.Client, baseRepo ghrepo.Interface, projectID string) (*Project, error) {
96+
func getProject(client *api.Client, baseRepo ghrepo.Interface, projectID int) (*Project, error) {
8097
data, err := client.GetProject(baseRepo, projectID)
8198
if err != nil {
8299
return nil, err
@@ -89,5 +106,27 @@ func getProject(client *api.Client, baseRepo ghrepo.Interface, projectID string)
89106
return nil, err
90107
}
91108

109+
data, err = client.GetProjectColumns(baseRepo, projectID)
110+
if err != nil {
111+
return nil, err
112+
}
113+
114+
err = json.Unmarshal(data, &project.Columns)
115+
if err != nil {
116+
return nil, err
117+
}
118+
119+
for _, column := range project.Columns {
120+
data, err := client.GetProjectCards(baseRepo, column.ID)
121+
if err != nil {
122+
return nil, err
123+
}
124+
125+
err = json.Unmarshal(data, &column.Cards)
126+
if err != nil {
127+
return nil, err
128+
}
129+
}
130+
92131
return project, nil
93132
}

0 commit comments

Comments
 (0)