Skip to content

Commit 9fc9b5b

Browse files
authored
fix(azuredevops): default empty entities and add CROSS to repo scope in makeScopeV200 (#8751)
When scopeConfig.Entities is empty (common when no entities are explicitly selected in the UI), makeScopeV200 produced zero scopes, leaving project_mapping with no rows. Additionally, the repo scope condition did not check for DOMAIN_TYPE_CROSS, so selecting only CROSS would not create a repo scope, breaking DORA metrics. This adds the same fixes applied to GitLab in #8743. Closes #8749
1 parent 04795c2 commit 9fc9b5b

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

backend/plugins/azuredevops_go/api/blueprint_v200.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,14 @@ func makeScopeV200(
7777
}
7878
id := didgen.NewDomainIdGenerator(&models.AzuredevopsRepo{}).Generate(connectionId, azuredevopsRepo.Id)
7979

80+
// if no entities specified, use all entities enabled by default
81+
if len(scopeConfig.Entities) == 0 {
82+
scopeConfig.Entities = plugin.DOMAIN_TYPES
83+
}
84+
8085
if utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE_REVIEW) ||
81-
utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE) {
86+
utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE) ||
87+
utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CROSS) {
8288
// if we don't need to collect gitex, we need to add repo to scopes here
8389
scopeRepo := code.NewRepo(id, azuredevopsRepo.Name)
8490
sc = append(sc, scopeRepo)

backend/plugins/azuredevops_go/api/blueprint_v200_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,64 @@ func TestMakeScopes(t *testing.T) {
7878
assert.Equal(t, actualScopes[2].ScopeId(), expectDomainScopeId)
7979
}
8080

81+
func TestMakeScopesWithEmptyEntities(t *testing.T) {
82+
mockAzuredevopsPlugin(t)
83+
84+
actualScopes, err := makeScopeV200(
85+
connectionID,
86+
[]*srvhelper.ScopeDetail[models.AzuredevopsRepo, models.AzuredevopsScopeConfig]{
87+
{
88+
Scope: models.AzuredevopsRepo{
89+
Scope: common.Scope{
90+
ConnectionId: connectionID,
91+
},
92+
Id: azuredevopsRepoId,
93+
Type: models.RepositoryTypeADO,
94+
},
95+
ScopeConfig: &models.AzuredevopsScopeConfig{
96+
ScopeConfig: common.ScopeConfig{
97+
Entities: []string{},
98+
},
99+
},
100+
},
101+
},
102+
)
103+
assert.Nil(t, err)
104+
// empty entities should default to all domain types, producing repo + cicd + board scopes
105+
assert.Equal(t, 3, len(actualScopes))
106+
assert.Equal(t, actualScopes[0].ScopeId(), expectDomainScopeId)
107+
}
108+
109+
func TestMakeScopesWithCrossEntity(t *testing.T) {
110+
mockAzuredevopsPlugin(t)
111+
112+
actualScopes, err := makeScopeV200(
113+
connectionID,
114+
[]*srvhelper.ScopeDetail[models.AzuredevopsRepo, models.AzuredevopsScopeConfig]{
115+
{
116+
Scope: models.AzuredevopsRepo{
117+
Scope: common.Scope{
118+
ConnectionId: connectionID,
119+
},
120+
Id: azuredevopsRepoId,
121+
Type: models.RepositoryTypeADO,
122+
},
123+
ScopeConfig: &models.AzuredevopsScopeConfig{
124+
ScopeConfig: common.ScopeConfig{
125+
Entities: []string{plugin.DOMAIN_TYPE_CROSS, plugin.DOMAIN_TYPE_TICKET},
126+
},
127+
},
128+
},
129+
},
130+
)
131+
assert.Nil(t, err)
132+
// CROSS entity should trigger repo scope creation, plus ticket = board scope
133+
assert.Equal(t, 2, len(actualScopes))
134+
assert.Equal(t, actualScopes[0].ScopeId(), expectDomainScopeId)
135+
assert.Equal(t, "repos", actualScopes[0].TableName())
136+
assert.Equal(t, "boards", actualScopes[1].TableName())
137+
}
138+
81139
func TestMakeDataSourcePipelinePlanV200(t *testing.T) {
82140
mockAzuredevopsPlugin(t)
83141

0 commit comments

Comments
 (0)