Skip to content

Commit a21382a

Browse files
spiffazSpiff Azeta
andauthored
fix(gitlab): add missing repos scope in project_mapping (#8743)
GitLab's makeScopeV200 did not create a repos scope when scopeConfig.Entities was empty or only contained CROSS. This caused project_mapping to have no table='repos' row, breaking downstream DORA metrics, PR-issue linking, and all PR dashboard panels that join on project_mapping. The fix aligns GitLab with the GitHub plugin by: 1. Defaulting empty entities to plugin.DOMAIN_TYPES 2. Adding DOMAIN_TYPE_CROSS to the repo scope condition Closes #8742 Co-authored-by: Spiff Azeta <spiffazeta@gmail.com>
1 parent 3b10ef7 commit a21382a

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

backend/plugins/gitlab/api/blueprint_V200_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,70 @@ func TestMakeScopes(t *testing.T) {
7272
assert.Equal(t, actualScopes[2].ScopeId(), expectDomainScopeId)
7373
}
7474

75+
func TestMakeScopesWithEmptyEntities(t *testing.T) {
76+
mockGitlabPlugin(t)
77+
78+
const connectionId = 1
79+
const gitlabProjectId = 37
80+
const expectDomainScopeId = "gitlab:GitlabProject:1:37"
81+
82+
actualScopes, err := makeScopeV200(
83+
connectionId,
84+
[]*srvhelper.ScopeDetail[models.GitlabProject, models.GitlabScopeConfig]{
85+
{
86+
Scope: models.GitlabProject{
87+
Scope: common.Scope{
88+
ConnectionId: connectionId,
89+
},
90+
GitlabId: gitlabProjectId,
91+
},
92+
ScopeConfig: &models.GitlabScopeConfig{
93+
ScopeConfig: common.ScopeConfig{
94+
Entities: []string{},
95+
},
96+
},
97+
},
98+
},
99+
)
100+
assert.Nil(t, err)
101+
// empty entities should default to all domain types, producing repo + cicd + board scopes
102+
assert.Equal(t, 3, len(actualScopes))
103+
assert.Equal(t, actualScopes[0].ScopeId(), expectDomainScopeId)
104+
}
105+
106+
func TestMakeScopesWithCrossEntity(t *testing.T) {
107+
mockGitlabPlugin(t)
108+
109+
const connectionId = 1
110+
const gitlabProjectId = 37
111+
const expectDomainScopeId = "gitlab:GitlabProject:1:37"
112+
113+
actualScopes, err := makeScopeV200(
114+
connectionId,
115+
[]*srvhelper.ScopeDetail[models.GitlabProject, models.GitlabScopeConfig]{
116+
{
117+
Scope: models.GitlabProject{
118+
Scope: common.Scope{
119+
ConnectionId: connectionId,
120+
},
121+
GitlabId: gitlabProjectId,
122+
},
123+
ScopeConfig: &models.GitlabScopeConfig{
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+
75139
func TestMakeDataSourcePipelinePlanV200(t *testing.T) {
76140
mockGitlabPlugin(t)
77141

backend/plugins/gitlab/api/blueprint_v200.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,14 @@ func makeScopeV200(
7878
gitlabProject, scopeConfig := scope.Scope, scope.ScopeConfig
7979
id := didgen.NewDomainIdGenerator(&models.GitlabProject{}).Generate(connectionId, gitlabProject.GitlabId)
8080

81+
// if no entities specified, use all entities enabled by default
82+
if len(scopeConfig.Entities) == 0 {
83+
scopeConfig.Entities = plugin.DOMAIN_TYPES
84+
}
85+
8186
if utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE_REVIEW) ||
82-
utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE) {
87+
utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE) ||
88+
utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CROSS) {
8389
// if we don't need to collect gitex, we need to add repo to scopes here
8490
scopeRepo := code.NewRepo(id, gitlabProject.PathWithNamespace)
8591

0 commit comments

Comments
 (0)