Skip to content

Commit 03a2756

Browse files
authored
Add function to diff github and gitea repos (#4)
1 parent d9674ea commit 03a2756

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

gitea_github_sync/migration.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List
2+
3+
from gitea_github_sync.repository import Repository
4+
5+
6+
def list_missing_github_repos(
7+
gh_repos: List[Repository], gitea_repos: List[Repository]
8+
) -> List[Repository]:
9+
gitea_repos_by_name = [repo.get_repo_name() for repo in gitea_repos]
10+
return [repo for repo in gh_repos if repo.get_repo_name() not in gitea_repos_by_name]

tests/test_migration.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from typing import List
2+
3+
import pytest
4+
5+
from gitea_github_sync.migration import list_missing_github_repos
6+
from gitea_github_sync.repository import Repository, Visibility
7+
8+
9+
def r(org_name: str, repo_name: str) -> Repository:
10+
return Repository(full_repo_name=f"{org_name}/{repo_name}", visibility=Visibility.PUBLIC)
11+
12+
13+
def team_a_repo(repo_name: str) -> Repository:
14+
return r(org_name="team-a", repo_name=repo_name)
15+
16+
17+
def team_b_repo(repo_name: str) -> Repository:
18+
return r(org_name="team-b", repo_name=repo_name)
19+
20+
21+
@pytest.mark.parametrize(
22+
"gh_repos, gt_repos, expected_diff",
23+
[
24+
pytest.param(
25+
[team_a_repo("a-repo"), team_a_repo("b-repo")],
26+
[team_b_repo("a-repo"), team_b_repo("b-repo")],
27+
[],
28+
id="equal",
29+
),
30+
pytest.param(
31+
[team_a_repo("a-repo"), team_a_repo("b-repo")],
32+
[team_b_repo("a-repo")],
33+
[team_a_repo("b-repo")],
34+
id="missing-repo-on-gitea",
35+
),
36+
pytest.param(
37+
[team_a_repo("a-repo"), team_a_repo("b-repo")],
38+
[team_b_repo("a-repo"), team_b_repo("b-repo"), team_b_repo("c-repo")],
39+
[],
40+
id="too-many-repos-on-gitea",
41+
),
42+
],
43+
)
44+
def test_list_missing_github_repos(
45+
gh_repos: List[Repository], gt_repos: List[Repository], expected_diff: List[Repository]
46+
) -> None:
47+
result = list_missing_github_repos(gh_repos=gh_repos, gitea_repos=gt_repos)
48+
49+
assert result == expected_diff

0 commit comments

Comments
 (0)