Skip to content

Commit 5ea7b45

Browse files
committed
fix runtime errors
1 parent 6e91b5f commit 5ea7b45

File tree

5 files changed

+12
-29
lines changed

5 files changed

+12
-29
lines changed

cmd/gh-classroom/clone/student-repos/student-repos.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func NewCmdStudentRepo(f *cmdutil.Factory) *cobra.Command {
2222
var page int
2323
var perPage int
2424
var getAll bool
25+
var verbose bool
2526

2627
cmd := &cobra.Command{
2728
Use: "student-repos",
@@ -90,9 +91,10 @@ func NewCmdStudentRepo(f *cmdutil.Factory) *cobra.Command {
9091
}
9192

9293
totalCloned := 0
94+
cloneErrors := []string{}
9395
for _, acceptAssignment := range acceptedAssignmentList.AcceptedAssignments {
9496
clonePath := filepath.Join(fullPath, acceptAssignment.Repository.Name)
95-
_, err := CloneRepository(clonePath, acceptAssignment.Repository.FullName, gh)
97+
err := utils.CloneRepository(clonePath, acceptAssignment.Repository.FullName, gh.Exec)
9698
if err != nil {
9799
errMsg := fmt.Sprintf("Error cloning %s: %v", acceptAssignment.Repository.FullName, err)
98100
fmt.Println(errMsg)

cmd/gh-classroom/clone/utils/clone-repository.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@ import (
88
"bytes"
99
)
1010

11-
// GitHubExec defines an interface for executing GitHub CLI commands.
1211
// This abstraction allows for easier testing and decoupling from the actual CLI.
1312
// Exec invokes a gh command in a subprocess and captures the output and error streams.
14-
type GitHubExec interface {
15-
Exec(args ...string) (stdout, stderr bytes.Buffer, err error)
16-
}
13+
type GitHubExec func(args ...string) (stdout, stderr bytes.Buffer, err error)
1714

1815
// CloneRepository attempts to clone a repository into the specified path.
1916
// It returns an error if the cloning process fails.
20-
func CloneRepository(clonePath string, repoFullName string, gh GitHubExec) error {
17+
func CloneRepository(clonePath string, repoFullName string, ghExec GitHubExec) error {
2118
if _, err := os.Stat(clonePath); os.IsNotExist(err) {
2219
fmt.Printf("Cloning into: %v\n", clonePath)
23-
_, _, err := gh.Exec("repo", "clone", repoFullName, "--", clonePath)
20+
_, _, err := ghExec("repo", "clone", repoFullName, "--", clonePath)
2421
if err != nil {
2522
fmt.Printf("error cloning %s: %v\n", repoFullName, err)
2623
return fmt.Errorf("error cloning %s: %v", repoFullName, err)

cmd/gh-classroom/clone/utils/clone-repository_test.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ import (
1010
"path/filepath"
1111
)
1212

13-
// MockGitHubExec is a mock of the GitHubExec interface for testing.
14-
type MockGitHubExec struct {
15-
ExecFunc func(args ...string) (stdout, stderr bytes.Buffer, err error)
16-
}
17-
18-
func (m *MockGitHubExec) Exec(args ...string) (stdout, stderr bytes.Buffer, err error) {
19-
return m.ExecFunc(args...)
20-
}
21-
22-
2313
func TestCloneRepository(t *testing.T) {
2414
tmpDir, err := ioutil.TempDir("", "cloneTest")
2515
if err != nil {
@@ -29,32 +19,28 @@ func TestCloneRepository(t *testing.T) {
2919
// Test cases
3020
tests := []struct {
3121
name string
32-
execMock *MockGitHubExec
22+
execMock GitHubExec
3323
clonePath string
3424
repoFullName string
3525
wantErr bool
3626
errMsg string
3727
}{
3828
{
3929
name: "successful clone",
40-
execMock: &MockGitHubExec{
41-
ExecFunc: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
30+
execMock: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
4231
var stdoutBuf, stderrBuf bytes.Buffer
4332
stdoutBuf.Write([]byte("your string here"))
4433
return stdoutBuf, stderrBuf, nil
45-
},
4634
},
4735
clonePath: "", // Will be set to a temp directory in the test
4836
repoFullName: "example/repo",
4937
wantErr: false,
5038
},
5139
{
5240
name: "clone failure",
53-
execMock: &MockGitHubExec{
54-
ExecFunc: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
41+
execMock: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
5542
var stdoutBuf, stderrBuf bytes.Buffer
5643
return stdoutBuf, stderrBuf, errors.New("clone error")
57-
},
5844
},
5945
clonePath: filepath.Join(tmpDir, "repo"),
6046
repoFullName: "example/repo",
@@ -63,11 +49,9 @@ func TestCloneRepository(t *testing.T) {
6349
},
6450
{
6551
name: "repository already exists",
66-
execMock: &MockGitHubExec{
67-
ExecFunc: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
52+
execMock: func(args ...string) (stdout bytes.Buffer, stderr bytes.Buffer, err error) {
6853
var stdoutBuf, stderrBuf bytes.Buffer
6954
return stdoutBuf, stderrBuf, nil
70-
},
7155
},
7256
clonePath: "./repo", // Current directory always exists
7357
repoFullName: "example/repo",

cmd/gh-classroom/pull/student-repos/student-repos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func NewCmdStudentReposPull(f *cmdutil.Factory) *cobra.Command {
8080
if !r.IsDir() {
8181
continue
8282
}
83-
clonePath := filepath.Join(fullPath, r.Name)
83+
clonePath := filepath.Join(fullPath, r.Name())
8484
fmt.Printf("Pulling repo: %v\n", clonePath)
8585
err = os.Chdir(clonePath)
8686
if err != nil {

pkg/classroom/classroom.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type Classroom struct {
5656

5757
type GithubRepository struct {
5858
Id int `json:"id"`
59-
Name string `json:name`
59+
Name string `json:"name"`
6060
FullName string `json:"full_name"`
6161
HtmlUrl string `json:"html_url"`
6262
NodeId string `json:"node_id"`

0 commit comments

Comments
 (0)