Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid panic #8011

Merged
merged 18 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/plugins/ae/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func (p AE) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/azuredevops_go/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ func (p Azuredevops) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/bamboo/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ func (p Bamboo) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/bitbucket/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ func (p Bitbucket) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion backend/plugins/bitbucket_server/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ func (p BitbucketServer) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion backend/plugins/circleci/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ func (p Circleci) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/feishu/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func (p Feishu) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/gitee/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ func (p Gitee) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
39 changes: 24 additions & 15 deletions backend/plugins/gitlab/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,14 @@ func (p Gitlab) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]i
return nil, errors.BadInput.Wrap(err, "connection not found")
}

apiClient, err := tasks.NewGitlabApiClient(taskCtx, connection)
if err != nil {
return nil, err
var apiClient *helper.ApiAsyncClient
syncPolicy := taskCtx.SyncPolicy()
if syncPolicy != nil && !syncPolicy.SkipCollectors {
newApiClient, err := tasks.NewGitlabApiClient(taskCtx, connection)
if err != nil {
return nil, err
}
apiClient = newApiClient
}
if op.ProjectId != 0 {
var scope *models.GitlabProject
Expand All @@ -163,17 +168,19 @@ func (p Gitlab) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]i
}
}
if err != nil && db.IsErrorNotFound(err) {
var project *models.GitlabApiProject
project, err = api.GetApiProject(op, apiClient)
if err != nil {
return nil, err
}
logger.Debug(fmt.Sprintf("Current project: %d", project.GitlabId))
scope := project.ConvertApiScope()
scope.ConnectionId = op.ConnectionId
err = taskCtx.GetDal().CreateIfNotExist(scope)
if err != nil {
return nil, err
if apiClient != nil {
var project *models.GitlabApiProject
project, err = api.GetApiProject(op, apiClient)
if err != nil {
return nil, err
}
logger.Debug(fmt.Sprintf("Current project: %d", project.GitlabId))
scope := project.ConvertApiScope()
scope.ConnectionId = op.ConnectionId
err = taskCtx.GetDal().CreateIfNotExist(scope)
if err != nil {
return nil, err
}
}
}
if err != nil {
Expand Down Expand Up @@ -284,6 +291,8 @@ func (p Gitlab) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
17 changes: 10 additions & 7 deletions backend/plugins/gitlab/tasks/account_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ package tasks

import (
"encoding/json"
"strings"

"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/gitlab/models"
"strings"
)

func init() {
Expand All @@ -44,7 +43,7 @@ func ExtractAccounts(taskCtx plugin.SubTaskContext) errors.Error {
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_USER_TABLE)

// Do not extract createdUserAt if we are not using /users API
var skipCreatedUserAt = strings.HasPrefix(data.ApiClient.GetEndpoint(), "https://gitlab.com")
//var skipCreatedUserAt = strings.HasPrefix(data.ApiClient.GetEndpoint(), "https://gitlab.com")

extractor, err := api.NewApiExtractor(api.ApiExtractorArgs{
RawDataSubTaskArgs: *rawDataSubTaskArgs,
Expand All @@ -55,10 +54,14 @@ func ExtractAccounts(taskCtx plugin.SubTaskContext) errors.Error {
return nil, err
}

// Do not extract createdUserAt if we are not using /users API
// Why? I don't know, just refact this code, make it doesn't need api client.
var skipCreatedUserAt = strings.HasPrefix(row.Url, "https://gitlab.com")

results := make([]interface{}, 0)
var GitlabAccount *models.GitlabAccount
var gitlabAccount *models.GitlabAccount
if skipCreatedUserAt {
GitlabAccount = &models.GitlabAccount{
gitlabAccount = &models.GitlabAccount{
ConnectionId: data.Options.ConnectionId,
GitlabId: userRes.GitlabId,
Username: userRes.Username,
Expand All @@ -70,7 +73,7 @@ func ExtractAccounts(taskCtx plugin.SubTaskContext) errors.Error {
Email: userRes.Email,
}
} else {
GitlabAccount = &models.GitlabAccount{
gitlabAccount = &models.GitlabAccount{
ConnectionId: data.Options.ConnectionId,
GitlabId: userRes.GitlabId,
Username: userRes.Username,
Expand All @@ -84,7 +87,7 @@ func ExtractAccounts(taskCtx plugin.SubTaskContext) errors.Error {
}
}

results = append(results, GitlabAccount)
results = append(results, gitlabAccount)

return results, nil
},
Expand Down
4 changes: 3 additions & 1 deletion backend/plugins/icla/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func (p Icla) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/jenkins/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ func (p Jenkins) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion backend/plugins/jira/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ func (p Jira) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/slack/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ func (p Slack) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/sonarqube/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func (p Sonarqube) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/tapd/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ func (p Tapd) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/teambition/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ func (p Teambition) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/trello/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ func (p Trello) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
4 changes: 3 additions & 1 deletion backend/plugins/zentao/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ func (p Zentao) Close(taskCtx plugin.TaskContext) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("GetData failed when try to close %+v", taskCtx))
}
data.ApiClient.Release()
if data != nil && data.ApiClient != nil {
data.ApiClient.Release()
}
return nil
}
Loading