From 8e024ce8fa1ddb438bb87ad5f4cb1b3ac8deb585 Mon Sep 17 00:00:00 2001 From: abeizn Date: Wed, 13 Mar 2024 17:54:53 +0800 Subject: [PATCH] fix: jira epic add time after (#7161) * fix: jira epic add time after * fix: description --- backend/plugins/jira/api/connection_api.go | 4 +-- backend/plugins/jira/tasks/epic_collector.go | 38 ++++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/backend/plugins/jira/api/connection_api.go b/backend/plugins/jira/api/connection_api.go index c72d8cbbab6..df10db8afe0 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 2404366bf3b..25cbd3998c9 100644 --- a/backend/plugins/jira/tasks/epic_collector.go +++ b/backend/plugins/jira/tasks/epic_collector.go @@ -42,13 +42,14 @@ var CollectEpicsMeta = plugin.SubTaskMeta{ Name: "collectEpics", EntryPoint: CollectEpics, EnabledByDefault: true, - Description: "collect Jira epics from all boards, does not support either timeFilter or diffSync.", + Description: "collect Jira epics from all boards, supports both timeFilter and diffSync.", DomainTypes: []string{plugin.DOMAIN_TYPE_TICKET, plugin.DOMAIN_TYPE_CROSS}, } 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) {