Skip to content

Commit

Permalink
optional webhook (#71)
Browse files Browse the repository at this point in the history
* optional webhook
  • Loading branch information
yairsimantov20 authored Aug 11, 2023
1 parent d4bebea commit f646e93
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 14 deletions.
4 changes: 2 additions & 2 deletions integrations/gitlab/.port/spec.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: v0.1.8
version: v0.1.9
type: gitlab
description: Gitlab integration for Port Ocean
icon: GitLab
Expand All @@ -16,7 +16,7 @@ configurations:
description: "Mapping of Gitlab tokens to Port Ocean tokens. example: {\"THE_GROUP_TOKEN\":[\"getport-labs/**\", \"GROUP/PROJECT PATTERN TO RUN FOR\"]}"
sensitive: true
- name: appHost
required: true
required: false
type: url
description: The host of the Port Ocean app. Used for setting up the webhooks against the Gitlab.
- name: gitlabHost
Expand Down
8 changes: 8 additions & 0 deletions integrations/gitlab/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

0.1.9 (2023-08-11)
==================

### Improvements

- Made the webhook live events feature optional


0.1.8 (2023-08-11)
==================

Expand Down
1 change: 0 additions & 1 deletion integrations/gitlab/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ integration:
# The configuration of the integration.
config:
tokenMapping: "{{ from env TOKEN_MAPPING }}"
appHost: "{{ from env APP_HOST }}"
16 changes: 7 additions & 9 deletions integrations/gitlab/gitlab_integration/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from gitlab import Gitlab

from gitlab_integration.events.event_handler import EventHandler
from gitlab_integration.events.hooks.issues import Issues
from gitlab_integration.events.hooks.jobs import Job
Expand All @@ -7,8 +8,6 @@
from gitlab_integration.events.hooks.push import PushHook
from gitlab_integration.gitlab_service import GitlabService

from port_ocean.context.ocean import ocean

event_handler = EventHandler()


Expand All @@ -25,13 +24,12 @@ def setup_listeners(gitlab_service: GitlabService, webhook_id: str | int) -> Non
event_handler.on(event_ids, handler.on_hook)


def setup_application() -> None:
logic_settings = ocean.integration_config
for token, group_mapping in logic_settings["token_mapping"].items():
gitlab_client = Gitlab(logic_settings["gitlab_host"], token)
gitlab_service = GitlabService(
gitlab_client, logic_settings["app_host"], group_mapping
)
def setup_application(
token_mapping: dict[str, list[str]], gitlab_host: str, app_host: str
) -> None:
for token, group_mapping in token_mapping.items():
gitlab_client = Gitlab(gitlab_host, token)
gitlab_service = GitlabService(gitlab_client, app_host, group_mapping)
webhook_ids = gitlab_service.create_webhooks()
for webhook_id in webhook_ids:
setup_listeners(gitlab_service, webhook_id)
19 changes: 18 additions & 1 deletion integrations/gitlab/gitlab_integration/ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from port_ocean.context.ocean import ocean
from port_ocean.core.ocean_types import RAW_RESULT, ASYNC_GENERATOR_RESYNC_TYPE

NO_WEBHOOK_WARNING = "Without setting up the webhook, the integration will not export live changes from the gitlab"

all_tokens_services = get_all_services()


Expand All @@ -23,7 +25,22 @@ async def handle_webhook(group_id: str, request: Request) -> dict[str, Any]:

@ocean.on_start()
async def on_start() -> None:
setup_application()
logic_settings = ocean.integration_config
if not logic_settings.get("app_host"):
logger.warning(
f"No app host provided, skipping webhook creation. {NO_WEBHOOK_WARNING}"
)
try:
setup_application(
logic_settings["token_mapping"],
logic_settings["gitlab_host"],
logic_settings["app_host"],
)
except Exception as e:
logger.warning(
f"Failed to setup webhook: {e}. {NO_WEBHOOK_WARNING}",
stack_info=True,
)


@ocean.on_resync(ObjectKind.PROJECT)
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.8"
version = "0.1.9"
description = "Gitlab integration for Port using Port-Ocean Framework"
authors = ["Yair Siman-Tov <yair@getport.io>"]

Expand Down
4 changes: 4 additions & 0 deletions integrations/jira/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ install:
$(call install_poetry) && \
poetry install --with dev

install/prod:
$(call install_poetry) && \
poetry install --without dev --no-root --no-interaction --no-ansi --no-cache

lint:
$(ACTIVATE) && \
$(call run_checks,.)
Expand Down
4 changes: 4 additions & 0 deletions integrations/newrelic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ install:
$(call install_poetry) && \
poetry install --with dev

install/prod:
$(call install_poetry) && \
poetry install --without dev --no-root --no-interaction --no-ansi --no-cache

lint:
$(ACTIVATE) && \
$(call run_checks,.)
Expand Down
4 changes: 4 additions & 0 deletions integrations/pagerduty/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ install:
$(call install_poetry) && \
poetry install --with dev

install/prod:
$(call install_poetry) && \
poetry install --without dev --no-root --no-interaction --no-ansi --no-cache

lint:
$(ACTIVATE) && \
$(call run_checks,.)
Expand Down

0 comments on commit f646e93

Please sign in to comment.