Skip to content

Conversation

dennis-bilson-port
Copy link
Member

@dennis-bilson-port dennis-bilson-port commented Oct 15, 2025

User description

This PR adds support for syncing GitLab releases and tags as new resource kinds.

What -

Why -

How -

Type of change

Please leave one option from the following and delete the rest:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • New Integration (non-breaking change which adds a new integration)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Non-breaking change (fix of existing functionality that will not change current behavior)
  • Documentation (added/updated documentation)

All tests should be run against the port production environment(using a testing org).

Core testing checklist

  • Integration able to create all default resources from scratch
  • Resync finishes successfully
  • Resync able to create entities
  • Resync able to update entities
  • Resync able to detect and delete entities
  • Scheduled resync able to abort existing resync and start a new one
  • Tested with at least 2 integrations from scratch
  • Tested with Kafka and Polling event listeners
  • Tested deletion of entities that don't pass the selector

Integration testing checklist

  • Integration able to create all default resources from scratch
  • Completed a full resync from a freshly installed integration and it completed successfully
  • Resync able to create entities
  • Resync able to update entities
  • Resync able to detect and delete entities
  • Resync finishes successfully
  • If new resource kind is added or updated in the integration, add example raw data, mapping and expected result to the examples folder in the integration directory.
  • If resource kind is updated, run the integration with the example data and check if the expected result is achieved
  • If new resource kind is added or updated, validate that live-events for that resource are working as expected
  • Docs PR link here

Preflight checklist

  • Handled rate limiting
  • Handled pagination
  • Implemented the code in async
  • Support Multi account

Screenshots

image image image image

API Documentation

Provide links to the API documentation used for this integration.


PR Type

Enhancement


Description

  • Added support for syncing GitLab releases and tags as new resource kinds

  • Implemented get_tags() and get_releases() methods with project enrichment

  • Added new blueprints and Port mappings for tag and release entities

  • Created comprehensive test coverage for new tag and release functionality


Diagram Walkthrough

flowchart LR
  client["GitLabClient"] -- "fetch tags/releases" --> enrichment["get_projects_resource_with_enrichment"]
  enrichment -- "enrich with project info" --> resources["Tags & Releases"]
  resources -- "sync to Port" --> blueprints["Port Blueprints"]
  main["main.py"] -- "register handlers" --> resync["on_resync_tags/releases"]
Loading

File Walkthrough

Relevant files
Enhancement
3 files
gitlab_client.py
Add methods for fetching tags and releases with enrichment
+75/-0   
utils.py
Add TAG and RELEASE to ObjectKind enum                                     
+2/-0     
main.py
Implement resync handlers for tags and releases                   
+36/-0   
Configuration changes
4 files
integration.py
Add TagResourceConfig and ReleaseResourceConfig classes   
+12/-0   
blueprints.json
Define blueprints for gitlabTag and gitlabRelease entities
+104/-0 
port-app-config.yml
Add Port mappings for tag and release kinds                           
+40/-1   
spec.yaml
Register releases and tags as exportable resources             
+2/-0     
Tests
1 files
test_gitlab_client.py
Add test cases for tags and releases functionality             
+103/-0 
Documentation
1 files
CHANGELOG.md
Document addition of releases and tags support                     
+8/-0     
Dependencies
1 files
pyproject.toml
Bump version to 0.2.37                                                                     
+1/-1     

@dennis-bilson-port dennis-bilson-port self-assigned this Oct 15, 2025
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-2294.d1ftd8v2gowp8w.amplifyapp.com

@dennis-bilson-port dennis-bilson-port marked this pull request as ready for review October 15, 2025 12:59
Copy link
Contributor

qodo-merge-pro bot commented Oct 15, 2025

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
Identifier normalization

Description: The entity identifiers for tags and releases are derived from user-controlled names
without strict normalization (only spaces removed), which could allow collisions or path
traversal-like identifiers across namespaces; ensure robust normalization/escaping and
uniqueness guarantees.
port-app-config.yml [65-112]

