You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by GitBox <gi...@apache.org> on 2022/06/30 09:28:37 UTC

[GitHub] [incubator-devlake] abeizn opened a new pull request, #2396: fix: gitlab users are not appeared in table.users

abeizn opened a new pull request, #2396:
URL: https://github.com/apache/incubator-devlake/pull/2396

   # Summary
   add gitlab user collector, extractor and convertor.
   update gitlab user model
   
   ### Does this close any open issues?
   related to #2126 
   
   ### Screenshots
   ![image](https://user-images.githubusercontent.com/101256042/176643060-2fc5bfb4-9238-44e3-827c-354b513a0d91.png)
   
   ### Other Information
   Any other information that is important to this PR.
   


-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh merged pull request #2396: fix: gitlab users are not appeared in table.users

Posted by GitBox <gi...@apache.org>.
klesh merged PR #2396:
URL: https://github.com/apache/incubator-devlake/pull/2396


-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] abeizn commented on a diff in pull request #2396: fix: gitlab users are not appeared in table.users

Posted by GitBox <gi...@apache.org>.
abeizn commented on code in PR #2396:
URL: https://github.com/apache/incubator-devlake/pull/2396#discussion_r912308621


##########
plugins/gitlab/tasks/user_extractor.go:
##########
@@ -0,0 +1,70 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+	"encoding/json"
+
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/gitlab/models"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+var ExtractUserMeta = core.SubTaskMeta{
+	Name:             "extractUsers",
+	EntryPoint:       ExtractUsers,
+	EnabledByDefault: true,
+	Description:      "Extract raw workspace data into tool layer table _tool_gitlab_users",
+}
+
+func ExtractUsers(taskCtx core.SubTaskContext) error {
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_USER_TABLE)
+
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: *rawDataSubTaskArgs,
+		Extract: func(row *helper.RawData) ([]interface{}, error) {
+			var userRes []models.GitlabUser
+			err := json.Unmarshal(row.Data, &userRes)
+			if err != nil {
+				return nil, err
+			}
+
+			results := make([]interface{}, 0)
+			for _, v := range userRes {

Review Comment:
   updated



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #2396: fix: gitlab users are not appeared in table.users

Posted by GitBox <gi...@apache.org>.
klesh commented on code in PR #2396:
URL: https://github.com/apache/incubator-devlake/pull/2396#discussion_r911580459


##########
plugins/gitlab/models/migrationscripts/archived/user.go:
##########
@@ -20,9 +20,16 @@ package archived
 import "github.com/apache/incubator-devlake/models/migrationscripts/archived"
 
 type GitlabUser struct {
-	ConnectionId uint64 `gorm:"primaryKey"`
-	Email        string `gorm:"primaryKey;type:varchar(255)"`
-	Name         string `gorm:"type:varchar(255)"`
+	ConnectionId    uint64 `gorm:"primaryKey"`
+	ProjectId       int    `gorm:"primaryKey"`

Review Comment:
   This should be a Many-to-Many relationship



##########
plugins/gitlab/models/user.go:
##########
@@ -17,12 +17,21 @@ limitations under the License.
 
 package models
 
-import "github.com/apache/incubator-devlake/models/common"
+import (
+	"github.com/apache/incubator-devlake/models/common"
+)
 
 type GitlabUser struct {
-	ConnectionId uint64 `gorm:"primaryKey"`
-	Email        string `gorm:"primaryKey;type:varchar(255)"`
-	Name         string `gorm:"type:varchar(255)"`
+	ConnectionId    uint64 `gorm:"primaryKey"`
+	ProjectId       int    `gorm:"primaryKey"`

Review Comment:
   Same as above



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] abeizn commented on a diff in pull request #2396: fix: gitlab users are not appeared in table.users

Posted by GitBox <gi...@apache.org>.
abeizn commented on code in PR #2396:
URL: https://github.com/apache/incubator-devlake/pull/2396#discussion_r911571173


##########
plugins/gitlab/tasks/user_collector.go:
##########
@@ -0,0 +1,72 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+	"encoding/json"
+	"net/http"
+	"net/url"
+
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+const RAW_USER_TABLE = "gitlab_api_users"
+
+var CollectUserMeta = core.SubTaskMeta{
+	Name:             "collectUsers",
+	EntryPoint:       CollectUsers,
+	EnabledByDefault: true,
+	Description:      "collect gitlab users",
+}
+
+func CollectUsers(taskCtx core.SubTaskContext) error {
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_USER_TABLE)
+	logger := taskCtx.GetLogger()
+	logger.Info("collect gitlab users")
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: *rawDataSubTaskArgs,
+		ApiClient:          data.ApiClient,
+		UrlTemplate:        "/projects/{{ .Params.ProjectId }}/members",

Review Comment:
   yes, I think everyone who is invited is an organizer, but the organizer determined by the company still needs to be determined by the company itself



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #2396: fix: gitlab users are not appeared in table.users

Posted by GitBox <gi...@apache.org>.
klesh commented on code in PR #2396:
URL: https://github.com/apache/incubator-devlake/pull/2396#discussion_r912019566


##########
plugins/gitlab/tasks/user_extractor.go:
##########
@@ -0,0 +1,70 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+	"encoding/json"
+
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/gitlab/models"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+var ExtractUserMeta = core.SubTaskMeta{
+	Name:             "extractUsers",
+	EntryPoint:       ExtractUsers,
+	EnabledByDefault: true,
+	Description:      "Extract raw workspace data into tool layer table _tool_gitlab_users",
+}
+
+func ExtractUsers(taskCtx core.SubTaskContext) error {
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_USER_TABLE)
+
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: *rawDataSubTaskArgs,
+		Extract: func(row *helper.RawData) ([]interface{}, error) {
+			var userRes []models.GitlabUser
+			err := json.Unmarshal(row.Data, &userRes)
+			if err != nil {
+				return nil, err
+			}
+
+			results := make([]interface{}, 0)
+			for _, v := range userRes {

Review Comment:
   We should be expecting a single User in this callback, not all Users



##########
plugins/gitlab/tasks/user_collector.go:
##########
@@ -0,0 +1,72 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+	"encoding/json"
+	"net/http"
+	"net/url"
+
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+const RAW_USER_TABLE = "gitlab_api_users"
+
+var CollectUserMeta = core.SubTaskMeta{
+	Name:             "collectUsers",
+	EntryPoint:       CollectUsers,
+	EnabledByDefault: true,
+	Description:      "collect gitlab users",
+}
+
+func CollectUsers(taskCtx core.SubTaskContext) error {
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_USER_TABLE)
+	logger := taskCtx.GetLogger()
+	logger.Info("collect gitlab users")
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: *rawDataSubTaskArgs,
+		ApiClient:          data.ApiClient,
+		UrlTemplate:        "/projects/{{ .Params.ProjectId }}/members/all",
+		//PageSize:           100,
+		Query: func(reqData *helper.RequestData) (url.Values, error) {
+			query := url.Values{}
+			// query.Set("sort", "asc")
+			// query.Set("page", fmt.Sprintf("%v", reqData.Pager.Page))
+			// query.Set("per_page", fmt.Sprintf("%v", reqData.Pager.Size))
+			return query, nil
+		},
+
+		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
+			var result json.RawMessage
+			err := helper.UnmarshalResponse(res, &result)
+			if err != nil {
+				return nil, err
+			}
+			return []json.RawMessage{result}, nil

Review Comment:
   This doesn't seem right, by convention, we store `items` of a `page`, not the raw response body.
   Even though it works in this particular case, it breaks the convention.



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #2396: fix: gitlab users are not appeared in table.users

Posted by GitBox <gi...@apache.org>.
likyh commented on code in PR #2396:
URL: https://github.com/apache/incubator-devlake/pull/2396#discussion_r911552576


##########
plugins/gitlab/tasks/user_collector.go:
##########
@@ -0,0 +1,72 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+	"encoding/json"
+	"net/http"
+	"net/url"
+
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+const RAW_USER_TABLE = "gitlab_api_users"
+
+var CollectUserMeta = core.SubTaskMeta{
+	Name:             "collectUsers",
+	EntryPoint:       CollectUsers,
+	EnabledByDefault: true,
+	Description:      "collect gitlab users",
+}
+
+func CollectUsers(taskCtx core.SubTaskContext) error {
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_USER_TABLE)
+	logger := taskCtx.GetLogger()
+	logger.Info("collect gitlab users")
+
+	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
+		RawDataSubTaskArgs: *rawDataSubTaskArgs,
+		ApiClient:          data.ApiClient,
+		UrlTemplate:        "/projects/{{ .Params.ProjectId }}/members",

Review Comment:
   Maybe users are not limited in members. Is this how it is planned?



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] abeizn commented on a diff in pull request #2396: fix: gitlab users are not appeared in table.users

Posted by GitBox <gi...@apache.org>.
abeizn commented on code in PR #2396:
URL: https://github.com/apache/incubator-devlake/pull/2396#discussion_r911594223


##########
plugins/gitlab/models/migrationscripts/archived/user.go:
##########
@@ -20,9 +20,16 @@ package archived
 import "github.com/apache/incubator-devlake/models/migrationscripts/archived"
 
 type GitlabUser struct {
-	ConnectionId uint64 `gorm:"primaryKey"`
-	Email        string `gorm:"primaryKey;type:varchar(255)"`
-	Name         string `gorm:"type:varchar(255)"`
+	ConnectionId    uint64 `gorm:"primaryKey"`
+	ProjectId       int    `gorm:"primaryKey"`

Review Comment:
   I don't understand very well, like jira, tapd and gitlab should all be unified, right? This definition structure should be able to achieve all cases



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org