You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ma...@apache.org on 2024/06/09 17:50:25 UTC

(incubator-devlake) 01/01: feat(azuredevops): support disabled Azure DevOps Repos

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

markusb pushed a commit to branch feat/ado-disabled-repos
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 211ddc0d9a61eb95692e2dfa7bea58895460b395
Author: Markus Braunbeck <32...@users.noreply.github.com>
AuthorDate: Sun Jun 9 19:46:10 2024 +0200

    feat(azuredevops): support disabled Azure DevOps Repos
    
    It is now possible to select disabled repositories as a remote scope. However, disabled repositories are not included in tasks related to domain `code` and `code review`, as the Azure DevOps API returns a 4xx status code for the required API calls.
    
    A new column called `is_disabled` has been added to the `_tool_azuredevops_go_repos` table to support disabled repositories. For existing entries, the default value for this column is set to `false`.
---
 .../plugins/azuredevops_go/api/blueprint_v200.go   |  5 +-
 .../azuredevops_go/api/blueprint_v200_test.go      | 13 +++---
 .../plugins/azuredevops_go/api/remote_helper.go    |  4 --
 .../20246008_support_disabled_repos.go             | 54 ++++++++++++++++++++++
 .../models/migrationscripts/register.go            |  1 +
 backend/plugins/azuredevops_go/models/repo.go      |  1 +
 6 files changed, 65 insertions(+), 13 deletions(-)

diff --git a/backend/plugins/azuredevops_go/api/blueprint_v200.go b/backend/plugins/azuredevops_go/api/blueprint_v200.go
index 59a587b78..a0fea7695 100644
--- a/backend/plugins/azuredevops_go/api/blueprint_v200.go
+++ b/backend/plugins/azuredevops_go/api/blueprint_v200.go
@@ -77,9 +77,8 @@ func makeScopeV200(
 		}
 		id := didgen.NewDomainIdGenerator(&models.AzuredevopsRepo{}).Generate(connectionId, azuredevopsRepo.Id)
 
-		if utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE_REVIEW) ||
-			utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE) {
-			// if we don't need to collect gitex, we need to add repo to scopes here
+		if !azuredevopsRepo.IsDisabled && (utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE_REVIEW) ||
+			utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE)) {
 			scopeRepo := code.NewRepo(id, azuredevopsRepo.Name)
 			sc = append(sc, scopeRepo)
 		}
diff --git a/backend/plugins/azuredevops_go/api/blueprint_v200_test.go b/backend/plugins/azuredevops_go/api/blueprint_v200_test.go
index ceddcda68..2cb2a2513 100644
--- a/backend/plugins/azuredevops_go/api/blueprint_v200_test.go
+++ b/backend/plugins/azuredevops_go/api/blueprint_v200_test.go
@@ -190,12 +190,12 @@ func TestMakeRemoteRepoScopes(t *testing.T) {
 		Name           string
 		Type           string
 		Private        bool
+		Disabled       bool
 		ExpectedScopes []string
 	}{
 		{Name: "Azure DevOps Repository", Type: models.RepositoryTypeADO, Private: false, ExpectedScopes: []string{"*code.Repo", "*ticket.Board", "*devops.CicdScope"}},
-
+		{Name: "Azure DevOps disabled Repository", Type: models.RepositoryTypeADO, Disabled: true, ExpectedScopes: []string{"*ticket.Board", "*devops.CicdScope"}},
 		{Name: "Public GitHub Repository", Type: models.RepositoryTypeGithub, Private: false, ExpectedScopes: []string{"*code.Repo", "*devops.CicdScope"}},
-
 		{Name: "Private GitHub Repository", Type: models.RepositoryTypeGithub, Private: true, ExpectedScopes: []string{"*devops.CicdScope"}},
 	}
 
@@ -212,10 +212,11 @@ func TestMakeRemoteRepoScopes(t *testing.T) {
 							Scope: common.Scope{
 								ConnectionId: connectionID,
 							},
-							Id:        id,
-							Type:      d.Type,
-							Name:      d.Name,
-							IsPrivate: d.Private,
+							Id:         id,
+							Type:       d.Type,
+							Name:       d.Name,
+							IsPrivate:  d.Private,
+							IsDisabled: d.Disabled,
 						},
 						ScopeConfig: &models.AzuredevopsScopeConfig{
 							ScopeConfig: common.ScopeConfig{
diff --git a/backend/plugins/azuredevops_go/api/remote_helper.go b/backend/plugins/azuredevops_go/api/remote_helper.go
index 00110daf6..4cf26cba6 100644
--- a/backend/plugins/azuredevops_go/api/remote_helper.go
+++ b/backend/plugins/azuredevops_go/api/remote_helper.go
@@ -149,10 +149,6 @@ func listAzuredevopsRepos(
 	}
 
 	for _, v := range repos {
-		if v.IsDisabled {
-			continue
-		}
-
 		pID := orgId + idSeparator + projectId
 		repo := models.AzuredevopsRepo{
 			Id:        v.Id,
diff --git a/backend/plugins/azuredevops_go/models/migrationscripts/20246008_support_disabled_repos.go b/backend/plugins/azuredevops_go/models/migrationscripts/20246008_support_disabled_repos.go
new file mode 100644
index 000000000..818db13c2
--- /dev/null
+++ b/backend/plugins/azuredevops_go/models/migrationscripts/20246008_support_disabled_repos.go
@@ -0,0 +1,54 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/core/context"
+	"github.com/apache/incubator-devlake/core/dal"
+	"github.com/apache/incubator-devlake/core/errors"
+	"github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+type disabledRepos struct{}
+
+type SupportDisabledRepos struct {
+	IsDisabled bool
+}
+
+func (SupportDisabledRepos) TableName() string {
+	return "_tool_azuredevops_go_repos"
+}
+
+func (*disabledRepos) Up(baseRes context.BasicRes) errors.Error {
+	err := migrationhelper.AutoMigrateTables(baseRes, &SupportDisabledRepos{})
+	if err != nil {
+		return err
+	}
+
+	return baseRes.GetDal().UpdateColumn(
+		&SupportDisabledRepos{}, "is_disabled", false,
+		dal.Where("is_disabled IS NULL"))
+}
+
+func (*disabledRepos) Version() uint64 {
+	return 20240806100000
+}
+
+func (*disabledRepos) Name() string {
+	return "add [is_disabled] to _tool_azuredevops_go_repos in order to support disabled repositories"
+}
diff --git a/backend/plugins/azuredevops_go/models/migrationscripts/register.go b/backend/plugins/azuredevops_go/models/migrationscripts/register.go
index 59fa7832f..c1d97a08b 100644
--- a/backend/plugins/azuredevops_go/models/migrationscripts/register.go
+++ b/backend/plugins/azuredevops_go/models/migrationscripts/register.go
@@ -26,5 +26,6 @@ func All() []plugin.MigrationScript {
 	return []plugin.MigrationScript{
 		new(addInitTables),
 		new(extendRepoTable),
+		new(disabledRepos),
 	}
 }
diff --git a/backend/plugins/azuredevops_go/models/repo.go b/backend/plugins/azuredevops_go/models/repo.go
index dd171996f..e4ff5a7fc 100644
--- a/backend/plugins/azuredevops_go/models/repo.go
+++ b/backend/plugins/azuredevops_go/models/repo.go
@@ -36,6 +36,7 @@ type AzuredevopsRepo struct {
 	ExternalId string
 	IsFork     bool
 	IsPrivate  bool
+	IsDisabled bool
 }
 
 func (repo AzuredevopsRepo) ScopeId() string {