Skip to content

Commit 6a7a919

Browse files
committed
add graceful failures and remove Name() function
1 parent 3347006 commit 6a7a919

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/github/gh-classroom/cmd/gh-classroom/shared"
1414
"github.com/github/gh-classroom/pkg/classroom"
1515
"github.com/spf13/cobra"
16+
"github.com/github/gh-classroom/cmd/gh-classroom/clone/utils"
1617
)
1718

1819
func NewCmdStudentRepo(f *cmdutil.Factory) *cobra.Command {
@@ -90,17 +91,24 @@ func NewCmdStudentRepo(f *cmdutil.Factory) *cobra.Command {
9091

9192
totalCloned := 0
9293
for _, acceptAssignment := range acceptedAssignmentList.AcceptedAssignments {
93-
clonePath := filepath.Join(fullPath, acceptAssignment.Repository.Name())
94-
if _, err := os.Stat(clonePath); os.IsNotExist(err) {
95-
fmt.Printf("Cloning into: %v\n", clonePath)
96-
_, _, err := gh.Exec("repo", "clone", acceptAssignment.Repository.FullName, "--", clonePath)
97-
totalCloned++
98-
if err != nil {
99-
log.Fatal(err)
100-
return
101-
}
94+
clonePath := filepath.Join(fullPath, acceptAssignment.Repository.Name)
95+
_, err := CloneRepository(clonePath, acceptAssignment.Repository.FullName, gh)
96+
if err != nil {
97+
errMsg := fmt.Sprintf("Error cloning %s: %v", acceptAssignment.Repository.FullName, err)
98+
fmt.Println(errMsg)
99+
cloneErrors = append(cloneErrors, errMsg)
100+
continue // Continue with the next iteration
101+
}
102+
totalCloned++
103+
}
104+
if len(cloneErrors) > 0 {
105+
fmt.Println("Some repositories failed to clone.")
106+
if !verbose {
107+
fmt.Println("Run with --verbose flag to see more details")
102108
} else {
103-
fmt.Printf("Skip existing repo: %v use gh classroom pull to get new commits\n", clonePath)
109+
for _, errMsg := range cloneErrors {
110+
fmt.Println(errMsg)
111+
}
104112
}
105113
}
106114
if getAll {
@@ -117,6 +125,7 @@ func NewCmdStudentRepo(f *cmdutil.Factory) *cobra.Command {
117125
cmd.Flags().IntVar(&page, "page", 1, "Page number")
118126
cmd.Flags().IntVar(&perPage, "per-page", 15, "Number of accepted assignments per page")
119127
cmd.Flags().BoolVar(&getAll, "all", true, "Clone All assignments by default")
128+
cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose error output")
120129

121130
return cmd
122131
}

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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,3 @@ func (a Assignment) IsGroupAssignment() bool {
138138
func (a AcceptedAssignment) RepositoryUrl() string {
139139
return a.Repository.HtmlUrl
140140
}
141-
142-
func (gr GithubRepository) Name() string {
143-
return strings.Split(gr.FullName, "/")[1]
144-
}

pkg/classroom/classroom_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,4 @@ func TestAcceptedAssignments(t *testing.T) {
121121
acceptedAssignment := AcceptedAssignment{Repository: GithubRepository{HtmlUrl: "https://github.com/owner/repo"}}
122122
assert.Equal(t, acceptedAssignment.RepositoryUrl(), "https://github.com/owner/repo")
123123
})
124-
}
125-
126-
func TestGithubRepositories(t *testing.T) {
127-
t.Run("Returns repo name", func(t *testing.T) {
128-
repository := GithubRepository{FullName: "owner/repo"}
129-
assert.Equal(t, repository.Name(), "repo")
130-
})
131-
}
124+
}

0 commit comments

Comments
 (0)