You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by wa...@apache.org on 2022/09/11 05:32:05 UTC

[incubator-devlake] branch feat-plugin-gitea updated: fix(gitea): modify some minor issues

This is an automated email from the ASF dual-hosted git repository.

warren pushed a commit to branch feat-plugin-gitea
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/feat-plugin-gitea by this push:
     new 0444d9dd fix(gitea): modify some minor issues
0444d9dd is described below

commit 0444d9dd215e830ee6fe900dbfe935eece8cdecd
Author: Yingchu Chen <yi...@merico.dev>
AuthorDate: Sun Sep 11 13:30:37 2022 +0800

    fix(gitea): modify some minor issues
    
    relate to #2992
---
 plugins/gitea/tasks/commit_collector.go        |  1 +
 plugins/gitea/tasks/issue_comment_collector.go |  5 ++++-
 plugins/gitea/tasks/repo_collector.go          |  1 +
 plugins/gitea/tasks/shared.go                  | 12 ++++--------
 plugins/github/tasks/comment_extractor.go      |  3 +--
 plugins/github/tasks/shared.go                 |  3 +--
 plugins/{github/utils => helper}/utils.go      |  2 +-
 plugins/{github/utils => helper}/utils_test.go |  2 +-
 8 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/plugins/gitea/tasks/commit_collector.go b/plugins/gitea/tasks/commit_collector.go
index d15d9d72..9d4a33f4 100644
--- a/plugins/gitea/tasks/commit_collector.go
+++ b/plugins/gitea/tasks/commit_collector.go
@@ -78,6 +78,7 @@ func CollectApiCommits(taskCtx core.SubTaskContext) error {
 			query.Set("limit", strconv.Itoa(reqData.Pager.Size))
 			return query, nil
 		},
+		GetTotalPages:  GetTotalPagesFromResponse,
 		ResponseParser: GetRawMessageFromResponse,
 	})
 
diff --git a/plugins/gitea/tasks/issue_comment_collector.go b/plugins/gitea/tasks/issue_comment_collector.go
index 535fe7e8..125a68be 100644
--- a/plugins/gitea/tasks/issue_comment_collector.go
+++ b/plugins/gitea/tasks/issue_comment_collector.go
@@ -60,7 +60,10 @@ func CollectApiIssueComments(taskCtx core.SubTaskContext) error {
 		if err != nil {
 			return fmt.Errorf("failed to get latest gitea issue record: %w", err)
 		}
-
+		if latestUpdatedIssueComment.IssueId != 0 {
+			since = &latestUpdatedIssueComment.GiteaUpdatedAt
+			incremental = true
+		}
 	}
 
 	collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
diff --git a/plugins/gitea/tasks/repo_collector.go b/plugins/gitea/tasks/repo_collector.go
index f1f438c7..685e02a9 100644
--- a/plugins/gitea/tasks/repo_collector.go
+++ b/plugins/gitea/tasks/repo_collector.go
@@ -54,6 +54,7 @@ func CollectApiRepositories(taskCtx core.SubTaskContext) error {
 			query.Set("limit", fmt.Sprintf("%v", reqData.Pager.Size))
 			return query, nil
 		},
+		GetTotalPages: GetTotalPagesFromResponse,
 		ResponseParser: func(res *http.Response) ([]json.RawMessage, error) {
 			body, err := ioutil.ReadAll(res.Body)
 			res.Body.Close()
diff --git a/plugins/gitea/tasks/shared.go b/plugins/gitea/tasks/shared.go
index 2d2d17e0..834a86a7 100644
--- a/plugins/gitea/tasks/shared.go
+++ b/plugins/gitea/tasks/shared.go
@@ -22,7 +22,6 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/http"
-	"strconv"
 	"time"
 
 	"github.com/apache/incubator-devlake/plugins/core"
@@ -55,15 +54,12 @@ type GiteaInput struct {
 }
 
 func GetTotalPagesFromResponse(res *http.Response, args *helper.ApiCollectorArgs) (int, error) {
-	total := res.Header.Get("X-PageCount")
-	if total == "" {
-		return 0, nil
-	}
-	totalInt, err := strconv.Atoi(total)
+	link := res.Header.Get("link")
+	pageInfo, err := helper.GetPagingFromLinkHeader(link)
 	if err != nil {
-		return 0, err
+		return 0, nil
 	}
-	return totalInt, nil
+	return pageInfo.Last, nil
 }
 
 func GetRawMessageFromResponse(res *http.Response) ([]json.RawMessage, error) {
diff --git a/plugins/github/tasks/comment_extractor.go b/plugins/github/tasks/comment_extractor.go
index d87f4135..369e6c86 100644
--- a/plugins/github/tasks/comment_extractor.go
+++ b/plugins/github/tasks/comment_extractor.go
@@ -25,7 +25,6 @@ import (
 
 	"github.com/apache/incubator-devlake/plugins/core"
 	"github.com/apache/incubator-devlake/plugins/github/models"
-	githubUtils "github.com/apache/incubator-devlake/plugins/github/utils"
 	"github.com/apache/incubator-devlake/plugins/helper"
 )
 
@@ -72,7 +71,7 @@ func ExtractApiComments(taskCtx core.SubTaskContext) error {
 				return nil, nil
 			}
 			//If this is a pr, ignore
-			issueINumber, err := githubUtils.GetIssueIdByIssueUrl(apiComment.IssueUrl)
+			issueINumber, err := helper.GetIssueIdByIssueUrl(apiComment.IssueUrl)
 			if err != nil {
 				return nil, err
 			}
diff --git a/plugins/github/tasks/shared.go b/plugins/github/tasks/shared.go
index b7d27c57..4e221670 100644
--- a/plugins/github/tasks/shared.go
+++ b/plugins/github/tasks/shared.go
@@ -18,7 +18,6 @@ limitations under the License.
 package tasks
 
 import (
-	"github.com/apache/incubator-devlake/plugins/github/utils"
 	"net/http"
 
 	"github.com/apache/incubator-devlake/plugins/helper"
@@ -26,7 +25,7 @@ import (
 
 func GetTotalPagesFromResponse(res *http.Response, args *helper.ApiCollectorArgs) (int, error) {
 	link := res.Header.Get("link")
-	pageInfo, err := utils.GetPagingFromLinkHeader(link)
+	pageInfo, err := helper.GetPagingFromLinkHeader(link)
 	if err != nil {
 		return 0, nil
 	}
diff --git a/plugins/github/utils/utils.go b/plugins/helper/utils.go
similarity index 99%
rename from plugins/github/utils/utils.go
rename to plugins/helper/utils.go
index 59366c0f..c81f1855 100644
--- a/plugins/github/utils/utils.go
+++ b/plugins/helper/utils.go
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package utils
+package helper
 
 import (
 	//"errors"
diff --git a/plugins/github/utils/utils_test.go b/plugins/helper/utils_test.go
similarity index 99%
rename from plugins/github/utils/utils_test.go
rename to plugins/helper/utils_test.go
index 891e97d7..d1d39294 100644
--- a/plugins/github/utils/utils_test.go
+++ b/plugins/helper/utils_test.go
@@ -17,7 +17,7 @@ limitations under the License.
 
 // https://golang.org/doc/tutorial/add-a-test
 
-package utils
+package helper
 
 import (
 	"fmt"