This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 7a1d7014e fix: improve the response for the remote api (#5446)
7a1d7014e is described below
commit 7a1d7014e3591548c6c451155a9957674a68f0f2
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jun 13 09:23:44 2023 +0800
fix: improve the response for the remote api (#5446)
* fix: remote api for github
* fix: e2e test
---
backend/plugins/github/api/remote.go | 19 ++++-----
.../github/e2e/raw_tables/_tool_github_repos.csv | 4 +-
.../{register.go => 20230612_add_fullName.go} | 45 +++++++++++-----------
.../github/models/migrationscripts/register.go | 1 +
backend/plugins/github/models/repo.go | 1 +
backend/plugins/github/tasks/repo_convertor.go | 6 +--
6 files changed, 38 insertions(+), 38 deletions(-)
diff --git a/backend/plugins/github/api/remote.go
b/backend/plugins/github/api/remote.go
index 714b1b500..5a6fbbf47 100644
--- a/backend/plugins/github/api/remote.go
+++ b/backend/plugins/github/api/remote.go
@@ -168,7 +168,8 @@ type repo struct {
func (r repo) ConvertApiScope() plugin.ToolLayerScope {
githubRepository := &models.GithubRepo{
GithubId: r.ID,
- Name: r.FullName,
+ Name: r.Name,
+ FullName: r.FullName,
HTMLUrl: r.HTMLURL,
Description: r.Description,
OwnerId: r.Owner.ID,
@@ -214,22 +215,18 @@ func RemoteScopes(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, er
return resBody, err
},
func(basicRes context2.BasicRes, gid string, queryData
*api.RemoteQueryData, connection models.GithubConnection) ([]repo,
errors.Error) {
+ if gid == "" {
+ return nil, nil
+ }
apiClient, err :=
api.NewApiClientFromConnection(context.TODO(), basicRes, &connection)
if err != nil {
return nil, errors.BadInput.Wrap(err, "failed
to get create apiClient")
}
query := initialQuery(queryData)
var res *http.Response
- if gid == "" {
- res, err = apiClient.Get("user/repos", query,
nil)
- if err != nil {
- return nil, err
- }
- } else {
- res, err =
apiClient.Get(fmt.Sprintf("orgs/%s/repos", gid), query, nil)
- if err != nil {
- return nil, err
- }
+ res, err = apiClient.Get(fmt.Sprintf("orgs/%s/repos",
gid), query, nil)
+ if err != nil {
+ return nil, err
}
var resBody []repo
err = api.UnmarshalResponse(res, &resBody)
diff --git a/backend/plugins/github/e2e/raw_tables/_tool_github_repos.csv
b/backend/plugins/github/e2e/raw_tables/_tool_github_repos.csv
index e5da5db87..10c585c58 100644
--- a/backend/plugins/github/e2e/raw_tables/_tool_github_repos.csv
+++ b/backend/plugins/github/e2e/raw_tables/_tool_github_repos.csv
@@ -1,2 +1,2 @@
-connection_id,github_id,name,html_url,description,owner_id,language,created_date,updated_date,_raw_data_params,_raw_data_table,_raw_data_id,_raw_data_remark
-1,134018330,panjf2000/ants,https://github.com/panjf2000/ants,"🐜🐜🐜 ants is a
high-performance and low-cost goroutine pool in Go, inspired by fasthttp./ ants
chinese goroutine chinese
。",7496278,Go,2018-05-19T01:13:38.000+00:00,2022-06-13T15:27:54.000+00:00,"{""ConnectionId"":1,""Name"":""panjf2000/ants""}",_raw_github_api_repositories,7,
+connection_id,github_id,name,full_name,html_url,description,owner_id,language,created_date,updated_date,_raw_data_params,_raw_data_table,_raw_data_id,_raw_data_remark
+1,134018330,ants,panjf2000/ants,https://github.com/panjf2000/ants,"🐜🐜🐜 ants is
a high-performance and low-cost goroutine pool in Go, inspired by fasthttp./
ants chinese goroutine chinese
。",7496278,Go,2018-05-19T01:13:38.000+00:00,2022-06-13T15:27:54.000+00:00,"{""ConnectionId"":1,""Name"":""panjf2000/ants""}",_raw_github_api_repositories,7,
diff --git a/backend/plugins/github/models/migrationscripts/register.go
b/backend/plugins/github/models/migrationscripts/20230612_add_fullName.go
similarity index 53%
copy from backend/plugins/github/models/migrationscripts/register.go
copy to backend/plugins/github/models/migrationscripts/20230612_add_fullName.go
index 676471cf3..447c1537c 100644
--- a/backend/plugins/github/models/migrationscripts/register.go
+++ b/backend/plugins/github/models/migrationscripts/20230612_add_fullName.go
@@ -18,28 +18,29 @@ limitations under the License.
package migrationscripts
import (
- "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/core/context"
+ "github.com/apache/incubator-devlake/core/errors"
)
-// All return all the migration scripts
-func All() []plugin.MigrationScript {
- return []plugin.MigrationScript{
- new(addInitTables),
- new(addGithubRunsTable),
- new(addGithubJobsTable),
- new(addGithubPipelineTable),
- new(deleteGithubPipelineTable),
- new(addHeadRepoIdFieldInGithubPr),
- new(addEnableGraphqlForConnection),
- new(addTransformationRule20221124),
- new(concatOwnerAndName),
- new(addStdTypeToIssue221230),
- new(addConnectionIdToTransformationRule),
- new(addEnvToRunAndJob),
- new(addGithubCommitAuthorInfo),
- new(fixRunNameToText),
- new(addGithubMultiAuth),
- new(renameTr2ScopeConfig),
- new(addGithubIssueAssignee),
- }
+type githubRepo20230612 struct {
+ FullName string `gorm:"type:varchar(255)"`
+}
+
+func (githubRepo20230612) TableName() string {
+ return "_tool_github_repos"
+}
+
+type addFullName struct{}
+
+func (*addFullName) Up(res context.BasicRes) errors.Error {
+ db := res.GetDal()
+ return db.AutoMigrate(&githubRepo20230612{})
+}
+
+func (*addFullName) Version() uint64 {
+ return 20230612184110
+}
+
+func (*addFullName) Name() string {
+ return "add full_name to _tool_github_repos"
}
diff --git a/backend/plugins/github/models/migrationscripts/register.go
b/backend/plugins/github/models/migrationscripts/register.go
index 676471cf3..cb216fad1 100644
--- a/backend/plugins/github/models/migrationscripts/register.go
+++ b/backend/plugins/github/models/migrationscripts/register.go
@@ -41,5 +41,6 @@ func All() []plugin.MigrationScript {
new(addGithubMultiAuth),
new(renameTr2ScopeConfig),
new(addGithubIssueAssignee),
+ new(addFullName),
}
}
diff --git a/backend/plugins/github/models/repo.go
b/backend/plugins/github/models/repo.go
index b320a5bb2..a865e9d5b 100644
--- a/backend/plugins/github/models/repo.go
+++ b/backend/plugins/github/models/repo.go
@@ -31,6 +31,7 @@ type GithubRepo struct {
ConnectionId uint64 `json:"connectionId" gorm:"primaryKey"
validate:"required" mapstructure:"connectionId,omitempty"`
GithubId int `json:"githubId" gorm:"primaryKey"
validate:"required" mapstructure:"githubId"`
Name string `json:"name" gorm:"type:varchar(255)"
mapstructure:"name,omitempty"`
+ FullName string `json:"fullName" gorm:"type:varchar(255)"
mapstructure:"fullName,omitempty"`
HTMLUrl string `json:"HTMLUrl" gorm:"type:varchar(255)"
mapstructure:"HTMLUrl,omitempty"`
Description string `json:"description"
mapstructure:"description,omitempty"`
ScopeConfigId uint64 `json:"scopeConfigId,omitempty"
mapstructure:"scopeConfigId,omitempty"`
diff --git a/backend/plugins/github/tasks/repo_convertor.go
b/backend/plugins/github/tasks/repo_convertor.go
index c25e16519..418ef7a00 100644
--- a/backend/plugins/github/tasks/repo_convertor.go
+++ b/backend/plugins/github/tasks/repo_convertor.go
@@ -93,7 +93,7 @@ func ConvertRepo(taskCtx plugin.SubTaskContext) errors.Error {
DomainEntity: domainlayer.DomainEntity{
Id:
repoIdGen.Generate(data.Options.ConnectionId, repository.GithubId),
},
- Name: repository.Name,
+ Name: repository.FullName,
Url: repository.HTMLUrl,
Description: repository.Description,
ForkedFrom: repository.ParentHTMLUrl,
@@ -105,7 +105,7 @@ func ConvertRepo(taskCtx plugin.SubTaskContext)
errors.Error {
DomainEntity: domainlayer.DomainEntity{
Id:
repoIdGen.Generate(data.Options.ConnectionId, repository.GithubId),
},
- Name: repository.Name,
+ Name: repository.FullName,
Url: fmt.Sprintf("%s/%s",
repository.HTMLUrl, "issues"),
Description: repository.Description,
CreatedDate: repository.CreatedDate,
@@ -120,7 +120,7 @@ func ConvertRepo(taskCtx plugin.SubTaskContext)
errors.Error {
DomainEntity: domainlayer.DomainEntity{
Id:
repoIdGen.Generate(data.Options.ConnectionId, repository.GithubId),
},
- Name: repository.Name,
+ Name: repository.FullName,
Url: repository.HTMLUrl,
Description: repository.Description,
CreatedDate: repository.CreatedDate,