Skip to content

Commit 61a1be8

Browse files
committed
Store repos with lowercase org and name
Avoid duplicates by storing all repos with a lowercase org and repo name. This is not enforced by the current database schema, so changes to this functionality could still result in duplicates in the future. A better long term solution is required. Signed-off-by: hasheddan <[email protected]>
1 parent c5372f6 commit 61a1be8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cmd/gitter/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"os"
2929
"path"
3030
"regexp"
31+
"strings"
3132
"time"
3233

3334
"github.com/crdsdev/doc/pkg/crd"
@@ -93,8 +94,9 @@ func (g *Gitter) Index(gRepo models.GitterRepo, reply *string) error {
9394
return err
9495
}
9596
defer os.RemoveAll(dir)
97+
fullRepo := fmt.Sprintf("%s/%s/%s", "github.com", strings.ToLower(gRepo.Org), strings.ToLower(gRepo.Repo))
9698
cloneOpts := &git.CloneOptions{
97-
URL: fmt.Sprintf("https://github.com/%s/%s", gRepo.Org, gRepo.Repo),
99+
URL: fmt.Sprintf("https://%s", fullRepo),
98100
Depth: 1,
99101
Progress: os.Stdout,
100102
RecurseSubmodules: git.NoRecurseSubmodules,
@@ -147,13 +149,13 @@ func (g *Gitter) Index(gRepo models.GitterRepo, reply *string) error {
147149
log.Printf("Unable to resolve revision: %s (%v)", t.hash.String(), err)
148150
continue
149151
}
150-
r := g.conn.QueryRow(context.Background(), "SELECT id FROM tags WHERE name=$1 AND repo=$2", t.name, "github.com/"+gRepo.Org+"/"+gRepo.Repo)
152+
r := g.conn.QueryRow(context.Background(), "SELECT id FROM tags WHERE name=$1 AND repo=$2", t.name, fullRepo)
151153
var tagID int
152154
if err := r.Scan(&tagID); err != nil {
153155
if !errors.Is(err, pgx.ErrNoRows) {
154156
return err
155157
}
156-
r := g.conn.QueryRow(context.Background(), "INSERT INTO tags(name, repo, time) VALUES ($1, $2, $3) RETURNING id", t.name, "github.com/"+gRepo.Org+"/"+gRepo.Repo, c.Committer.When)
158+
r := g.conn.QueryRow(context.Background(), "INSERT INTO tags(name, repo, time) VALUES ($1, $2, $3) RETURNING id", t.name, fullRepo, c.Committer.When)
157159
if err := r.Scan(&tagID); err != nil {
158160
return err
159161
}

0 commit comments

Comments
 (0)