Referred Code
            | sub("\\..*Z$"; "Z") | strptime("%Y-%m-%dT%H:%M:%SZ") | mktime)
            as $createdTimestamp | ($mergedAt | if . == null then null else
            sub("\\..*Z$"; "Z") | strptime("%Y-%m-%dT%H:%M:%SZ") | mktime end)
            as $mergedTimestamp | if $mergedTimestamp == null then null else
            (((($mergedTimestamp - $createdTimestamp) / 3600) * 100 | floor) /
            100) end)
          reviewers: .reviewers | map(.name)
        relations:
          service: .references.full | gsub("!.+"; "")
- kind: tag
  selector:
    query: 'true'
  port:
    entity:
      mappings:
        identifier: .__project.path_with_namespace + "/" + .name | gsub(" "; "")
        title: .name
        blueprint: '"gitlabTag"'
        properties:
          tagName: .name
          message: .message


 ... (clipped 27 lines)
Ticket Compliance
🎫 No ticket provided
- [ ] Create ticket/issue <!-- /create_ticket --create_ticket=true -->

</details></td></tr>
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
No custom compliance provided

Follow the guide to enable custom compliance check.

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

Copy link
Contributor

qodo-merge-pro bot commented Oct 15, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Avoid re-fetching all GitLab projects

The new resync handlers for tags and releases inefficiently re-fetch the entire
list of GitLab projects. This should be optimized by fetching the projects once
and caching them for reuse across all handlers during a resync event.

Examples:

