Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions airflow/providers/jira/hooks/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# specific language governing permissions and limitations
# under the License.
"""Hook for JIRA"""
from typing import Any, Optional

from jira import JIRA
from jira.exceptions import JIRAError

Expand All @@ -31,15 +33,15 @@ class JiraHook(BaseHook):
:type jira_conn_id: str
"""
def __init__(self,
jira_conn_id='jira_default',
proxies=None):
jira_conn_id: str = 'jira_default',
proxies: Optional[Any] = None) -> None:
super().__init__()
self.jira_conn_id = jira_conn_id
self.proxies = proxies
self.client = None
self.get_conn()

def get_conn(self):
def get_conn(self) -> JIRA:
if not self.client:
self.log.debug('Creating Jira client for conn_id: %s', self.jira_conn_id)

Expand Down
15 changes: 8 additions & 7 deletions airflow/providers/jira/operators/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# specific language governing permissions and limitations
# under the License.

from typing import Any, Callable, Dict, Optional

from airflow.exceptions import AirflowException
from airflow.models import BaseOperator
Expand Down Expand Up @@ -45,21 +46,21 @@ class JiraOperator(BaseOperator):

@apply_defaults
def __init__(self,
jira_conn_id='jira_default',
jira_method=None,
jira_method_args=None,
result_processor=None,
get_jira_resource_method=None,
jira_method: str,
jira_conn_id: str = 'jira_default',
jira_method_args: Optional[dict] = None,
result_processor: Optional[Callable] = None,
get_jira_resource_method: Optional[Callable] = None,
*args,
**kwargs):
**kwargs) -> None:
super().__init__(*args, **kwargs)
self.jira_conn_id = jira_conn_id
self.method_name = jira_method
self.jira_method_args = jira_method_args
self.result_processor = result_processor
self.get_jira_resource_method = get_jira_resource_method

def execute(self, context):
def execute(self, context: Dict) -> Any:
try:
if self.get_jira_resource_method is not None:
# if get_jira_resource_method is provided, jira_method will be executed on
Expand Down
34 changes: 17 additions & 17 deletions airflow/providers/jira/sensors/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from jira.resources import Resource
from typing import Any, Callable, Dict, Optional

from jira.resources import Issue, Resource

from airflow.providers.jira.operators.jira import JIRAError, JiraOperator
from airflow.sensors.base_sensor_operator import BaseSensorOperator
Expand All @@ -38,12 +40,12 @@ class JiraSensor(BaseSensorOperator):

@apply_defaults
def __init__(self,
jira_conn_id='jira_default',
method_name=None,
method_params=None,
result_processor=None,
method_name: str,
jira_conn_id: str = 'jira_default',
method_params: Optional[dict] = None,
result_processor: Optional[Callable] = None,
*args,
**kwargs):
**kwargs) -> None:
super().__init__(*args, **kwargs)
self.jira_conn_id = jira_conn_id
self.result_processor = None
Expand All @@ -57,7 +59,7 @@ def __init__(self,
jira_method_args=self.method_params,
result_processor=self.result_processor)

def poke(self, context):
def poke(self, context: Dict) -> Any:
return self.jira_operator.execute(context=context)


Expand All @@ -81,13 +83,12 @@ class JiraTicketSensor(JiraSensor):

@apply_defaults
def __init__(self,
jira_conn_id='jira_default',
ticket_id=None,
field=None,
expected_value=None,
field_checker_func=None,
*args,
**kwargs):
jira_conn_id: str = 'jira_default',
ticket_id: Optional[str] = None,
field: Optional[str] = None,
expected_value: Optional[str] = None,
field_checker_func: Optional[Callable] = None,
**kwargs) -> None:

self.jira_conn_id = jira_conn_id
self.ticket_id = ticket_id
Expand All @@ -98,10 +99,9 @@ def __init__(self,

super().__init__(jira_conn_id=jira_conn_id,
result_processor=field_checker_func,
*args,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove *args to avoid mypy issue:
python/mypy#6799
#9784

@mik-laj mik-laj Jul 26, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove args in more operators:
#9942

@mik-laj mik-laj Jul 26, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me with that too in a saperate PR? That way, other people won't face the problem you had.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will look into soon.

**kwargs)

def poke(self, context):
def poke(self, context: Dict) -> Any:
self.log.info('Jira Sensor checking for change in ticket: %s', self.ticket_id)

self.jira_operator.method_name = "issue"
Expand All @@ -111,7 +111,7 @@ def poke(self, context):
}
return JiraSensor.poke(self, context=context)

def issue_field_checker(self, issue):
def issue_field_checker(self, issue: Issue) -> Optional[bool]:
"""Check issue using different conditions to prepare to evaluate sensor."""
result = None
try: # pylint: disable=too-many-nested-blocks
Expand Down
1 change: 1 addition & 0 deletions tests/providers/jira/sensors/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_issue_label_set(self, jira_mock):
jira_mock.return_value.issue.return_value = minimal_test_ticket

ticket_label_sensor = JiraTicketSensor(
method_name='issue',
task_id='search-ticket-test',
ticket_id='TEST-1226',
field_checker_func=TestJiraSensor.field_checker_func,
Expand Down