Skip to content

Commit 4d3c73e

Browse files
authored
Adds list_repos and list_commits functions to data.py (#16)
1 parent 8f716ee commit 4d3c73e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

icds/data.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ def get_repo_by_name(db, name: str) -> DbRepo | None:
1010
return repo
1111

1212

13+
def list_repos(db, limit=None) -> list[DbRepo] | None:
14+
statement = select(DbRepo)
15+
if limit:
16+
statement = statement.limit(limit)
17+
repos = db.exec(statement).all()
18+
return repos
19+
20+
1321
def get_or_create_db_repo(db, repo, repo_path) -> DbRepo:
1422
remote_url = repo.remotes.origin.url
1523
repo_name = remote_url.split("/")[-1].split(".")[0]
@@ -30,6 +38,14 @@ def get_repo_name_by_id(db, repo_id) -> str:
3038
return db.exec(select(DbRepo).where(DbRepo.id == repo_id)).first().name
3139

3240

41+
def list_commits(db, repo_id, limit=None) -> list[RepoCommit] | None:
42+
statement = select(RepoCommit).where(RepoCommit.repo_id == repo_id)
43+
if limit:
44+
statement = statement.limit(limit)
45+
commits = db.exec(statement).all()
46+
return commits
47+
48+
3349
def search_commits(
3450
db, query, repo_name, file, author, start_date, end_date
3551
) -> list[RepoCommit]:

0 commit comments

Comments
 (0)