Skip to content

Commit 55c3cd9

Browse files
authored
Merge pull request #3 from viveksyngh/add_watcher
Replace double quotes with single quotes
2 parents 5f35b43 + 1f84b00 commit 55c3cd9

5 files changed

Lines changed: 110 additions & 104 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
command: sudo apt -y install gmic optipng
109109
- run:
110110
name: Update exchange.stackstorm.org
111-
command: ~/ci/.circle/deployment
111+
command: ~/ci/.circle/deployment
112112

113113
workflows:
114114
version: 2

actions/lib/base.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from jira import JIRA
22

33
# from st2common.runners.base_action import Action
4-
__all__ = ["BaseJiraAction"]
4+
__all__ = ['BaseJiraAction']
55

66

77
class Action(object):
@@ -17,48 +17,48 @@ def __init__(self, config):
1717
def _get_client(self):
1818
config = self.config
1919

20-
options = {"server": config["url"], "verify": config["verify"]}
20+
options = {'server': config['url'], 'verify': config['verify']}
2121

2222
# Getting client cert configuration
23-
cert_file_path = config["client_cert_file"]
24-
key_file_path = config["client_key_file"]
23+
cert_file_path = config['client_cert_file']
24+
key_file_path = config['client_key_file']
2525
if cert_file_path and key_file_path:
26-
options["client_cert"] = (cert_file_path, key_file_path)
26+
options['client_cert'] = (cert_file_path, key_file_path)
2727

28-
auth_method = config["auth_method"]
28+
auth_method = config['auth_method']
2929

30-
if auth_method == "oauth":
31-
rsa_cert_file = config["rsa_cert_file"]
30+
if auth_method == 'oauth':
31+
rsa_cert_file = config['rsa_cert_file']
3232
rsa_key_content = self._get_file_content(file_path=rsa_cert_file)
3333

3434
oauth_creds = {
35-
"access_token": config["oauth_token"],
36-
"access_token_secret": config["oauth_secret"],
37-
"consumer_key": config["consumer_key"],
38-
"key_cert": rsa_key_content,
35+
'access_token': config['oauth_token'],
36+
'access_token_secret': config['oauth_secret'],
37+
'consumer_key': config['consumer_key'],
38+
'key_cert': rsa_key_content,
3939
}
4040

4141
client = JIRA(options=options, oauth=oauth_creds)
4242

43-
elif auth_method == "basic":
44-
basic_creds = (config["username"], config["password"])
43+
elif auth_method == 'basic':
44+
basic_creds = (config['username'], config['password'])
4545
client = JIRA(
4646
options=options,
4747
basic_auth=basic_creds,
48-
validate=config.get("validate", False),
48+
validate=config.get('validate', False),
4949
)
5050

5151
else:
5252
msg = (
53-
'You must set auth_method to either "oauth"',
54-
'or "basic" your jira.yaml config file.',
53+
"You must set auth_method to either 'oauth'",
54+
"or 'basic' your jira.yaml config file.",
5555
)
5656
raise Exception(msg)
5757

5858
return client
5959

6060
def _get_file_content(self, file_path):
61-
with open(file_path, "r") as fp:
61+
with open(file_path, 'r') as fp:
6262
content = fp.read()
6363

6464
return content

sensors/jira_sensor.py

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,84 +7,86 @@
77

88

