dosubot[bot] commented on issue #7504:
URL:
https://github.com/apache/incubator-devlake/issues/7504#issuecomment-2128294586
<!-- Answer -->
To resolve the 400 error when adding an Azure DevOps scope to an existing
project with a GitHub connection, you need to ensure that the scope details and
connection information are correctly mapped and validated. The error message
indicates that the argument list is too long, which suggests that the payload
size might be an issue.
Here are some steps to address this:
1. **Batch Processing**: Modify the `PutScopes` function to handle payloads
in smaller batches to prevent the "argument list too long" error. Here is an
example of how you might adjust the function:
```go
func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig])
PutScopes(input *plugin.ApiResourceInput, scopes []*Scope) ([]*ScopeRes[Scope,
ScopeConfig], errors.Error) {
params, err := gs.extractFromReqParam(input, false)
if err != nil {
return nil, err
}
err = gs.dbHelper.VerifyConnection(params.connectionId)
if err != nil {
return nil, errors.Default.Wrap(err, fmt.Sprintf("error
verifying connection for connection ID %d", params.connectionId))
}
if len(scopes) == 0 {
return nil, nil
}
err = gs.validatePrimaryKeys(scopes)
if err != nil {
return nil, err
}
now := time.Now()
batchSize := 100 // Adjust the batch size as needed
for i := 0; i < len(scopes); i += batchSize {
end := i + batchSize
if end > len(scopes) {
end = len(scopes)
}
batch := scopes[i:end]
for _, scope := range batch {
gs.setScopeFields(scope, params.connectionId, &now, &now)
err = gs.verifyScope(scope, gs.validator)
if err != nil {
return nil, errors.Default.Wrap(err, "error verifying
scope")
}
}
gs.setRawDataOrigin(batch...)
err = gs.dbHelper.SaveScope(batch)
if err != nil {
return nil, errors.Default.Wrap(err, "error saving scope")
}
}
apiScopes, err := gs.addScopeConfig(scopes...)
if err != nil {
return nil, errors.Default.Wrap(err, "error associating scope
config to scope")
}
return apiScopes, nil
}
```
2. **Scope Mapping**: Ensure that the `MapScopeDetails` function correctly
maps the scope details for both Azure DevOps and GitHub. This function
differentiates between scope details by checking the repository type and
processing them accordingly.
```go
for _, scope := range scopeDetails {
azuredevopsRepo, scopeConfig := scope.Scope, scope.ScopeConfig
if azuredevopsRepo.Type != models.RepositoryTypeADO {
continue
}
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) {
scopeRepo := code.NewRepo(id, azuredevopsRepo.Name)
sc = append(sc, scopeRepo)
}
if utils.StringsContains(scopeConfig.Entities,
plugin.DOMAIN_TYPE_CICD) {
scopeCICD := devops.NewCicdScope(id, azuredevopsRepo.Name)
sc = append(sc, scopeCICD)
}
if utils.StringsContains(scopeConfig.Entities,
plugin.DOMAIN_TYPE_TICKET) {
scopeTicket := ticket.NewBoard(id, azuredevopsRepo.Name)
sc = append(sc, scopeTicket)
}
}
for _, scope := range scopeDetails {
azuredevopsRepo, scopeConfig := scope.Scope, scope.ScopeConfig
if azuredevopsRepo.Type == models.RepositoryTypeADO {
continue
}
id :=
didgen.NewDomainIdGenerator(&models.AzuredevopsRepo{}).Generate(connectionId,
azuredevopsRepo.Id)
if utils.StringsContains(scopeConfig.Entities,
plugin.DOMAIN_TYPE_CICD) {
scopeCICD := devops.NewCicdScope(id, azuredevopsRepo.Name)
sc = append(sc, scopeCICD)
}
if !azuredevopsRepo.IsPrivate &&
utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_CODE) {
scopeRepo := code.NewRepo(id, azuredevopsRepo.Name)
sc = append(sc, scopeRepo)
}
}
```
3. **Validation**: Ensure that the `PutScopes` function includes validation
checks to verify the scope details and prevent oversized payloads.
By implementing these changes, you should be able to resolve the 400 error
and successfully add Azure DevOps scopes to an existing project with a GitHub
connection
<sup>[[1]](https://github.com/apache/incubator-devlake/blob/main/backend/helpers/pluginhelper/api/scope_generic_helper.go)</sup><sup>[[2]](https://github.com/apache/incubator-devlake/blob/main/backend/helpers/srvhelper/scope_service_helper.go)</sup>.
<!-- Dosu Comment Footer -->
<details>
<summary>
#### Details
</summary>
**About Dosu**
This response is meant to be useful and save you time. It is **not meant to
be a precise solution**, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is
irrelevant.
</details>
*To continue the conversation, mention @dosu.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]