Skip to content

Commit

Permalink
revert 'removed start_date from spec'
Browse files Browse the repository at this point in the history
  • Loading branch information
darynaishchenko committed Sep 20, 2023
1 parent 26bc0c4 commit 0cc07fb
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 28 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-jira/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.8.0
LABEL io.airbyte.version=0.7.1
LABEL io.airbyte.name=airbyte/source-jira
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-jira/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 68e63de2-bb83-4c7e-93fa-a8a9051e3993
dockerImageTag: 0.8.0
dockerImageTag: 0.7.1
maxSecondsBetweenMessages: 21600
dockerRepository: airbyte/source-jira
githubIssueLabel: source-jira
Expand Down
28 changes: 18 additions & 10 deletions airbyte-integrations/connectors/source-jira/source_jira/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from typing import Any, List, Mapping, Optional, Tuple

import pendulum
import requests
from airbyte_cdk import AirbyteLogger
from airbyte_cdk.models import FailureType
Expand Down Expand Up @@ -73,6 +74,10 @@

class SourceJira(AbstractSource):
def _validate_and_transform(self, config: Mapping[str, Any]):
start_date = config.get("start_date")
if start_date:
config["start_date"] = pendulum.parse(start_date)

config["projects"] = config.get("projects", [])
return config

Expand Down Expand Up @@ -113,39 +118,42 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
config = self._validate_and_transform(config)
authenticator = self.get_authenticator(config)
args = {"authenticator": authenticator, "domain": config["domain"], "projects": config["projects"]}
issues_stream = Issues(**args, expand_fields=config.get("issues_stream_expand_with", []))
incremental_args = {**args, "start_date": config.get("start_date")}
issues_stream = Issues(**incremental_args, expand_fields=config.get("issues_stream_expand_with", []))
issue_fields_stream = IssueFields(**args)
experimental_streams = []
if config.get("enable_experimental_streams", False):
experimental_streams.append(PullRequests(issues_stream=issues_stream, issue_fields_stream=issue_fields_stream, **args))
experimental_streams.append(
PullRequests(issues_stream=issues_stream, issue_fields_stream=issue_fields_stream, **incremental_args)
)
return [
ApplicationRoles(**args),
Avatars(**args),
Boards(**args),
BoardIssues(**args),
BoardIssues(**incremental_args),
Dashboards(**args),
Filters(**args),
FilterSharing(**args),
Groups(**args),
issues_stream,
IssueComments(**args),
IssueComments(**incremental_args),
issue_fields_stream,
IssueFieldConfigurations(**args),
IssueCustomFieldContexts(**args),
IssueLinkTypes(**args),
IssueNavigatorSettings(**args),
IssueNotificationSchemes(**args),
IssuePriorities(**args),
IssueProperties(**args),
IssueRemoteLinks(**args),
IssueProperties(**incremental_args),
IssueRemoteLinks(**incremental_args),
IssueResolutions(**args),
IssueSecuritySchemes(**args),
IssueTransitions(**args),
IssueTypeSchemes(**args),
IssueTypeScreenSchemes(**args),
IssueVotes(**args),
IssueWatchers(**args),
IssueWorklogs(**args),
IssueVotes(**incremental_args),
IssueWatchers(**incremental_args),
IssueWorklogs(**incremental_args),
JiraSettings(**args),
Labels(**args),
Permissions(**args),
Expand All @@ -163,7 +171,7 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
ScreenTabFields(**args),
ScreenSchemes(**args),
Sprints(**args),
SprintIssues(**args),
SprintIssues(**incremental_args),
TimeTracking(**args),
Users(**args),
UsersGroupsDetailed(**args),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
"description": "List of Jira project keys to replicate data for, or leave it empty if you want to replicate data for all projects.",
"order": 3
},
"start_date": {
"type": "string",
"title": "Start Date",
"description": "The date from which you want to replicate data from Jira, use the format YYYY-MM-DDT00:00:00Z. Note that this field only applies to certain streams, and only data generated on or after the start date will be replicated. Or leave it empty if you want to replicate all data. For more information, refer to the <a href=\"https://docs.airbyte.com/integrations/sources/jira/\">documentation</a>.",
"examples": ["2021-03-01T00:00:00Z"],
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
"format": "date-time",
"order": 4
},
"expand_issue_changelog": {
"type": "boolean",
"title": "Expand Issue Changelog",
Expand Down
72 changes: 57 additions & 15 deletions airbyte-integrations/connectors/source-jira/source_jira/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from requests.exceptions import HTTPError
from source_jira.type_transfromer import DateTimeTransformer

from .utils import read_full_refresh, read_incremental
from .utils import read_full_refresh, read_incremental, safe_max

API_VERSION = 3

Expand Down Expand Up @@ -128,7 +128,13 @@ def should_retry(self, response: requests.Response) -> bool:
return super().should_retry(response)


class IncrementalJiraStream(JiraStream, ABC):
class StartDateJiraStream(JiraStream, ABC):
def __init__(self, start_date: Optional[pendulum.DateTime] = None, **kwargs):
super().__init__(**kwargs)
self._start_date = start_date


class IncrementalJiraStream(StartDateJiraStream, ABC):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._starting_point_cache = {}
Expand Down Expand Up @@ -157,7 +163,8 @@ def _get_starting_point(self, stream_state: Mapping[str, Any]) -> Optional[pendu
stream_state_value = stream_state.get(self.cursor_field)
if stream_state_value:
stream_state_value = pendulum.parse(stream_state_value)
return stream_state_value
return safe_max(stream_state_value, self._start_date)
return self._start_date

def read_records(
self, stream_slice: Optional[Mapping[str, Any]] = None, stream_state: Mapping[str, Any] = None, **kwargs
Expand Down Expand Up @@ -421,7 +428,12 @@ class IssueComments(IncrementalJiraStream):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.issues_stream = Issues(authenticator=self.authenticator, domain=self._domain, projects=self._projects)
self.issues_stream = Issues(
authenticator=self.authenticator,
domain=self._domain,
projects=self._projects,
start_date=self._start_date,
)

def path(self, stream_slice: Mapping[str, Any], **kwargs) -> str:
return f"issue/{stream_slice['key']}/comment"
Expand Down Expand Up @@ -570,7 +582,7 @@ def read_records(self, stream_slice: Mapping[str, Any], **kwargs) -> Iterable[Ma
yield from super().read_records(stream_slice={"key": issue_key}, **kwargs)


class IssueProperties(JiraStream):
class IssueProperties(StartDateJiraStream):
"""
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-properties/#api-rest-api-3-issue-issueidorkey-properties-propertykey-get
"""
Expand All @@ -579,7 +591,12 @@ class IssueProperties(JiraStream):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.issues_stream = Issues(authenticator=self.authenticator, domain=self._domain, projects=self._projects)
self.issues_stream = Issues(
authenticator=self.authenticator,
domain=self._domain,
projects=self._projects,
start_date=self._start_date,
)
self.issue_property_keys_stream = IssuePropertyKeys(authenticator=self.authenticator, domain=self._domain, projects=self._projects)

def path(self, stream_slice: Mapping[str, Any], **kwargs) -> str:
Expand All @@ -595,14 +612,19 @@ def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str,
return record


class IssueRemoteLinks(JiraStream):
class IssueRemoteLinks(StartDateJiraStream):
"""
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-remote-links/#api-rest-api-3-issue-issueidorkey-remotelink-get
"""

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.issues_stream = Issues(authenticator=self.authenticator, domain=self._domain, projects=self._projects)
self.issues_stream = Issues(
authenticator=self.authenticator,
domain=self._domain,
projects=self._projects,
start_date=self._start_date,
)

def path(self, stream_slice: Mapping[str, Any], **kwargs) -> str:
return f"issue/{stream_slice['key']}/remotelink"
Expand Down Expand Up @@ -675,7 +697,7 @@ def path(self, **kwargs) -> str:
return "issuetypescreenscheme"


class IssueTransitions(JiraStream):
class IssueTransitions(StartDateJiraStream):
"""
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-transitions-get
"""
Expand All @@ -685,7 +707,12 @@ class IssueTransitions(JiraStream):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.issues_stream = Issues(authenticator=self.authenticator, domain=self._domain, projects=self._projects)
self.issues_stream = Issues(
authenticator=self.authenticator,
domain=self._domain,
projects=self._projects,
start_date=self._start_date,
)

def path(self, stream_slice: Mapping[str, Any], **kwargs) -> str:
return f"issue/{stream_slice['key']}/transitions"
Expand All @@ -702,7 +729,7 @@ def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str,
return record


class IssueVotes(JiraStream):
class IssueVotes(StartDateJiraStream):
"""
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-votes/#api-rest-api-3-issue-issueidorkey-votes-get
Expand All @@ -717,7 +744,12 @@ class IssueVotes(JiraStream):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.issues_stream = Issues(authenticator=self.authenticator, domain=self._domain, projects=self._projects)
self.issues_stream = Issues(
authenticator=self.authenticator,
domain=self._domain,
projects=self._projects,
start_date=self._start_date,
)

def path(self, stream_slice: Mapping[str, Any], **kwargs) -> str:
return f"issue/{stream_slice['key']}/votes"
Expand All @@ -731,7 +763,7 @@ def transform(self, record: MutableMapping[str, Any], stream_slice: Mapping[str,
return record


class IssueWatchers(JiraStream):
class IssueWatchers(StartDateJiraStream):
"""
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-watchers/#api-rest-api-3-issue-issueidorkey-watchers-get
Expand All @@ -747,7 +779,12 @@ class IssueWatchers(JiraStream):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.issues_stream = Issues(authenticator=self.authenticator, domain=self._domain, projects=self._projects)
self.issues_stream = Issues(
authenticator=self.authenticator,
domain=self._domain,
projects=self._projects,
start_date=self._start_date,
)

def path(self, stream_slice: Mapping[str, Any], **kwargs) -> str:
return f"issue/{stream_slice['key']}/watchers"
Expand All @@ -771,7 +808,12 @@ class IssueWorklogs(IncrementalJiraStream):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.issues_stream = Issues(authenticator=self.authenticator, domain=self._domain, projects=self._projects)
self.issues_stream = Issues(
authenticator=self.authenticator,
domain=self._domain,
projects=self._projects,
start_date=self._start_date,
)

def path(self, stream_slice: Mapping[str, Any], **kwargs) -> str:
return f"issue/{stream_slice['key']}/worklog"
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/sources/jira.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ The Jira connector should not run into Jira API limitations under normal usage.

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:-----------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------|
| 0.8.0 | 2023-09-19 | [\#30585](https://github.com/airbytehq/airbyte/pull/30585) | Remove start date from spec |
| 0.7.1 | 2023-09-19 | [\#30585](https://github.com/airbytehq/airbyte/pull/30585) | Add skip for 404 error in issue properties steam |
| 0.7.0 | 2023-09-17 | [\#30532](https://github.com/airbytehq/airbyte/pull/30532) | Add foreign key to stream record where it misseing |
| 0.6.3 | 2023-09-19 | [\#30515](https://github.com/airbytehq/airbyte/pull/30515) | Add transform for invalid date-time format, add 404 handling for check |
| 0.6.2 | 2023-09-19 | [\#30578](https://github.com/airbytehq/airbyte/pull/30578) | Fetch deleted and archived Projects |
Expand Down

0 comments on commit 0cc07fb

Please sign in to comment.