99
class JIRASensor(PollingSensor):
10-
"""
10+
'''
1111
Sensor will monitor for any new projects created in JIRA and
1212
emit trigger instance when one is created.
13-
"""
13+
'''
1414

1515
def __init__(self, sensor_service, config=None, poll_interval=5):
1616
super(JIRASensor, self).__init__(
1717
sensor_service=sensor_service, config=config, poll_interval=poll_interval
1818
)
1919

2020
self._jira_url = None
21-
# The Consumer Key created while setting up the "Incoming Authentication" in
21+
# The Consumer Key created while setting up the 'Incoming Authentication' in
2222
# JIRA for the Application Link.
23-
self._consumer_key = u""
23+
self._consumer_key = u''
2424
self._rsa_key = None
2525
self._jira_client = None
26-
self._access_token = u""
27-
self._access_secret = u""
26+
self._access_token = u''
27+
self._access_secret = u''
2828
self._projects_available = None
2929
self._poll_interval = 30
3030
self._project = None
3131
self._issues_in_project = None
3232
self._jql_query = None
33-
self._trigger_name = "issues_tracker"
34-
self._trigger_pack = "jira"
35-
self._trigger_ref = ".".join([self._trigger_pack, self._trigger_name])
33+
self._trigger_name = 'issues_tracker'
34+
self._trigger_pack = 'jira'
35+
self._trigger_ref = '.'.join([self._trigger_pack, self._trigger_name])
3636

3737
def _read_cert(self, file_path):
3838
with open(file_path) as f:
3939
return f.read()
4040

4141
def setup(self):
42-
self._jira_url = self._config["url"]
43-
auth_method = self._config["auth_method"]
42+
self._jira_url = self._config['url']
43+
auth_method = self._config['auth_method']
4444

45-
options = {"server": self._config["url"], "verify": self._config["verify"]}
45+
options = {'server': self._config['url'],
46+
'verify': self._config['verify']}
4647
# Getting client cert configuration
47-
cert_file_path = self._config["client_cert_file"]
48-
key_file_path = self._config["client_key_file"]
48+
cert_file_path = self._config['client_cert_file']
49+
key_file_path = self._config['client_key_file']
4950
if cert_file_path and key_file_path:
50-
options["client_cert"] = (cert_file_path, key_file_path)
51+
options['client_cert'] = (cert_file_path, key_file_path)
5152

52-
if auth_method == "oauth":
53-
rsa_cert_file = self._config["rsa_cert_file"]
53+
if auth_method == 'oauth':
54+
rsa_cert_file = self._config['rsa_cert_file']
5455
if not os.path.exists(rsa_cert_file):
5556
raise Exception(
56-
"Cert file for JIRA OAuth not found at %s." % rsa_cert_file
57+
'Cert file for JIRA OAuth not found at %s.' % rsa_cert_file
5758
)
5859
self._rsa_key = self._read_cert(rsa_cert_file)
59-
self._poll_interval = self._config.get("poll_interval", self._poll_interval)
60+
self._poll_interval = self._config.get(
61+
'poll_interval', self._poll_interval)
6062
oauth_creds = {
61-
"access_token": self._config["oauth_token"],
62-
"access_token_secret": self._config["oauth_secret"],
63-
"consumer_key": self._config["consumer_key"],
64-
"key_cert": self._rsa_key,
63+
'access_token': self._config['oauth_token'],
64+
'access_token_secret': self._config['oauth_secret'],
65+
'consumer_key': self._config['consumer_key'],
66+
'key_cert': self._rsa_key,
6567
}
6668

6769
self._jira_client = JIRA(options=options, oauth=oauth_creds)
68-
elif auth_method == "basic":
69-
basic_creds = (self._config["username"], self._config["password"])
70+
elif auth_method == 'basic':
71+
basic_creds = (self._config['username'], self._config['password'])
7072
self._jira_client = JIRA(options=options, basic_auth=basic_creds)
7173

7274
else:
73-
msg = (
74-
'You must set auth_method to either "oauth"',
75-
'or "basic" your jira.yaml config file.',
76-
)
75+
msg = ('You must set auth_method to either "oauth"',
76+
'or "basic" your jira.yaml config file.',
77+
)
7778
raise Exception(msg)
7879

7980
if self._projects_available is None:
8081
self._projects_available = set()
8182
for proj in self._jira_client.projects():
8283
self._projects_available.add(proj.key)
83-
self._project = self._config.get("project", None)
84+
self._project = self._config.get('project', None)
8485
if not self._project or self._project not in self._projects_available:
85-
raise Exception("Invalid project (%s) to track." % self._project)
86-
self._jql_query = "project=%s" % self._project
87-
all_issues = self._jira_client.search_issues(self._jql_query, maxResults=None)
86+
raise Exception('Invalid project (%s) to track.' % self._project)
87+
self._jql_query = 'project=%s' % self._project
88+
all_issues = self._jira_client.search_issues(
89+
self._jql_query, maxResults=None)
8890
self._issues_in_project = {issue.key: issue for issue in all_issues}
8991

9092
def poll(self):
@@ -115,12 +117,12 @@ def _detect_new_issues(self):
115117
def _dispatch_issues_trigger(self, issue):
116118
trigger = self._trigger_ref
117119
payload = {}
118-
payload["issue_name"] = issue.key
119-
payload["issue_url"] = issue.self
120-
payload["issue_browse_url"] = self._jira_url + "/browse/" + issue.key
121-
payload["project"] = self._project
122-
payload["created"] = issue.raw["fields"]["created"]
123-
payload["assignee"] = issue.raw["fields"]["assignee"]
124-
payload["fix_versions"] = issue.raw["fields"]["fixVersions"]
125-
payload["issue_type"] = issue.raw["fields"]["issuetype"]["name"]
120+
payload['issue_name'] = issue.key
121+
payload['issue_url'] = issue.self
122+
payload['issue_browse_url'] = self._jira_url + '/browse/' + issue.key
123+
payload['project'] = self._project
124+
payload['created'] = issue.raw['fields']['created']
125+
payload['assignee'] = issue.raw['fields']['assignee']
126+
payload['fix_versions'] = issue.raw['fields']['fixVersions']
127+
payload['issue_type'] = issue.raw['fields']['issuetype']['name']
126128
self._sensor_service.dispatch(trigger, payload)

sensors/jira_sensor_for_apiv2.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,68 @@
77

88

99
class JIRASensorForAPIv2(PollingSensor):
10-
"""
10+
'''
1111
Sensor will monitor for any new projects created in JIRA and
1212
emit trigger instance when one is created.
13-
"""
13+
'''
1414

1515
def __init__(self, sensor_service, config=None, poll_interval=5):
1616
super(JIRASensorForAPIv2, self).__init__(
1717
sensor_service=sensor_service, config=config, poll_interval=poll_interval
1818
)
1919

2020
self._jira_url = None
21-
# The Consumer Key created while setting up the "Incoming Authentication" in
21+
# The Consumer Key created while setting up the 'Incoming Authentication' in
2222
# JIRA for the Application Link.
23-
self._consumer_key = u""
23+
self._consumer_key = u''
2424
self._rsa_key = None
2525
self._jira_client = None
26-
self._access_token = u""
27-
self._access_secret = u""
26+
self._access_token = u''
27+
self._access_secret = u''
2828
self._projects_available = None
2929
self._poll_interval = 30
3030
self._project = None
3131
self._issues_in_project = None
3232
self._jql_query = None
33-
self._trigger_name = "issues_tracker_for_apiv2"
34-
self._trigger_pack = "jira"
35-
self._trigger_ref = ".".join([self._trigger_pack, self._trigger_name])
33+
self._trigger_name = 'issues_tracker_for_apiv2'
34+
self._trigger_pack = 'jira'
35+
self._trigger_ref = '.'.join([self._trigger_pack, self._trigger_name])
3636

3737
def _read_cert(self, file_path):
3838
with open(file_path) as f:
3939
return f.read()
4040

4141
def setup(self):
42-
self._jira_url = self._config["url"]
43-
auth_method = self._config["auth_method"]
42+
self._jira_url = self._config['url']
43+
auth_method = self._config['auth_method']
4444

45-
options = {"server": self._config["url"], "verify": self._config["verify"]}
45+
options = {'server': self._config['url'],
46+
'verify': self._config['verify']}
4647
# Getting client cert configuration
47-
cert_file_path = self._config["client_cert_file"]
48-
key_file_path = self._config["client_key_file"]
48+
cert_file_path = self._config['client_cert_file']
49+
key_file_path = self._config['client_key_file']
4950
if cert_file_path and key_file_path:
50-
options["client_cert"] = (cert_file_path, key_file_path)
51+
options['client_cert'] = (cert_file_path, key_file_path)
5152

52-
if auth_method == "oauth":
53-
rsa_cert_file = self._config["rsa_cert_file"]
53+
if auth_method == 'oauth':
54+
rsa_cert_file = self._config['rsa_cert_file']
5455
if not os.path.exists(rsa_cert_file):
5556
raise Exception(
56-
"Cert file for JIRA OAuth not found at %s." % rsa_cert_file
57+
'Cert file for JIRA OAuth not found at %s.' % rsa_cert_file
5758
)
5859
self._rsa_key = self._read_cert(rsa_cert_file)
59-
self._poll_interval = self._config.get("poll_interval", self._poll_interval)
60+
self._poll_interval = self._config.get(
61+
'poll_interval', self._poll_interval)
6062
oauth_creds = {
61-
"access_token": self._config["oauth_token"],
62-
"access_token_secret": self._config["oauth_secret"],
63-
"consumer_key": self._config["consumer_key"],
64-
"key_cert": self._rsa_key,
63+
'access_token': self._config['oauth_token'],
64+
'access_token_secret': self._config['oauth_secret'],
65+
'consumer_key': self._config['consumer_key'],
66+
'key_cert': self._rsa_key,
6567
}
6668

6769
self._jira_client = JIRA(options=options, oauth=oauth_creds)
68-
elif auth_method == "basic":
69-
basic_creds = (self._config["username"], self._config["password"])
70+
elif auth_method == 'basic':
71+
basic_creds = (self._config['username'], self._config['password'])
7072
self._jira_client = JIRA(options=options, basic_auth=basic_creds)
7173

7274
else:
@@ -80,11 +82,12 @@ def setup(self):
8082
self._projects_available = set()
8183
for proj in self._jira_client.projects():
8284
self._projects_available.add(proj.key)
83-
self._project = self._config.get("project", None)
85+
self._project = self._config.get('project', None)
8486
if not self._project or self._project not in self._projects_available:
85-
raise Exception("Invalid project (%s) to track." % self._project)
86-
self._jql_query = "project=%s" % self._project
87-
all_issues = self._jira_client.search_issues(self._jql_query, maxResults=None)
87+
raise Exception('Invalid project (%s) to track.' % self._project)
88+
self._jql_query = 'project=%s' % self._project
89+
all_issues = self._jira_client.search_issues(
90+
self._jql_query, maxResults=None)
8891
self._issues_in_project = {issue.key: issue for issue in all_issues}
8992

9093
def poll(self):
@@ -115,11 +118,11 @@ def _detect_new_issues(self):
115118
def _dispatch_issues_trigger(self, issue):
116119
trigger = self._trigger_ref
117120
payload = {}
118-
payload["project"] = self._project
119-
payload["id"] = issue.id
120-
payload["expand"] = issue.raw.get("expand", "")
121-
payload["issue_key"] = issue.key
122-
payload["issue_url"] = issue.self
123-
payload["issue_browse_url"] = self._jira_url + "/browse/" + issue.key
124-
payload["fields"] = issue.raw.get("fields", {})
121+
payload['project'] = self._project
122+
payload['id'] = issue.id
123+
payload['expand'] = issue.raw.get('expand', '')
124+
payload['issue_key'] = issue.key
125+
payload['issue_url'] = issue.self
126+
payload['issue_browse_url'] = self._jira_url + '/browse/' + issue.key
127+
payload['fields'] = issue.raw.get('fields', {})
125128
self._sensor_service.dispatch(trigger, payload)
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
2-
url: "https://company.atlassian.net"
3-
auth_method: "basic"
4-
username: "user"
5-
password: "passwd"
6-
poll_interval: 30
7-
project: "MY_PROJECT"
8-
verify: True
9-
2+
url: "https://company.atlassian.net"
3+
auth_method: "basic"
4+
username: "user"
5+
password: "passwd"
6+
poll_interval: 30
7+
project: "MY_PROJECT"
8+
verify: True
9+
client_cert_file: ""
10+
client_key_file: ""

0 commit comments

Comments
 (0)