Skip to content

Commit

Permalink
Merge branch 'main' into PORT-11906-add-expand-to-ado-work-item
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyGis authored Dec 11, 2024
2 parents 4c9b605 + f5a3928 commit a6291a5
Show file tree
Hide file tree
Showing 7 changed files with 2,738 additions and 853 deletions.
3,535 changes: 2,693 additions & 842 deletions docs/framework-guides/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/framework-guides/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"prism-react-renderer": "^2.3.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"redocusaurus": "^2.0.0",
"redocusaurus": "^2.1.2",
"remark-math": "^5.1.1",
"sass": "^1.81.0",
"stream": "^0.0.3",
Expand Down
12 changes: 12 additions & 0 deletions integrations/gitlab/.port/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,17 @@ configurations:
\"subgroup_events\",
\"confidential_issues_events\"]"
sensitive: true
saas:
enabled: true
oauthConfiguration:
requiredSecrets:
- name: tokenMapping
value: '{(.oauthData.accessToken): ["**"]} | @json'
description: '"Token mapping for Gitlab OAuth2 integration"'
valuesOverride:
integrationSpec:
gitlabHost: '"https://gitlab.com"'
appSpec:
minimumScheduledResyncInterval: '2h'
deploymentMethodOverride:
- type: helm
9 changes: 9 additions & 0 deletions integrations/gitlab/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

0.2.0 (2024-12-11)
====================

### Improvements

- Added support for OAuth2.0 token
- Added OAuth installation specification for Port


0.1.147 (2024-12-10)
====================

Expand Down
7 changes: 3 additions & 4 deletions integrations/gitlab/gitlab_integration/events/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Type, List

from gitlab import Gitlab

from loguru import logger

from gitlab_integration.events.event_handler import EventHandler, SystemEventHandler
Expand All @@ -26,6 +24,7 @@
GitlabEventListenerConflict,
GitlabIllegalEventName,
)
from gitlab_integration.utils import generate_gitlab_client

event_handler = EventHandler()
system_event_handler = SystemEventHandler()
Expand Down Expand Up @@ -161,7 +160,7 @@ async def create_webhooks_by_client(
groups_hooks_events_override: dict[str, WebhookGroupConfig] | None,
group_mapping: list[str],
) -> tuple[GitlabService, list[str]]:
gitlab_client = Gitlab(gitlab_host, token)
gitlab_client = generate_gitlab_client(gitlab_host, token)
gitlab_service = GitlabService(gitlab_client, app_host, group_mapping)

groups_for_webhooks = await gitlab_service.get_filtered_groups_for_webhooks(
Expand Down Expand Up @@ -203,7 +202,7 @@ async def setup_application(
logger.info("Using system hook")
validate_use_system_hook(token_mapping)
token, group_mapping = list(token_mapping.items())[0]
gitlab_client = Gitlab(gitlab_host, token)
gitlab_client = generate_gitlab_client(gitlab_host, token)
gitlab_service = GitlabService(gitlab_client, app_host, group_mapping)
setup_system_listeners([gitlab_service])

Expand Down
24 changes: 19 additions & 5 deletions integrations/gitlab/gitlab_integration/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List

import gitlab
from gitlab import Gitlab
from gitlab_integration.gitlab_service import GitlabService
from loguru import logger
Expand All @@ -10,6 +11,23 @@
RETRY_TRANSIENT_ERRORS = True


def generate_gitlab_client(host: str, token: str) -> Gitlab:
try:
gitlab_client = Gitlab(
host, token, retry_transient_errors=RETRY_TRANSIENT_ERRORS
)
gitlab_client.auth()
logger.info("Successfully authenticated using the provided private token")
except gitlab.exceptions.GitlabAuthenticationError:
gitlab_client = Gitlab(
host, oauth_token=token, retry_transient_errors=RETRY_TRANSIENT_ERRORS
)
gitlab_client.auth()
logger.info("Successfully authenticated using the provided OAuth2.0 token")

return gitlab_client


def get_all_services() -> List[GitlabService]:
logic_settings = ocean.integration_config
all_tokens_services = []
Expand All @@ -18,11 +36,7 @@ def get_all_services() -> List[GitlabService]:
f"Creating gitlab clients for {len(logic_settings['token_mapping'])} tokens"
)
for token, group_mapping in logic_settings["token_mapping"].items():
gitlab_client = Gitlab(
logic_settings["gitlab_host"],
token,
retry_transient_errors=RETRY_TRANSIENT_ERRORS,
)
gitlab_client = generate_gitlab_client(logic_settings["gitlab_host"], token)
gitlab_service = GitlabService(
gitlab_client, logic_settings["app_host"], group_mapping
)
Expand Down
2 changes: 1 addition & 1 deletion integrations/gitlab/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gitlab"
version = "0.1.147"
version = "0.2.0"
description = "Gitlab integration for Port using Port-Ocean Framework"
authors = ["Yair Siman-Tov <[email protected]>"]

Expand Down

0 comments on commit a6291a5

Please sign in to comment.