mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 14:57:59 -05:00
feat(backend): Include owner_type in the Get Repositories API response. (#9763)
This commit is contained in:
@@ -9,6 +9,7 @@ from openhands.integrations.service_types import (
|
||||
BaseGitService,
|
||||
Branch,
|
||||
GitService,
|
||||
OwnerType,
|
||||
ProviderType,
|
||||
Repository,
|
||||
RequestMethod,
|
||||
@@ -246,6 +247,11 @@ class BitBucketService(BaseGitService, GitService):
|
||||
is_public=repo.get('is_private', True) is False,
|
||||
stargazers_count=None, # Bitbucket doesn't have stars
|
||||
pushed_at=repo.get('updated_on'),
|
||||
owner_type=(
|
||||
OwnerType.ORGANIZATION
|
||||
if repo.get('workspace', {}).get('is_private') is False
|
||||
else OwnerType.USER
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -287,6 +293,11 @@ class BitBucketService(BaseGitService, GitService):
|
||||
is_public=data.get('is_private', True) is False,
|
||||
stargazers_count=None, # Bitbucket doesn't have stars
|
||||
pushed_at=data.get('updated_on'),
|
||||
owner_type=(
|
||||
OwnerType.ORGANIZATION
|
||||
if data.get('workspace', {}).get('is_private') is False
|
||||
else OwnerType.USER
|
||||
),
|
||||
)
|
||||
|
||||
async def get_branches(self, repository: str) -> list[Branch]:
|
||||
|
||||
@@ -15,6 +15,7 @@ from openhands.integrations.service_types import (
|
||||
BaseGitService,
|
||||
Branch,
|
||||
GitService,
|
||||
OwnerType,
|
||||
ProviderType,
|
||||
Repository,
|
||||
RequestMethod,
|
||||
@@ -236,6 +237,11 @@ class GitHubService(BaseGitService, GitService):
|
||||
stargazers_count=repo.get('stargazers_count'),
|
||||
git_provider=ProviderType.GITHUB,
|
||||
is_public=not repo.get('private', True),
|
||||
owner_type=(
|
||||
OwnerType.ORGANIZATION
|
||||
if repo.get('owner', {}).get('type') == 'Organization'
|
||||
else OwnerType.USER
|
||||
),
|
||||
)
|
||||
for repo in all_repos
|
||||
]
|
||||
@@ -269,6 +275,11 @@ class GitHubService(BaseGitService, GitService):
|
||||
stargazers_count=repo.get('stargazers_count'),
|
||||
git_provider=ProviderType.GITHUB,
|
||||
is_public=True,
|
||||
owner_type=(
|
||||
OwnerType.ORGANIZATION
|
||||
if repo.get('owner', {}).get('type') == 'Organization'
|
||||
else OwnerType.USER
|
||||
),
|
||||
)
|
||||
for repo in repo_items
|
||||
]
|
||||
@@ -414,6 +425,11 @@ class GitHubService(BaseGitService, GitService):
|
||||
stargazers_count=repo.get('stargazers_count'),
|
||||
git_provider=ProviderType.GITHUB,
|
||||
is_public=not repo.get('private', True),
|
||||
owner_type=(
|
||||
OwnerType.ORGANIZATION
|
||||
if repo.get('owner', {}).get('type') == 'Organization'
|
||||
else OwnerType.USER
|
||||
),
|
||||
)
|
||||
|
||||
async def get_branches(self, repository: str) -> list[Branch]:
|
||||
|
||||
@@ -8,6 +8,7 @@ from openhands.integrations.service_types import (
|
||||
BaseGitService,
|
||||
Branch,
|
||||
GitService,
|
||||
OwnerType,
|
||||
ProviderType,
|
||||
Repository,
|
||||
RequestMethod,
|
||||
@@ -214,6 +215,11 @@ class GitLabService(BaseGitService, GitService):
|
||||
stargazers_count=repo.get('star_count'),
|
||||
git_provider=ProviderType.GITLAB,
|
||||
is_public=True,
|
||||
owner_type=(
|
||||
OwnerType.ORGANIZATION
|
||||
if repo.get('namespace', {}).get('kind') == 'group'
|
||||
else OwnerType.USER
|
||||
),
|
||||
)
|
||||
for repo in response
|
||||
]
|
||||
@@ -265,6 +271,11 @@ class GitLabService(BaseGitService, GitService):
|
||||
stargazers_count=repo.get('star_count'),
|
||||
git_provider=ProviderType.GITLAB,
|
||||
is_public=repo.get('visibility') == 'public',
|
||||
owner_type=(
|
||||
OwnerType.ORGANIZATION
|
||||
if repo.get('namespace', {}).get('kind') == 'group'
|
||||
else OwnerType.USER
|
||||
),
|
||||
)
|
||||
for repo in all_repos
|
||||
]
|
||||
@@ -415,6 +426,11 @@ class GitLabService(BaseGitService, GitService):
|
||||
stargazers_count=repo.get('star_count'),
|
||||
git_provider=ProviderType.GITLAB,
|
||||
is_public=repo.get('visibility') == 'public',
|
||||
owner_type=(
|
||||
OwnerType.ORGANIZATION
|
||||
if repo.get('namespace', {}).get('kind') == 'group'
|
||||
else OwnerType.USER
|
||||
),
|
||||
)
|
||||
|
||||
async def get_branches(self, repository: str) -> list[Branch]:
|
||||
|
||||
@@ -24,6 +24,11 @@ class TaskType(str, Enum):
|
||||
OPEN_PR = 'OPEN_PR'
|
||||
|
||||
|
||||
class OwnerType(str, Enum):
|
||||
USER = 'user'
|
||||
ORGANIZATION = 'organization'
|
||||
|
||||
|
||||
class SuggestedTask(BaseModel):
|
||||
git_provider: ProviderType
|
||||
task_type: TaskType
|
||||
@@ -32,17 +37,7 @@ class SuggestedTask(BaseModel):
|
||||
title: str
|
||||
|
||||
def get_provider_terms(self) -> dict:
|
||||
if self.git_provider == ProviderType.GITLAB:
|
||||
return {
|
||||
'requestType': 'Merge Request',
|
||||
'requestTypeShort': 'MR',
|
||||
'apiName': 'GitLab API',
|
||||
'tokenEnvVar': 'GITLAB_TOKEN',
|
||||
'ciSystem': 'CI pipelines',
|
||||
'ciProvider': 'GitLab',
|
||||
'requestVerb': 'merge request',
|
||||
}
|
||||
elif self.git_provider == ProviderType.GITHUB:
|
||||
if self.git_provider == ProviderType.GITHUB:
|
||||
return {
|
||||
'requestType': 'Pull Request',
|
||||
'requestTypeShort': 'PR',
|
||||
@@ -52,6 +47,16 @@ class SuggestedTask(BaseModel):
|
||||
'ciProvider': 'GitHub',
|
||||
'requestVerb': 'pull request',
|
||||
}
|
||||
elif self.git_provider == ProviderType.GITLAB:
|
||||
return {
|
||||
'requestType': 'Merge Request',
|
||||
'requestTypeShort': 'MR',
|
||||
'apiName': 'GitLab API',
|
||||
'tokenEnvVar': 'GITLAB_TOKEN',
|
||||
'ciSystem': 'CI pipelines',
|
||||
'ciProvider': 'GitLab',
|
||||
'requestVerb': 'merge request',
|
||||
}
|
||||
elif self.git_provider == ProviderType.BITBUCKET:
|
||||
return {
|
||||
'requestType': 'Pull Request',
|
||||
@@ -117,6 +122,9 @@ class Repository(BaseModel):
|
||||
stargazers_count: int | None = None
|
||||
link_header: str | None = None
|
||||
pushed_at: str | None = None # ISO 8601 format date string
|
||||
owner_type: OwnerType | None = (
|
||||
None # Whether the repository is owned by a user or organization
|
||||
)
|
||||
|
||||
|
||||
class AuthenticationError(ValueError):
|
||||
|
||||
Reference in New Issue
Block a user