gh-classroom icon indicating copy to clipboard operation
gh-classroom copied to clipboard

gh classroom clone student-repos crashing with "panic: runtime error: index out of range [1] with length 1"

Open sinkovitsd opened this issue 1 year ago • 2 comments

I'm new to GitHub classroom CLI. It worked flawlessly for the first two assignments, but the third and fourth assignments crash when I try to clone them using gh classroom clone student-repos. (The fifth worked fine, oddly.) It doesn't matter if I choose from the menu or explicitly access the assignment by its id. using -a.

What happens is that it clones some number of them but then crashes with a peculiar error: panic: runtime error: index out of range [1] with length 1

It always crashes in the same place for a particular assignment, but one assignment clones 19 before crashing and the other only clones 4.

image

sinkovitsd avatar Mar 13 '24 21:03 sinkovitsd

Update: The line that throws the error is this (in pkg/classroom/classroom/go): return strings.Split(gr.FullName, "/")[1]

Inserting a Printf, I find that the error is thrown when gr.FullName is empty.

I'm not sure why this is, but it seems like it may have to do with students who have accepted the assignment but have not pushed it.

Anyway, I was able to insert an if statement into student-repos.go to simply ignore this repository if the name is missing or malformed. The following would be the new lines 93 to 107 of student-repos.go. Perhaps later I'll figure out how to contribute this.

				if len(strings.Split(acceptAssignment.Repository.FullName, "/")) > 1 {
					clonePath := filepath.Join(fullPath, acceptAssignment.Repository.Name())
					if _, err := os.Stat(clonePath); os.IsNotExist(err) {
						fmt.Printf("Cloning into: %v\n", clonePath)
						_, _, err := gh.Exec("repo", "clone", acceptAssignment.Repository.FullName, "--", clonePath)
						totalCloned++
						if err != nil {
							log.Fatal(err)
							return
						}
					} else {
						fmt.Printf("Skip existing repo: %v use gh classroom pull to get new commits\n", clonePath)
					}
				}
			}

sinkovitsd avatar Mar 14 '24 17:03 sinkovitsd

I made my contribution a few months back (#59) and may be able to help you move yours along.

  • [x] get Go tools on your machine
  • [ ] fork this repo on your machine
  • [ ] make your changes
  • [ ] create a commit and sync your changes
  • [ ] create a pull request referencing this issue (with fixes #69 in the title or description)

Looks like you have Go all set on your end. So your first item is done.

Did you make a fork of this repo when you made your changes or simply a clone? If it was a clone, you cannot sync your changes back. Just make a fork of the repo, apply your changes in the forked repo then commit, sync and PR (pull request) from there.

If you don't know how to make a PR, the easiest way is on the GitHub website after you've synced your commit. There will be a big, inviting banner with a big, unavoidable button 😃 .

Once you've made the PR, the maintainers of this extension are pretty friendly about guiding you along the process.

physcrowley avatar May 06 '24 00:05 physcrowley