"context"
"fmt"
"os"
+ "path"
"path/filepath"
"strings"
return util.RemoveAll(repoPath)
}
-type unadoptedRrepositories struct {
+type unadoptedRepositories struct {
repositories []string
index int
start int
end int
}
-func (unadopted *unadoptedRrepositories) add(repository string) {
+func (unadopted *unadoptedRepositories) add(repository string) {
if unadopted.index >= unadopted.start && unadopted.index < unadopted.end {
unadopted.repositories = append(unadopted.repositories, repository)
}
unadopted.index++
}
-func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unadopted *unadoptedRrepositories) error {
+func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unadopted *unadoptedRepositories) error {
if len(repoNamesToCheck) == 0 {
return nil
}
}
for _, repoName := range repoNamesToCheck {
if _, ok := repoNames[repoName]; !ok {
- unadopted.add(filepath.Join(userName, repoName))
+ unadopted.add(path.Join(userName, repoName)) // These are not used as filepaths - but as reponames - therefore use path.Join not filepath.Join
}
}
return nil
var repoNamesToCheck []string
start := (opts.Page - 1) * opts.PageSize
- unadopted := &unadoptedRrepositories{
+ unadopted := &unadoptedRepositories{
repositories: make([]string, 0, opts.PageSize),
start: start,
end: start + opts.PageSize,
func TestCheckUnadoptedRepositories_Add(t *testing.T) {
start := 10
end := 20
- unadopted := &unadoptedRrepositories{
+ unadopted := &unadoptedRepositories{
start: start,
end: end,
index: 0,
//
// Non existent user
//
- unadopted := &unadoptedRrepositories{start: 0, end: 100}
+ unadopted := &unadoptedRepositories{start: 0, end: 100}
err := checkUnadoptedRepositories("notauser", []string{"repo"}, unadopted)
assert.NoError(t, err)
assert.Equal(t, 0, len(unadopted.repositories))
userName := "user2"
repoName := "repo2"
unadoptedRepoName := "unadopted"
- unadopted = &unadoptedRrepositories{start: 0, end: 100}
+ unadopted = &unadoptedRepositories{start: 0, end: 100}
err = checkUnadoptedRepositories(userName, []string{repoName, unadoptedRepoName}, unadopted)
assert.NoError(t, err)
assert.Equal(t, []string{path.Join(userName, unadoptedRepoName)}, unadopted.repositories)
//
// Existing (adopted) repository is not returned
//
- unadopted = &unadoptedRrepositories{start: 0, end: 100}
+ unadopted = &unadoptedRepositories{start: 0, end: 100}
err = checkUnadoptedRepositories(userName, []string{repoName}, unadopted)
assert.NoError(t, err)
assert.Equal(t, 0, len(unadopted.repositories))