Skip to content

Commit 0b9d294

Browse files
committed
Apply some refactors
1 parent 9295a56 commit 0b9d294

File tree

3 files changed

+41
-39
lines changed

3 files changed

+41
-39
lines changed

gitea_github_sync/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import click
22
from rich import print
33

4-
from . import github
4+
from . import github, repository
55

66

77
@click.group()
@@ -21,10 +21,10 @@ def list_all_repositories(stats: bool) -> None:
2121
print()
2222
print("[b]Repository stats[/]")
2323
number_public_repos = sum(
24-
[1 if repo.visibility == github.Visibility.PUBLIC else 0 for repo in repos]
24+
1 if repo.visibility == repository.Visibility.PUBLIC else 0 for repo in repos
2525
)
2626
number_private_repos = sum(
27-
[1 if repo.visibility == github.Visibility.PRIVATE else 0 for repo in repos]
27+
1 if repo.visibility == repository.Visibility.PRIVATE else 0 for repo in repos
2828
)
2929
number_unknown_repos = len(repos) - number_public_repos - number_private_repos
3030
print(f"Number of public repos identified: [b red]{number_public_repos}[/]")

gitea_github_sync/github.py

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,11 @@
11
from __future__ import annotations
22

3-
from dataclasses import dataclass
4-
from enum import Flag, auto
53
from typing import List, Optional
64

75
from github import Github
86

97
from . import config
10-
11-
12-
class Visibility(Flag):
13-
PUBLIC = auto()
14-
PRIVATE = auto()
15-
UNKNOWN = auto()
16-
17-
@staticmethod
18-
def from_str(value: str) -> Visibility:
19-
if value == "public":
20-
return Visibility.PUBLIC
21-
elif value == "private":
22-
return Visibility.PRIVATE
23-
else:
24-
return Visibility.UNKNOWN
25-
26-
27-
@dataclass(frozen=True)
28-
class Repository:
29-
full_repo_name: str
30-
visibility: Visibility
31-
32-
def get_org_name(self) -> str:
33-
return self.full_repo_name.split("/")[0]
34-
35-
def get_repo_name(self) -> str:
36-
return self.full_repo_name.split("/")[1]
8+
from .repository import Repository, Visibility
379

3810

3911
def get_github(conf: Optional[config.Config] = None) -> Github:
@@ -44,11 +16,10 @@ def get_github(conf: Optional[config.Config] = None) -> Github:
4416

4517
def list_all_repositories(gh: Github) -> List[Repository]:
4618
repos = gh.get_user().get_repos()
47-
output = []
48-
for repo in repos:
49-
output.append(
50-
Repository(
51-
full_repo_name=repo.full_name, visibility=Visibility.from_str(repo.visibility)
52-
)
19+
return [
20+
Repository(
21+
full_repo_name=repo.full_name,
22+
visibility=Visibility.from_str(repo.visibility),
5323
)
54-
return output
24+
for repo in repos
25+
]

gitea_github_sync/repository.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from __future__ import annotations
2+
3+
from dataclasses import dataclass
4+
from enum import Flag, auto
5+
6+
7+
class Visibility(Flag):
8+
PUBLIC = auto()
9+
PRIVATE = auto()
10+
UNKNOWN = auto()
11+
12+
@staticmethod
13+
def from_str(value: str) -> Visibility:
14+
if value == "public":
15+
return Visibility.PUBLIC
16+
elif value == "private":
17+
return Visibility.PRIVATE
18+
else:
19+
return Visibility.UNKNOWN
20+
21+
22+
@dataclass(frozen=True)
23+
class Repository:
24+
full_repo_name: str
25+
visibility: Visibility
26+
27+
def get_org_name(self) -> str:
28+
return self.full_repo_name.split("/")[0]
29+
30+
def get_repo_name(self) -> str:
31+
return self.full_repo_name.split("/")[1]

0 commit comments

Comments
 (0)