This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new aa2a0cda8 feat(azuredevops): collector pr's labels to table
pull_request_labels (#7706)
aa2a0cda8 is described below
commit aa2a0cda8ebeb54d7d6321f7ef17bf9f3c8e29eb
Author: Lynwee <[email protected]>
AuthorDate: Tue Jul 9 15:36:30 2024 +0800
feat(azuredevops): collector pr's labels to table pull_request_labels
(#7706)
---
.../plugins/azuredevops/azuredevops/migrations.py | 18 ++++++++++++------
.../python/plugins/azuredevops/azuredevops/models.py | 14 +++++---------
.../azuredevops/azuredevops/streams/pull_requests.py | 12 ++++++++++--
3 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/backend/python/plugins/azuredevops/azuredevops/migrations.py
b/backend/python/plugins/azuredevops/azuredevops/migrations.py
index e12dc76e5..383cbc9dd 100644
--- a/backend/python/plugins/azuredevops/azuredevops/migrations.py
+++ b/backend/python/plugins/azuredevops/azuredevops/migrations.py
@@ -215,14 +215,14 @@ def
add_updated_url_column_length_in_tool_azuredevops_builds(b: MigrationScriptB
@migration(20240527113400, name="Update url column in _raw_azuredevops_builds
")
def add_updated_url_column_length_in_raw_azuredevops_builds(b:
MigrationScriptBuilder):
table = '_raw_azuredevops_builds'
-
+
b.execute(f"""
CREATE PROCEDURE alter_url_column_if_exists()
BEGIN
DECLARE table_exists INT DEFAULT 0;
SELECT COUNT(*) INTO table_exists
- FROM information_schema.tables
- WHERE table_schema = DATABASE()
+ FROM information_schema.tables
+ WHERE table_schema = DATABASE()
AND table_name = '{table}';
IF table_exists > 0 THEN
ALTER TABLE {table} MODIFY COLUMN url TEXT;
@@ -231,14 +231,14 @@ def
add_updated_url_column_length_in_raw_azuredevops_builds(b: MigrationScriptBu
END IF;
END;
""", Dialect.MYSQL)
-
+
b.execute(f"CALL alter_url_column_if_exists();", Dialect.MYSQL)
b.execute(f"DROP PROCEDURE alter_url_column_if_exists;", Dialect.MYSQL)
-
+
b.execute(f"""
DO $$
BEGIN
- IF EXISTS (SELECT FROM information_schema.tables
+ IF EXISTS (SELECT FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = '{table}')
THEN
ALTER TABLE {table} ALTER COLUMN url TYPE TEXT;
ELSE
@@ -247,3 +247,9 @@ def
add_updated_url_column_length_in_raw_azuredevops_builds(b: MigrationScriptBu
END $$;
""", Dialect.POSTGRESQL)
+
+@migration(20240708182800, name="add labels field in
_tool_azuredevops_gitpullrequests")
+def add_labels_field_in_tool_azuredevops_gitpullrequests(b:
MigrationScriptBuilder):
+ table = '_tool_azuredevops_gitpullrequests'
+ b.execute(f'ALTER TABLE {table} ADD COLUMN labels json DEFAULT NULL',
Dialect.MYSQL)
+ b.execute(f'ALTER TABLE {table} ADD COLUMN labels jsonb',
Dialect.POSTGRESQL)
diff --git a/backend/python/plugins/azuredevops/azuredevops/models.py
b/backend/python/plugins/azuredevops/azuredevops/models.py
index 27c112429..58ebb0624 100644
--- a/backend/python/plugins/azuredevops/azuredevops/models.py
+++ b/backend/python/plugins/azuredevops/azuredevops/models.py
@@ -13,19 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import datetime
-import re
-from enum import Enum
-from typing import Optional
+from typing import List
-from pydantic import SecretStr
-
-from pydevlake import ScopeConfig, Field
-from pydevlake.model import ToolScope, ToolModel, Connection
-from pydevlake.pipeline_tasks import RefDiffOptions
+from sqlmodel import Column, JSON
# needed to be able to run migrations
from azuredevops.migrations import *
+from pydevlake import ScopeConfig
+from pydevlake.model import ToolScope
class AzureDevOpsConnection(Connection):
@@ -75,6 +70,7 @@ class GitPullRequest(ToolModel, table=True):
target_ref_name: Optional[str]
source_ref_name: Optional[str]
fork_repo_id: Optional[str] = Field(source='/forkSource/repository/id')
+ labels: Optional[List[dict]] = Field(sa_column=Column(JSON),
source="/labels")
class GitPullRequestCommit(ToolModel, table=True):
diff --git
a/backend/python/plugins/azuredevops/azuredevops/streams/pull_requests.py
b/backend/python/plugins/azuredevops/azuredevops/streams/pull_requests.py
index f58776d99..e7d5c37a0 100644
--- a/backend/python/plugins/azuredevops/azuredevops/streams/pull_requests.py
+++ b/backend/python/plugins/azuredevops/azuredevops/streams/pull_requests.py
@@ -15,10 +15,10 @@
from typing import Iterable
+import pydevlake.domain_layer.code as code
from azuredevops.api import AzureDevOpsAPI
from azuredevops.models import GitRepository, GitPullRequest
from pydevlake import Stream, DomainType, domain_id
-import pydevlake.domain_layer.code as code
class GitPullRequests(Stream):
@@ -45,7 +45,8 @@ class GitPullRequests(Stream):
def convert(self, pr: GitPullRequest, ctx):
repo_id = ctx.scope.domain_id()
# If the PR is from a fork, we forge a new repo ID for the base repo,
but it doesn't correspond to a real repo
- base_repo_id = domain_id(GitRepository, ctx.connection.id,
pr.fork_repo_id) if pr.fork_repo_id is not None else repo_id
+ base_repo_id = domain_id(GitRepository, ctx.connection.id,
+ pr.fork_repo_id) if pr.fork_repo_id is not
None else repo_id
# Use the same status values as GitHub plugin
status = None
@@ -78,3 +79,10 @@ class GitPullRequests(Stream):
head_commit_sha=pr.source_commit_sha,
base_commit_sha=pr.target_commit_sha
)
+ if pr.labels is not None:
+ for label_dict in pr.labels:
+ if "name" in label_dict:
+ yield code.PullRequestLabels(
+ pull_request_id=pr.pull_request_id,
+ label_name=label_dict["name"],
+ )