integrations/gitlab-v2/main.py [203-217]
@ocean.on_resync(ObjectKind.TAG)
async def on_resync_tags(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
    client = create_gitlab_client()

    async for projects_batch in client.get_projects(
        params=_build_visibility_params(),
        max_concurrent=DEFAULT_MAX_CONCURRENT,
        include_languages=False,
    ):
        logger.info(f"Processing batch of {len(projects_batch)} projects for tags")

 ... (clipped 5 lines)
integrations/gitlab-v2/main.py [220-234]
@ocean.on_resync(ObjectKind.RELEASE)
async def on_resync_releases(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
    client = create_gitlab_client()

    async for projects_batch in client.get_projects(
        params=_build_visibility_params(),
        max_concurrent=DEFAULT_MAX_CONCURRENT,
        include_languages=False,
    ):
        logger.info(f"Processing batch of {len(projects_batch)} projects for releases")

 ... (clipped 5 lines)

Solution Walkthrough:

Before:

@ocean.on_resync(ObjectKind.TAG)
async def on_resync_tags(kind: str):
    client = create_gitlab_client()
    # This fetches all projects from the API
    async for projects_batch in client.get_projects(...):
        async for tags_batch in client.get_tags(projects_batch, ...):
            yield tags_batch

@ocean.on_resync(ObjectKind.RELEASE)
async def on_resync_releases(kind: str):
    client = create_gitlab_client()
    # This re-fetches all projects from the API again
    async for projects_batch in client.get_projects(...):
        async for releases_batch in client.get_releases(projects_batch, ...):
            yield releases_batch

After:

# In gitlab_client.py
# A caching decorator can be used, similar to other integrations
@cache_iterator_result("projects")
async def get_projects(self, ...):
    # This will now only fetch projects from the API on the first call
    # during a resync, and serve from cache on subsequent calls.
    async for projects_batch in self.rest.get_paginated_resource(...):
        yield projects_batch

# In main.py (no changes needed to the handlers)
@ocean.on_resync(ObjectKind.TAG)
async def on_resync_tags(kind: str):
    client = create_gitlab_client()
    async for projects_batch in client.get_projects(...): # Uses cache
        ...

@ocean.on_resync(ObjectKind.RELEASE)
async def on_resync_releases(kind: str):
    client = create_gitlab_client()
    async for projects_batch in client.get_projects(...): # Uses cache
        ...
Suggestion importance[1-10]: 9

__

Why: This suggestion correctly identifies a critical performance flaw where multiple resync handlers redundantly fetch all projects, and fixing it would drastically improve resync efficiency and reduce API load.

High
General
Cache project data to avoid redundant API calls

Refactor the resync logic to fetch the project list only once by caching the
projects in the event context, avoiding redundant API calls when resyncing both
tags and releases.

integrations/gitlab-v2/main.py [203-234]

+async def _get_projects_for_resync() -> ASYNC_GENERATOR_RESYNC_TYPE:
+    """
+    Wrapper for client.get_projects to cache the result in the event context
+    """
+    if "projects" not in event.attributes:
+        logger.info("Projects not found in event context, fetching from GitLab")
+        client = create_gitlab_client()
+        event.attributes["projects"] = [
+            project
+            async for projects_batch in client.get_projects(
+                params=_build_visibility_params(),
+                max_concurrent=DEFAULT_MAX_CONCURRENT,
+                include_languages=False,
+            )
+            for project in projects_batch
+        ]
+    else:
+        logger.info("Found projects in event context, using them")
+
+    projects = event.attributes["projects"]
+    batch_size = 50
+    for i in range(0, len(projects), batch_size):
+        yield projects[i : i + batch_size]
+
+
 @ocean.on_resync(ObjectKind.TAG)
 async def on_resync_tags(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
     client = create_gitlab_client()
-
-    async for projects_batch in client.get_projects(
-        params=_build_visibility_params(),
-        max_concurrent=DEFAULT_MAX_CONCURRENT,
-        include_languages=False,
-    ):
+    async for projects_batch in _get_projects_for_resync():
         logger.info(f"Processing batch of {len(projects_batch)} projects for tags")
-
         async for tags_batch in client.get_tags(
             projects_batch, max_concurrent=DEFAULT_MAX_CONCURRENT
         ):
             yield tags_batch
 
 
 @ocean.on_resync(ObjectKind.RELEASE)
 async def on_resync_releases(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
     client = create_gitlab_client()
-
-    async for projects_batch in client.get_projects(
-        params=_build_visibility_params(),
-        max_concurrent=DEFAULT_MAX_CONCURRENT,
-        include_languages=False,
-    ):
+    async for projects_batch in _get_projects_for_resync():
         logger.info(f"Processing batch of {len(projects_batch)} projects for releases")
-
         async for releases_batch in client.get_releases(
             projects_batch, max_concurrent=DEFAULT_MAX_CONCURRENT
         ):
             yield releases_batch
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies redundant API calls to fetch projects and proposes a valid caching strategy, which improves performance and makes the integration more robust against API rate limiting.

Medium
Replace spaces instead of removing them

In the JQ mappings for tag and release identifiers and relations, replace spaces
with hyphens instead of removing them to prevent potential identifier
collisions.

integrations/gitlab-v2/.port/resources/port-app-config.yml [74-112]

 - kind: tag
   selector:
     query: 'true'
   port:
     entity:
       mappings:
-        identifier: .__project.path_with_namespace + "/" + .name | gsub(" "; "")
+        identifier: .__project.path_with_namespace + "/" + .name | gsub(" "; "-")
         title: .name
         blueprint: '"gitlabTag"'
         properties:
           tagName: .name
           message: .message
           protected: .protected
           createdAt: .created_at
           commitSha: .commit.id
           commitTitle: .commit.title
         relations:
-          service: .__project.path_with_namespace | gsub(" "; "")
+          service: .__project.path_with_namespace | gsub(" "; "-")
 - kind: release
   selector:
     query: 'true'
   port:
     entity:
       mappings:
-        identifier: .__project.path_with_namespace + "/" + .tag_name | gsub(" "; "")
+        identifier: .__project.path_with_namespace + "/" + .tag_name | gsub(" "; "-")
         title: .name
         blueprint: '"gitlabRelease"'
         properties:
           tagName: .tag_name
           name: .name
           description: .description
           createdAt: .created_at
           releasedAt: .released_at
           author: .author.name
           commitSha: .commit.id
           upcomingRelease: .upcoming_release
         relations:
-          service: .__project.path_with_namespace | gsub(" "; "")
+          service: .__project.path_with_namespace | gsub(" "; "-")
           gitlabMember: .author.username
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly points out that removing spaces can lead to identifier collisions and proposes a more robust method of replacing them with hyphens, which is a standard and safer practice.

Low
  • Update

Copy link
Member

@mk-armah mk-armah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left few comments

Copy link
Member

@mk-armah mk-armah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mk-armah mk-armah merged commit 6620500 into main Oct 17, 2025
27 checks passed
@mk-armah mk-armah deleted the PORT-16592-Implement-Release-and-Tag-Kinds branch October 17, 2025 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants