githarbor 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- githarbor/__init__.py +27 -0
- githarbor/core/__init__.py +0 -0
- githarbor/core/base.py +125 -0
- githarbor/core/models.py +210 -0
- githarbor/exceptions.py +29 -0
- githarbor/providers/__init__.py +18 -0
- githarbor/providers/githubrepository.py +344 -0
- githarbor/providers/gitlabrepository.py +344 -0
- githarbor/providers/testrepository.py +119 -0
- githarbor/py.typed +0 -0
- githarbor/registry.py +73 -0
- githarbor/repositories.py +50 -0
- githarbor/repository.py +73 -0
- githarbor-0.0.1.dist-info/METADATA +86 -0
- githarbor-0.0.1.dist-info/RECORD +17 -0
- githarbor-0.0.1.dist-info/WHEEL +4 -0
- githarbor-0.0.1.dist-info/licenses/LICENSE +22 -0
githarbor/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from githarbor.core.base import Repository
|
|
2
|
+
from githarbor.core.models import (
|
|
3
|
+
Branch,
|
|
4
|
+
Commit,
|
|
5
|
+
Issue,
|
|
6
|
+
Label,
|
|
7
|
+
PullRequest,
|
|
8
|
+
User,
|
|
9
|
+
Workflow,
|
|
10
|
+
WorkflowRun,
|
|
11
|
+
)
|
|
12
|
+
from githarbor.repositories import create_repository
|
|
13
|
+
|
|
14
|
+
__version__ = "0.0.1"
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"Repository",
|
|
18
|
+
"Branch",
|
|
19
|
+
"Commit",
|
|
20
|
+
"Issue",
|
|
21
|
+
"Label",
|
|
22
|
+
"PullRequest",
|
|
23
|
+
"User",
|
|
24
|
+
"Workflow",
|
|
25
|
+
"WorkflowRun",
|
|
26
|
+
"create_repository",
|
|
27
|
+
]
|
|
File without changes
|
githarbor/core/base.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import TYPE_CHECKING, Any, ClassVar
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
from githarbor.core.models import (
|
|
12
|
+
Branch,
|
|
13
|
+
Commit,
|
|
14
|
+
Issue,
|
|
15
|
+
PullRequest,
|
|
16
|
+
Workflow,
|
|
17
|
+
WorkflowRun,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Repository(ABC):
|
|
22
|
+
"""Base class representing a specific Git repository."""
|
|
23
|
+
|
|
24
|
+
_name: str
|
|
25
|
+
_owner: str
|
|
26
|
+
url_patterns: ClassVar[list[str]] = []
|
|
27
|
+
|
|
28
|
+
def __repr__(self):
|
|
29
|
+
return f"{type(self).__name__}(name={self._name}, owner={self._owner})"
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def supports_url(cls, url: str) -> bool:
|
|
33
|
+
"""Check if this provider can handle the given URL."""
|
|
34
|
+
return any(pattern in url for pattern in cls.url_patterns)
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def from_url(cls, url: str, **kwargs: Any) -> Repository:
|
|
39
|
+
"""Create a repository instance from a URL."""
|
|
40
|
+
raise NotImplementedError
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
@abstractmethod
|
|
44
|
+
def name(self) -> str:
|
|
45
|
+
"""Repository name."""
|
|
46
|
+
raise NotImplementedError
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
@abstractmethod
|
|
50
|
+
def default_branch(self) -> str:
|
|
51
|
+
"""Default branch name."""
|
|
52
|
+
raise NotImplementedError
|
|
53
|
+
|
|
54
|
+
@abstractmethod
|
|
55
|
+
def get_branch(self, name: str) -> Branch:
|
|
56
|
+
"""Get a specific branch."""
|
|
57
|
+
raise NotImplementedError
|
|
58
|
+
|
|
59
|
+
@abstractmethod
|
|
60
|
+
def get_pull_request(self, number: int) -> PullRequest:
|
|
61
|
+
"""Get a specific pull request."""
|
|
62
|
+
raise NotImplementedError
|
|
63
|
+
|
|
64
|
+
@abstractmethod
|
|
65
|
+
def list_pull_requests(self, state: str = "open") -> list[PullRequest]:
|
|
66
|
+
"""List pull requests."""
|
|
67
|
+
raise NotImplementedError
|
|
68
|
+
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def get_issue(self, issue_id: int) -> Issue:
|
|
71
|
+
"""Get a specific issue."""
|
|
72
|
+
raise NotImplementedError
|
|
73
|
+
|
|
74
|
+
@abstractmethod
|
|
75
|
+
def list_issues(self, state: str = "open") -> list[Issue]:
|
|
76
|
+
"""List issues."""
|
|
77
|
+
raise NotImplementedError
|
|
78
|
+
|
|
79
|
+
@abstractmethod
|
|
80
|
+
def get_commit(self, sha: str) -> Commit:
|
|
81
|
+
"""Get a specific commit."""
|
|
82
|
+
raise NotImplementedError
|
|
83
|
+
|
|
84
|
+
@abstractmethod
|
|
85
|
+
def list_commits(
|
|
86
|
+
self,
|
|
87
|
+
branch: str | None = None,
|
|
88
|
+
since: datetime | None = None,
|
|
89
|
+
until: datetime | None = None,
|
|
90
|
+
author: str | None = None,
|
|
91
|
+
path: str | None = None,
|
|
92
|
+
max_results: int | None = None,
|
|
93
|
+
) -> list[Commit]:
|
|
94
|
+
"""List commits."""
|
|
95
|
+
raise NotImplementedError
|
|
96
|
+
|
|
97
|
+
@abstractmethod
|
|
98
|
+
def get_workflow(self, workflow_id: str) -> Workflow:
|
|
99
|
+
"""Get a specific workflow."""
|
|
100
|
+
raise NotImplementedError
|
|
101
|
+
|
|
102
|
+
@abstractmethod
|
|
103
|
+
def list_workflows(self) -> list[Workflow]:
|
|
104
|
+
"""List workflows."""
|
|
105
|
+
raise NotImplementedError
|
|
106
|
+
|
|
107
|
+
@abstractmethod
|
|
108
|
+
def get_workflow_run(self, run_id: str) -> WorkflowRun:
|
|
109
|
+
"""Get a specific workflow run."""
|
|
110
|
+
raise NotImplementedError
|
|
111
|
+
|
|
112
|
+
def download(
|
|
113
|
+
self,
|
|
114
|
+
path: str | os.PathLike[str],
|
|
115
|
+
destination: str | os.PathLike[str],
|
|
116
|
+
recursive: bool = False,
|
|
117
|
+
):
|
|
118
|
+
"""Download a file or directory from this GitLab repository.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
path: Path to the file or directory we want to download.
|
|
122
|
+
destination: Path where file/directory should be saved.
|
|
123
|
+
recursive: Download all files from a folder (and subfolders).
|
|
124
|
+
"""
|
|
125
|
+
raise NotImplementedError
|
githarbor/core/models.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class User:
|
|
13
|
+
username: str
|
|
14
|
+
"""Username of the user."""
|
|
15
|
+
name: str | None = None
|
|
16
|
+
"""Full name of the user."""
|
|
17
|
+
email: str | None = None
|
|
18
|
+
"""Email address of the user."""
|
|
19
|
+
avatar_url: str | None = None
|
|
20
|
+
"""URL of the user's avatar image."""
|
|
21
|
+
created_at: datetime | None = None
|
|
22
|
+
"""Date and time when the user account was created."""
|
|
23
|
+
bio: str | None = None
|
|
24
|
+
"""Biography/description of the user."""
|
|
25
|
+
location: str | None = None
|
|
26
|
+
"""Geographic location of the user."""
|
|
27
|
+
company: str | None = None
|
|
28
|
+
"""Company/organization the user belongs to."""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class Label:
|
|
33
|
+
name: str
|
|
34
|
+
"""Name of the label."""
|
|
35
|
+
color: str = "" # Hex color code
|
|
36
|
+
"""Hex color code for the label."""
|
|
37
|
+
description: str = ""
|
|
38
|
+
"""Description of what the label represents."""
|
|
39
|
+
created_at: datetime | None = None
|
|
40
|
+
"""Date and time when the label was created."""
|
|
41
|
+
updated_at: datetime | None = None
|
|
42
|
+
"""Date and time when the label was last updated."""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class Comment:
|
|
47
|
+
id: str
|
|
48
|
+
"""Unique identifier for the comment."""
|
|
49
|
+
body: str
|
|
50
|
+
"""Content of the comment."""
|
|
51
|
+
author: User
|
|
52
|
+
"""User who wrote the comment."""
|
|
53
|
+
created_at: datetime
|
|
54
|
+
"""Date and time when the comment was created."""
|
|
55
|
+
updated_at: datetime | None = None
|
|
56
|
+
"""Date and time when the comment was last updated."""
|
|
57
|
+
reactions: dict[str, int] = field(default_factory=dict)
|
|
58
|
+
"""Dictionary of reaction types and their counts."""
|
|
59
|
+
reply_to: str | None = None # ID of parent comment if this is a reply
|
|
60
|
+
"""ID of parent comment if this is a reply."""
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass
|
|
64
|
+
class Branch:
|
|
65
|
+
name: str
|
|
66
|
+
"""Name of the branch."""
|
|
67
|
+
sha: str
|
|
68
|
+
"""SHA hash of the latest commit on this branch."""
|
|
69
|
+
protected: bool = False
|
|
70
|
+
"""Whether the branch has protection rules enabled."""
|
|
71
|
+
default: bool = False
|
|
72
|
+
"""Whether this is the default branch of the repository."""
|
|
73
|
+
created_at: datetime | None = None
|
|
74
|
+
"""Date and time when the branch was created."""
|
|
75
|
+
updated_at: datetime | None = None
|
|
76
|
+
"""Date and time when the branch was last updated."""
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@dataclass
|
|
80
|
+
class PullRequest:
|
|
81
|
+
title: str
|
|
82
|
+
"""Title of the pull request."""
|
|
83
|
+
source_branch: str
|
|
84
|
+
"""Branch containing the changes to merge."""
|
|
85
|
+
target_branch: str
|
|
86
|
+
"""Branch to merge the changes into."""
|
|
87
|
+
description: str = ""
|
|
88
|
+
"""Description of the changes in the pull request."""
|
|
89
|
+
state: str = "open"
|
|
90
|
+
"""Current state of the pull request."""
|
|
91
|
+
number: int | None = None
|
|
92
|
+
"""Unique identifier for the pull request."""
|
|
93
|
+
created_at: datetime | None = None
|
|
94
|
+
"""Date and time when the pull request was created."""
|
|
95
|
+
updated_at: datetime | None = None
|
|
96
|
+
"""Date and time when the pull request was last updated."""
|
|
97
|
+
merged_at: datetime | None = None
|
|
98
|
+
"""Date and time when the pull request was merged."""
|
|
99
|
+
closed_at: datetime | None = None
|
|
100
|
+
"""Date and time when the pull request was closed."""
|
|
101
|
+
author: User | None = None
|
|
102
|
+
"""User who created the pull request."""
|
|
103
|
+
assignees: list[User] = field(default_factory=list)
|
|
104
|
+
"""List of users assigned to review the pull request."""
|
|
105
|
+
labels: list[Label] = field(default_factory=list)
|
|
106
|
+
"""List of labels attached to the pull request."""
|
|
107
|
+
comments: list[Comment] = field(default_factory=list)
|
|
108
|
+
"""List of comments on the pull request."""
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@dataclass
|
|
112
|
+
class Issue:
|
|
113
|
+
number: int
|
|
114
|
+
"""Unique identifier for the issue."""
|
|
115
|
+
title: str
|
|
116
|
+
"""Title of the issue."""
|
|
117
|
+
description: str = ""
|
|
118
|
+
"""Description of the issue."""
|
|
119
|
+
state: str = "open"
|
|
120
|
+
"""State of the issue."""
|
|
121
|
+
author: User | None = None
|
|
122
|
+
"""User who created the issue."""
|
|
123
|
+
assignee: User | None = None
|
|
124
|
+
"""User who is assigned to the issue."""
|
|
125
|
+
labels: list[Label] = field(default_factory=list)
|
|
126
|
+
"""List of labels attached to the issue."""
|
|
127
|
+
created_at: datetime | None = None
|
|
128
|
+
"""Date and time when the issue was created."""
|
|
129
|
+
updated_at: datetime | None = None
|
|
130
|
+
"""Date and time when the issue was last updated."""
|
|
131
|
+
closed_at: datetime | None = None
|
|
132
|
+
"""Date and time when the issue was closed."""
|
|
133
|
+
closed: bool = False
|
|
134
|
+
"""Indicates if the issue is closed."""
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@dataclass
|
|
138
|
+
class Commit:
|
|
139
|
+
sha: str
|
|
140
|
+
"""Unique identifier for the commit."""
|
|
141
|
+
message: str
|
|
142
|
+
"""Commit message."""
|
|
143
|
+
author: User
|
|
144
|
+
"""User who authored the commit."""
|
|
145
|
+
created_at: datetime
|
|
146
|
+
"""Date and time when the commit was authored."""
|
|
147
|
+
committer: User | None = None
|
|
148
|
+
"""User who committed the changes."""
|
|
149
|
+
url: str | None = None
|
|
150
|
+
"""URL to the commit details."""
|
|
151
|
+
stats: dict[str, int] = field(default_factory=dict)
|
|
152
|
+
"""Commit statistics."""
|
|
153
|
+
parents: list[str] = field(default_factory=list)
|
|
154
|
+
"""List of parent commit SHAs."""
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@dataclass
|
|
158
|
+
class Workflow:
|
|
159
|
+
id: str
|
|
160
|
+
"""Unique identifier for the workflow."""
|
|
161
|
+
name: str
|
|
162
|
+
"""Name of the workflow."""
|
|
163
|
+
path: str
|
|
164
|
+
"""Path to the workflow file in the repository."""
|
|
165
|
+
state: str
|
|
166
|
+
"""State of the workflow."""
|
|
167
|
+
created_at: datetime
|
|
168
|
+
"""Date and time when the workflow was created."""
|
|
169
|
+
updated_at: datetime | None = None
|
|
170
|
+
"""Date and time when the workflow was last updated."""
|
|
171
|
+
description: str = ""
|
|
172
|
+
"""Description of the workflow."""
|
|
173
|
+
triggers: list[str] = field(default_factory=list)
|
|
174
|
+
"""List of triggers that can start the workflow."""
|
|
175
|
+
disabled: bool = False
|
|
176
|
+
"""Indicates if the workflow is disabled."""
|
|
177
|
+
last_run_at: datetime | None = None
|
|
178
|
+
"""Date and time when the workflow was last run."""
|
|
179
|
+
badge_url: str | None = None
|
|
180
|
+
"""URL to the badge image for the workflow."""
|
|
181
|
+
definition: str | None = None
|
|
182
|
+
"""Content of the workflow definition file."""
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@dataclass
|
|
186
|
+
class WorkflowRun:
|
|
187
|
+
id: str
|
|
188
|
+
"""Unique identifier for the workflow run."""
|
|
189
|
+
name: str
|
|
190
|
+
"""Name of the workflow run."""
|
|
191
|
+
workflow_id: str
|
|
192
|
+
"""ID of the parent workflow."""
|
|
193
|
+
status: str
|
|
194
|
+
"""Current status of the workflow run."""
|
|
195
|
+
conclusion: str | None
|
|
196
|
+
"""Final conclusion of the workflow run."""
|
|
197
|
+
branch: str | None = None
|
|
198
|
+
"""Branch the workflow was run on."""
|
|
199
|
+
commit_sha: str | None = None
|
|
200
|
+
"""SHA of the commit that triggered the workflow."""
|
|
201
|
+
url: str | None = None
|
|
202
|
+
"""URL to view the workflow run."""
|
|
203
|
+
created_at: datetime | None = None
|
|
204
|
+
"""Date and time when the workflow run was created."""
|
|
205
|
+
updated_at: datetime | None = None
|
|
206
|
+
"""Date and time when the workflow run was last updated."""
|
|
207
|
+
started_at: datetime | None = None
|
|
208
|
+
"""Date and time when the workflow run started."""
|
|
209
|
+
completed_at: datetime | None = None
|
|
210
|
+
"""Date and time when the workflow run completed."""
|
githarbor/exceptions.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class GitHarborError(Exception):
|
|
5
|
+
"""Base exception for GitHarbor."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RepositoryNotFoundError(GitHarborError):
|
|
9
|
+
"""Raised when a repository cannot be found."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AuthenticationError(GitHarborError):
|
|
13
|
+
"""Raised when authentication fails."""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ResourceNotFoundError(GitHarborError):
|
|
17
|
+
"""Raised when a requested resource is not found."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class OperationNotAllowedError(GitHarborError):
|
|
21
|
+
"""Raised when an operation is not allowed."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ProviderNotConfiguredError(GitHarborError):
|
|
25
|
+
"""Raised when provider is not properly configured (missing token etc)."""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class RateLimitError(GitHarborError):
|
|
29
|
+
"""Raised when API rate limit is exceeded."""
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from githarbor.providers.testrepository import DummyRepository
|
|
4
|
+
import importlib.util
|
|
5
|
+
|
|
6
|
+
if importlib.util.find_spec("github"):
|
|
7
|
+
from githarbor.providers.githubrepository import GitHubRepository
|
|
8
|
+
if importlib.util.find_spec("gitlab"):
|
|
9
|
+
from githarbor.providers.gitlabrepository import GitLabRepository
|
|
10
|
+
# if importlib.util.find_spec("atlassian"):
|
|
11
|
+
# from githarbor.providers.bitbucketrepository import BitbucketRepository
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"GitHubRepository",
|
|
15
|
+
"GitLabRepository",
|
|
16
|
+
# "BitbucketRepository",
|
|
17
|
+
"DummyRepository",
|
|
18
|
+
]
|