Skip to content

Commit 307ea61

Browse files
committed
feat: Add Github URL property on repositories
1 parent 0adeda0 commit 307ea61

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

cli/import.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func Import(_force bool, _debug bool, repoKey string) int {
7272
Description: *repository.Description,
7373
CreatedAt: *repository.CreatedAt.GetTime(),
7474
UpdatedAt: *repository.PushedAt.GetTime(),
75+
GithubURL: *repository.HTMLURL,
7576
})
7677
if err != nil {
7778
log.Println("Error upserting repository:", err)

cli/update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func Update(_force bool, _debug bool, repoKey string) int {
4646
Description: *githubRepository.Description,
4747
CreatedAt: *githubRepository.CreatedAt.GetTime(),
4848
UpdatedAt: *githubRepository.PushedAt.GetTime(),
49+
GithubURL: *githubRepository.HTMLURL,
4950
})
5051
if err != nil {
5152
log.Println("Error upserting repository:", err)

db/migrations/20251005184928_repositories.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CREATE TABLE repositories (
55
description TEXT,
66
created_at TIMESTAMP NOT NULL,
77
updated_at TIMESTAMP NOT NULL,
8+
github_url TEXT NOT NULL UNIQUE CHECK (github_url LIKE 'https?://github.com/%/%'),
89

910
UNIQUE(owner, name)
1011
);

internal/store/repository.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Repository struct {
1515
Description string `db:"description"`
1616
CreatedAt time.Time `db:"created_at"`
1717
UpdatedAt time.Time `db:"updated_at"`
18+
GithubURL string `db:"github_url"`
1819
}
1920

2021
type RepositoryStore struct {
@@ -35,7 +36,7 @@ func (store *RepositoryStore) GetByKey(ctx context.Context, key string) (*Reposi
3536

3637
var r Repository
3738
err := store.database.QueryRowContext(ctx, `
38-
SELECT id, owner, name, description, created_at, updated_at
39+
SELECT id, owner, name, description, created_at, updated_at, github_url
3940
FROM repositories
4041
WHERE owner = ? AND name = ?
4142
`, owner, name).Scan(
@@ -45,6 +46,7 @@ func (store *RepositoryStore) GetByKey(ctx context.Context, key string) (*Reposi
4546
&r.Description,
4647
&r.CreatedAt,
4748
&r.UpdatedAt,
49+
&r.GithubURL,
4850
)
4951

5052
if err != nil {
@@ -59,27 +61,29 @@ func (store *RepositoryStore) GetByKey(ctx context.Context, key string) (*Reposi
5961

6062
func (store *RepositoryStore) Upsert(ctx context.Context, r Repository) error {
6163
_, err := store.database.ExecContext(ctx, `
62-
INSERT INTO repositories (id, owner, name, description, created_at, updated_at)
63-
VALUES (?, ?, ?, ?, ?, ?)
64+
INSERT INTO repositories (id, owner, name, description, created_at, updated_at, github_url)
65+
VALUES (?, ?, ?, ?, ?, ?, ?)
6466
ON CONFLICT(id) DO UPDATE SET
6567
owner = excluded.owner,
6668
name = excluded.name,
6769
description = excluded.description,
68-
updated_at = excluded.updated_at;
70+
updated_at = excluded.updated_at,
71+
github_url = excluded.github_url;
6972
`,
7073
r.ID,
7174
r.Owner,
7275
r.Name,
7376
r.Description,
7477
r.CreatedAt,
7578
r.UpdatedAt,
79+
r.GithubURL,
7680
)
7781
return err
7882
}
7983

8084
func (store *RepositoryStore) GetAll() []Repository {
8185
rows, err := store.database.Query(`
82-
SELECT id, owner, name, description, created_at, updated_at
86+
SELECT id, owner, name, description, created_at, updated_at, github_url
8387
FROM repositories
8488
`)
8589
if err != nil {
@@ -97,6 +101,7 @@ func (store *RepositoryStore) GetAll() []Repository {
97101
&r.Description,
98102
&r.CreatedAt,
99103
&r.UpdatedAt,
104+
&r.GithubURL,
100105
); err != nil {
101106
panic(err)
102107
}

0 commit comments

Comments
 (0)