This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a commit to branch dev0620-1
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/dev0620-1 by this push:
     new 66f16e8f1 feat(azuredevops): still work in progress, try to add 
pull_request_labels data
66f16e8f1 is described below

commit 66f16e8f19a4ca9eec178b122eaad4108d1feba1
Author: d4x1 <[email protected]>
AuthorDate: Fri Jun 21 14:34:45 2024 +0800

    feat(azuredevops): still work in progress, try to add pull_request_labels 
data
---
 .../plugins/azuredevops/azuredevops/models.py      | 20 ++++----
 .../azuredevops/streams/pull_requests.py           | 57 ++++++++++++----------
 2 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/backend/python/plugins/azuredevops/azuredevops/models.py 
b/backend/python/plugins/azuredevops/azuredevops/models.py
index 27c112429..ebf6158e3 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 SQLModel
 
 # needed to be able to run migrations
 from azuredevops.migrations import *
+from pydevlake import ScopeConfig
+from pydevlake.model import ToolScope
 
 
 class AzureDevOpsConnection(Connection):
@@ -53,6 +48,12 @@ class GitRepository(ToolScope, table=True):
         return bool(self.provider)
 
 
+class GitPullRequestLabel(SQLModel, table=False):
+    id: str
+    name: str
+    active: bool
+
+
 class GitPullRequest(ToolModel, table=True):
     class PRStatus(Enum):
         Abandoned = "abandoned"
@@ -75,6 +76,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[GitPullRequestLabel]] = Field(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..0f12626d2 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
@@ -55,26 +56,32 @@ class GitPullRequests(Stream):
             status = 'OPEN'
         elif pr.status == GitPullRequest.PRStatus.Completed:
             status = 'MERGED'
-
-        yield code.PullRequest(
-            base_repo_id=base_repo_id,
-            head_repo_id=repo_id,
-            status=status,
-            original_status=pr.status.value,
-            title=pr.title,
-            description=pr.description,
-            url=f"{ctx.scope.url}/pullrequest/{pr.pull_request_id}",
-            author_name=pr.created_by_name,
-            author_id=pr.created_by_id,
-            pull_request_key=pr.pull_request_id,
-            created_date=pr.creation_date,
-            merged_date=pr.closed_date,
-            closed_date=pr.closed_date,
-            type=pr.type,
-            component="",  # not supported
-            merge_commit_sha=pr.merge_commit_sha,
-            head_ref=pr.source_ref_name,
-            base_ref=pr.target_ref_name,
-            head_commit_sha=pr.source_commit_sha,
-            base_commit_sha=pr.target_commit_sha
-        )
+        if pr._labels:
+            for label in pr._labels:
+                print(f"--->{label.name}")
+                yield code.PullRequestLabels(
+                    
pull_request_id=print(f"azudedevops:GitPullRequest:{ctx.connection.id}:{pr.pull_request_id}"),
+                    label_name=label.name,
+                )
+            yield code.PullRequest(
+                base_repo_id=base_repo_id,
+                head_repo_id=repo_id,
+                status=status,
+                original_status=pr.status.value,
+                title=pr.title,
+                description=pr.description,
+                url=f"{ctx.scope.url}/pullrequest/{pr.pull_request_id}",
+                author_name=pr.created_by_name,
+                author_id=pr.created_by_id,
+                pull_request_key=pr.pull_request_id,
+                created_date=pr.creation_date,
+                merged_date=pr.closed_date,
+                closed_date=pr.closed_date,
+                type=pr.type,
+                component="",  # not supported
+                merge_commit_sha=pr.merge_commit_sha,
+                head_ref=pr.source_ref_name,
+                base_ref=pr.target_ref_name,
+                head_commit_sha=pr.source_commit_sha,
+                base_commit_sha=pr.target_commit_sha
+            )

Reply via email to