You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2024/03/13 09:27:32 UTC

(incubator-devlake) branch fix-jira-timeafter updated: fix: jira epic add time after

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

abeizn pushed a commit to branch fix-jira-timeafter
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/fix-jira-timeafter by this push:
     new f6c2e84cf fix: jira epic add time after
f6c2e84cf is described below

commit f6c2e84cfceff4174bbe740182c2272fb9a072c2
Author: abeizn <zi...@merico.dev>
AuthorDate: Wed Mar 13 17:27:22 2024 +0800

    fix: jira epic add time after
---
 backend/plugins/jira/api/connection_api.go   |  4 ++--
 backend/plugins/jira/tasks/epic_collector.go | 36 ++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/backend/plugins/jira/api/connection_api.go b/backend/plugins/jira/api/connection_api.go
index c72d8cbba..df10db8af 100644
--- a/backend/plugins/jira/api/connection_api.go
+++ b/backend/plugins/jira/api/connection_api.go
@@ -71,7 +71,7 @@ func testConnection(ctx context.Context, connection models.JiraConn) (*JiraTestC
 		return nil, errors.NotFound.New(fmt.Sprintf("Seems like an invalid Endpoint URL, please try %s", restUrl.String()))
 	}
 	if res.StatusCode == http.StatusUnauthorized {
-		return nil, errors.HttpStatus(http.StatusBadRequest).New("Error username/password")
+		return nil, errors.HttpStatus(http.StatusBadRequest).New("Error credential")
 	}
 
 	resBody := &models.JiraServerInfo{}
@@ -100,7 +100,7 @@ func testConnection(ctx context.Context, connection models.JiraConn) (*JiraTestC
 
 	errMsg := ""
 	if res.StatusCode == http.StatusUnauthorized {
-		return nil, errors.HttpStatus(http.StatusBadRequest).New("Please check your username/password")
+		return nil, errors.HttpStatus(http.StatusBadRequest).New("Please check your credential")
 	}
 
 	if res.StatusCode != http.StatusOK {
diff --git a/backend/plugins/jira/tasks/epic_collector.go b/backend/plugins/jira/tasks/epic_collector.go
index 2404366bf..a2b88959b 100644
--- a/backend/plugins/jira/tasks/epic_collector.go
+++ b/backend/plugins/jira/tasks/epic_collector.go
@@ -49,6 +49,7 @@ var CollectEpicsMeta = plugin.SubTaskMeta{
 func CollectEpics(taskCtx plugin.SubTaskContext) errors.Error {
 	db := taskCtx.GetDal()
 	data := taskCtx.GetData().(*JiraTaskData)
+	logger := taskCtx.GetLogger()
 	batchSize := 100
 	if data.JiraServerInfo.DeploymentType == models.DeploymentServer && len(data.JiraServerInfo.VersionNumbers) == 3 && data.JiraServerInfo.VersionNumbers[0] <= 8 {
 		batchSize = 1
@@ -57,16 +58,31 @@ func CollectEpics(taskCtx plugin.SubTaskContext) errors.Error {
 	if err != nil {
 		return err
 	}
-	jql := "ORDER BY created ASC"
-	collector, err := api.NewApiCollector(api.ApiCollectorArgs{
-		RawDataSubTaskArgs: api.RawDataSubTaskArgs{
-			Ctx: taskCtx,
-			Params: JiraApiParams{
-				ConnectionId: data.Options.ConnectionId,
-				BoardId:      data.Options.BoardId,
-			},
-			Table: RAW_EPIC_TABLE,
+
+	collectorWithState, err := api.NewStatefulApiCollector(api.RawDataSubTaskArgs{
+		Ctx: taskCtx,
+		Params: JiraApiParams{
+			ConnectionId: data.Options.ConnectionId,
+			BoardId:      data.Options.BoardId,
 		},
+		Table: RAW_EPIC_TABLE,
+	})
+	if err != nil {
+		return err
+	}
+
+	loc, err := getTimeZone(taskCtx)
+	if err != nil {
+		logger.Info("failed to get timezone, err: %v", err)
+	} else {
+		logger.Info("got user's timezone: %v", loc.String())
+	}
+	jql := "ORDER BY created ASC"
+	if collectorWithState.Since != nil {
+		jql = "and " + buildJQL(*collectorWithState.Since, loc)
+	}
+
+	err = collectorWithState.InitCollector(api.ApiCollectorArgs{
 		ApiClient:   data.ApiClient,
 		PageSize:    100,
 		Incremental: false,
@@ -107,7 +123,7 @@ func CollectEpics(taskCtx plugin.SubTaskContext) errors.Error {
 	if err != nil {
 		return err
 	}
-	return collector.Execute()
+	return collectorWithState.Execute()
 }
 
 func GetEpicKeysIterator(db dal.Dal, data *JiraTaskData, batchSize int) (api.Iterator, errors.Error) {