Skip to content

Commit e50cd96

Browse files
committed
Use repo name instead of full_name, refs #3
1 parent bf846bd commit e50cd96

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

src/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
)
2222

2323
type repo struct {
24-
Name string `json:"full_name"`
24+
Name string `json:"name"`
2525
URL string `json:"html_url"`
2626
IsFork bool `json:"fork"`
2727
Owner struct {

src/cli_test.go

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ func TestUnmarshalRepo(t *testing.T) {
1919
t.Parallel()
2020
// Example JSON string that represents a repo's data
2121
jsonString := `{
22-
"full_name": "example/repo",
23-
"html_url": "https://github.com/example/repo",
22+
"name": "test-repo",
23+
"html_url": "https://github.com/test-owner/test-repo",
2424
"fork": false,
2525
"owner": {
26-
"name": "example"
26+
"name": "test-owner"
2727
},
2828
"updated_at": "2020-01-01T00:00:00Z"
2929
}`
3030

3131
// Expected repo object based on the JSON string
3232
expected := repo{
33-
Name: "example/repo",
34-
URL: "https://github.com/example/repo",
33+
Name: "test-repo",
34+
URL: "https://github.com/test-owner/test-repo",
3535
IsFork: false,
3636
Owner: struct {
3737
Name string `json:"name"`
3838
}{
39-
Name: "example",
39+
Name: "test-owner",
4040
},
4141
UpdatedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
4242
}
@@ -65,26 +65,34 @@ func TestFetchForkedReposPage(t *testing.T) {
6565
w.WriteHeader(http.StatusOK)
6666
fmt.Fprintln(
6767
w,
68-
`[{"full_name": "example/forkedrepo",`+
69-
`"html_url": "https://github.com/example/forkedrepo", "fork": true,`+
70-
`"owner": {"name": "example"}, "updated_at": "2020-01-01T00:00:00Z"}]`)
68+
`[{"name": "test-forked-repo",`+
69+
`"html_url": "https://github.com/test-owner/test-forked-repo", "fork": true,`+
70+
`"owner": {"name": "test-owner"}, "updated_at": "2020-01-01T00:00:00Z"}]`)
7171
}))
7272
defer mockServer.Close()
7373

7474
expected := []repo{
7575
{
76-
Name: "example/forkedrepo",
77-
URL: "https://github.com/example/forkedrepo",
76+
Name: "test-forked-repo",
77+
URL: "https://github.com/test-owner/test-forked-repo",
7878
IsFork: true,
7979
Owner: struct {
8080
Name string `json:"name"`
81-
}{Name: "example"},
81+
}{Name: "test-owner"},
8282
UpdatedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
8383
},
8484
}
8585

8686
forkedRepos, err := fetchForkedReposPage(
87-
context.Background(), mockServer.URL, "example", "fake-token", 1, 10, 60)
87+
context.Background(), // ctx
88+
mockServer.URL, // baseURL
89+
"test-owner", // owner
90+
"test-token", // token
91+
1, // pageNum
92+
10, // perPage
93+
60, // olderThanDays
94+
)
95+
8896
if err != nil {
8997
t.Fatalf("fetchForkedReposPage returned an error: %v", err)
9098
}
@@ -112,47 +120,48 @@ func TestFetchForkedRepos(t *testing.T) {
112120
w.WriteHeader(http.StatusOK)
113121
fmt.Fprintln(
114122
w,
115-
`[{"full_name": "example/forkedrepo",`+
116-
`"html_url": "https://test.com/example/forkedrepo", "fork": true,`+
117-
`"owner": {"name": "example"}, "updated_at": "2020-01-01T00:00:00Z"},`+
123+
`[{"name": "test-repo-1",`+
124+
`"html_url": "https://test.com/test-owner/test-repo-1", "fork": true,`+
125+
`"owner": {"name": "test-owner"}, "updated_at": "2020-01-01T00:00:00Z"},`+
118126

119-
`{"full_name": "example/forkedrepo2",`+
120-
`"html_url": "https://test.com/example/forkedrepo2", "fork": true,`+
121-
`"owner": {"name": "example2"}, "updated_at": "2020-01-01T00:00:00Z"}]`)
127+
`{"name": "test-repo-2",`+
128+
`"html_url": "https://test.com/test-owner/test-repo-2", "fork": true,`+
129+
`"owner": {"name": "test-owner"}, "updated_at": "2020-01-01T00:00:00Z"}]`)
122130

123131
}))
124132

125133
defer mockServer.Close()
126134

127135
expected := []repo{
128136
{
129-
Name: "example/forkedrepo",
130-
URL: "https://test.com/example/forkedrepo",
137+
Name: "test-repo-1",
138+
URL: "https://test.com/test-owner/test-repo-1",
131139
IsFork: true,
132140
Owner: struct {
133141
Name string `json:"name"`
134-
}{Name: "example"},
142+
}{Name: "test-owner"},
135143
UpdatedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
136144
},
137145
{
138-
Name: "example/forkedrepo2",
139-
URL: "https://test.com/example/forkedrepo2",
146+
Name: "test-repo-2",
147+
URL: "https://test.com/test-owner/test-repo-2",
140148
IsFork: true,
141149
Owner: struct {
142150
Name string `json:"name"`
143-
}{Name: "example2"},
151+
}{Name: "test-owner"},
144152
UpdatedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
145153
},
146154
}
147155

148156
forkedRepos, err := fetchForkedRepos(
149-
context.Background(),
150-
mockServer.URL,
151-
"example",
152-
"fake-token",
153-
10,
154-
1,
155-
60)
157+
context.Background(), // ctx
158+
mockServer.URL, // baseURL
159+
"test-owner", // owner
160+
"test-token", // token
161+
10, // perPage
162+
1, // maxPage
163+
60, // olderThanDays
164+
)
156165
if err != nil {
157166
t.Fatalf("fetchForkedRepos returned an error: %v", err)
158167
}

0 commit comments

Comments
 (0)