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/16 16:35:55 UTC

[GitHub] [incubator-devlake] warren830 commented on a diff in pull request #2195: [Feature-1883][Plugin] Implement the gitee plugin

warren830 commented on code in PR #2195:
URL: https://github.com/apache/incubator-devlake/pull/2195#discussion_r899264355


##########
plugins/gitee/tasks/commit_extractor.go:
##########
@@ -0,0 +1,128 @@
+/*
+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/gitee/models"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+var ExtractCommitsMeta = core.SubTaskMeta{
+	Name:             "extractApiCommits",
+	EntryPoint:       ExtractApiCommits,
+	EnabledByDefault: true,
+	Description:      "Extract raw commit data into tool layer table GiteeCommit,GiteeUser and GiteeRepoCommit",
+}
+
+type GiteeCommit struct {
+	Author struct {
+		Date  helper.Iso8601Time `json:"date"`
+		Email string             `json:"email"`
+		Name  string             `json:"name"`
+	}
+	Committer struct {
+		Date  helper.Iso8601Time `json:"date"`
+		Email string             `json:"email"`
+		Name  string             `json:"name"`
+	}
+	Message string `json:"message"`
+}
+
+type GiteeApiCommitResponse struct {
+	Author      *models.GiteeUser `json:"author"`
+	AuthorId    int
+	CommentsUrl string            `json:"comments_url"`
+	Commit      GiteeCommit       `json:"commit"`
+	Committer   *models.GiteeUser `json:"committer"`
+	HtmlUrl     string            `json:"html_url"`
+	Sha         string            `json:"sha"`
+	Url         string            `json:"url"`
+}
+
+func ExtractApiCommits(taskCtx core.SubTaskContext) error {
+	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_COMMIT_TABLE)
+
+	extractor, err := helper.NewApiExtractor(helper.ApiExtractorArgs{
+		RawDataSubTaskArgs: *rawDataSubTaskArgs,
+		Extract: func(row *helper.RawData) ([]interface{}, error) {
+			results := make([]interface{}, 0, 4)
+
+			commit := &GiteeApiCommitResponse{}
+
+			err := json.Unmarshal(row.Data, commit)
+
+			if err != nil {
+				return nil, err
+			}
+
+			if commit.Sha == "" {
+				return nil, nil
+			}
+
+			giteeCommit, err := ConvertCommit(commit)
+
+			if err != nil {
+				return nil, err
+			}
+
+			if commit.Author != nil {
+				giteeCommit.AuthorId = commit.Author.Id
+				results = append(results, commit.Author)
+			}
+			if commit.Committer != nil {
+				giteeCommit.CommitterId = commit.Committer.Id
+				results = append(results, commit.Committer)
+
+			}
+
+			giteeRepoCommit := &models.GiteeRepoCommit{
+				RepoId:    data.Repo.GiteeId,
+				CommitSha: commit.Sha,
+			}
+			results = append(results, giteeCommit)
+			results = append(results, giteeRepoCommit)
+			return results, nil
+		},
+	})
+
+	if err != nil {
+		return err
+	}
+
+	return extractor.Execute()
+}
+
+// ConvertCommit Convert the API response to our DB model instance
+func ConvertCommit(commit *GiteeApiCommitResponse) (*models.GiteeCommit, error) {
+	giteeCommit := &models.GiteeCommit{
+		Sha:            commit.Sha,
+		AuthorId:       commit.Author.Id,

Review Comment:
   I tried to run all tasks locally, but I got the following error:
   <img width="613" alt="image" src="https://user-images.githubusercontent.com/39366025/174115994-62a531b5-bcd0-4550-8b05-2577d99a616b.png">
   I think this is the root clause, commit.Author might be nil



##########
plugins/gitee/tasks/pr_review_collector.go:
##########
@@ -0,0 +1,89 @@
+/*
+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"
+	"fmt"
+	"net/http"
+	"net/url"
+	"reflect"
+
+	"github.com/apache/incubator-devlake/plugins/helper"
+
+	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/gitee/models"
+)
+
+const RAW_PULL_REQUEST_REVIEW_TABLE = "gitee_api_pull_request_reviews"
+
+var CollectApiPullRequestReviewsMeta = core.SubTaskMeta{
+	Name:             "collectApiPullRequestReviews",
+	EntryPoint:       CollectApiPullRequestReviews,
+	EnabledByDefault: true,
+	Description:      "Collect PullRequestReviews data from Gitee api",
+}
+
+func CollectApiPullRequestReviews(taskCtx core.SubTaskContext) error {
+	db := taskCtx.GetDb()

Review Comment:
   got `not found project` error when collecting pr_review
   <img width="1273" alt="image" src="https://user-images.githubusercontent.com/39366025/174118605-f1fbe624-8334-4df2-b455-971a56c2de53.png">
   



-- 
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