Skip to content

Gitlab repo sync ETL handler #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions backend/analytics_server/mhq/exapi/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ def __init__(self, access_token: str, domain="gitlab.com"):
self.base_url = f"https://{domain}/api/v4"
self.headers = {"Authorization": f"Bearer {self._token}"}

def check_pat(self) -> bool:
"""
Checks if PAT is Valid
:returns:
:raises HTTPError: If the request fails and status code is not 200
"""
url = f"{self.base_url}/user"
try:
response = requests.get(url, headers=self.headers)
except Exception as e:
raise Exception(f"Error in PAT validation, Error: {e.data}")

return response.status_code == 200

def _handle_error(self, response):
if response.status_code != 200:
error = response.json().get("error", "")
Expand Down
1 change: 1 addition & 0 deletions backend/analytics_server/mhq/service/code/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

CODE_INTEGRATION_BUCKET = [
UserIdentityProvider.GITHUB.value,
UserIdentityProvider.GITLAB.value,
]


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from mhq.service.code.sync.etl_gitlab_handler import get_gitlab_etl_handler
from mhq.service.code.sync.etl_github_handler import get_github_etl_handler
from mhq.service.code.sync.etl_provider_handler import CodeProviderETLHandler
from mhq.store.models.code import CodeProvider
Expand All @@ -10,4 +11,8 @@ def __init__(self, org_id: str):
def __call__(self, provider: str) -> CodeProviderETLHandler:
if provider == CodeProvider.GITHUB.value:
return get_github_etl_handler(self.org_id)

if provider == CodeProvider.GITLAB.value:
return get_gitlab_etl_handler(self.org_id)

raise NotImplementedError(f"Unknown provider - {provider}")
Loading
Loading