You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@devlake.apache.org by "Leniyou (via GitHub)" <gi...@apache.org> on 2024/08/05 19:00:18 UTC
[I] [Bug][Devlake] unexpected end of JSON when adding more than 31 repositories as data scope to Azure-DevOps Connection [incubator-devlake]
Leniyou opened a new issue, #7836:
URL: https://github.com/apache/incubator-devlake/issues/7836
### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/incubator-devlake/issues?q=is%3Aissue) and found no similar issues.
### What happened
Hi There!
Dear Team,
I am having this issue when trying to add more than 31 repositories as data scope to an Azure-DevOps Data Connection.
The error is this:
`level=error msg="HTTP 400 error\n\tcaused by: error patching the blueprint (400)\n\tWraps: (2)\n\tWraps: (3) unexpected end of JSON input\n\tWraps: (4) unexpected end of JSON input\n\tError types: (1) *hintdetail.withDetail (2) *hintdetail.withDetail (3) *hintdetail.withDetail (4) *json.SyntaxError"`

I have one project, that project has an Azure-DevOps Data Connection, that Data Connection has already 31 repositories added as data scope but when I tried to add one more repository, I got the error mentioned before.

### What do you expect to happen
The repository is added as data scope for an Azure-DevOps data connection.
### How to reproduce
Add more than 31 repositories as data scope to an Azure-DevOps Data Connection.
### Anything else
_No response_
### Version
v1.0.0
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
--
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: dev-unsubscribe@devlake.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug][Devlake] unexpected end of JSON when adding more than 31 repositories as data scope to Azure-DevOps Connection [incubator-devlake]
Posted by "klesh (via GitHub)" <gi...@apache.org>.
klesh commented on issue #7836:
URL: https://github.com/apache/incubator-devlake/issues/7836#issuecomment-2270528311
Please use the Go version plugin instead.
--
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: dev-unsubscribe@devlake.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug][Devlake] unexpected end of JSON when adding more than 31 repositories as data scope to Azure-DevOps Connection [incubator-devlake]
Posted by "klesh (via GitHub)" <gi...@apache.org>.
klesh closed issue #7836: [Bug][Devlake] unexpected end of JSON when adding more than 31 repositories as data scope to Azure-DevOps Connection
URL: https://github.com/apache/incubator-devlake/issues/7836
--
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: dev-unsubscribe@devlake.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug][Devlake] unexpected end of JSON when adding more than 31 repositories as data scope to Azure-DevOps Connection [incubator-devlake]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
dosubot[bot] commented on issue #7836:
URL: https://github.com/apache/incubator-devlake/issues/7836#issuecomment-2269724729
<!-- Greeting -->
@Leniyou Hello there! I'm a bot that can help you solve bugs, answer questions, and become a contributor. I'm here to assist you while waiting for a human maintainer.
<!-- Answer -->
To resolve the "unexpected end of JSON input" error when adding more than 31 repositories to an Azure-DevOps connection in DevLake, you need to ensure that the JSON response is correctly handled and paginated. The provided code snippets show how the repositories are fetched and processed, but they do not include pagination handling for the repositories.
You can modify the `listAzuredevopsRepos` function to handle pagination by adding support for the `ContinuationToken` or similar pagination mechanism provided by the Azure DevOps API. Here is an example of how you can modify the function to handle pagination:
```go
func listAzuredevopsRepos(
vsc azuredevops.Client,
orgId, projectId string,
) (
children []dsmodels.DsRemoteApiScopeListEntry[models.AzuredevopsRepo],
err errors.Error) {
args := azuredevops.GetRepositoriesArgs{
OrgId: orgId,
ProjectId: projectId,
}
var allRepos []azuredevops.Repository
for {
repos, continuationToken, err := vsc.GetRepositories(args)
if err != nil {
return nil, err
}
allRepos = append(allRepos, repos...)
if continuationToken == "" {
break
}
args.ContinuationToken = continuationToken
}
for _, v := range allRepos {
if v.IsDisabled {
continue
}
pID := orgId + idSeparator + projectId
repo := models.AzuredevopsRepo{
Id: v.Id,
Type: models.RepositoryTypeADO,
Name: v.Name,
Url: v.Url,
RemoteUrl: v.RemoteUrl,
IsFork: false,
}
repo.ProjectId = projectId
repo.OrganizationId = orgId
children = append(children, dsmodels.DsRemoteApiScopeListEntry[models.AzuredevopsRepo]{
Type: api.RAS_ENTRY_TYPE_SCOPE,
ParentId: &pID,
Id: v.Id,
Name: v.Name,
FullName: v.Name,
Data: &repo,
})
}
return
}
```
In this modified function, the `GetRepositories` method is assumed to return a `continuationToken` along with the repositories. The loop continues to fetch repositories until the `continuationToken` is empty, indicating that there are no more pages of repositories to fetch. This ensures that all repositories are retrieved and processed, avoiding the "unexpected end of JSON input" error.
The `GetRepositories` method in the `Client` struct should also be updated to handle pagination correctly. Here is an example of how you can implement it:
```go
func (c *Client) GetRepositories(args GetRepositoriesArgs) ([]Repository, string, errors.Error) {
query := url.Values{}
query.Set("api-version", apiVersion)
var data struct {
Repos []Repository `json:"value"`
}
path := fmt.Sprintf("%s/%s/_apis/git/repositories", args.OrgId, args.ProjectId)
res, err := c.apiClient.Get(path, query, nil)
if err != nil {
return nil, "", err
}
switch res.StatusCode {
case 401:
fallthrough
case 403:
return nil, "", errors.Unauthorized.New("failed to authorize the '.../_apis/git/repositories' request using the plugin connection")
case 404:
return nil, "", errors.NotFound.New("failed to find requested resource on '.../_apis/git/repositories'")
default:
}
err = api.UnmarshalResponse(res, &data)
if err != nil {
return nil, "", err
}
continuationToken := res.Header.Get("X-Ms-Continuationtoken")
return data.Repos, continuationToken, nil
}
```
This implementation ensures that the `GetRepositories` method returns a continuation token, which can be used to fetch the next page of repositories if available <sup>[[1]](https://github.com/apache/incubator-devlake/blob/main/backend/plugins/azuredevops_go/api/remote_helper.go)</sup><sup>[[2]](https://github.com/apache/incubator-devlake/blob/main/backend/plugins/azuredevops_go/api/azuredevops/client.go)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), 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: dev-unsubscribe@devlake.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org