本文整理汇总了Python中jira.JIRA.add_watcher方法的典型用法代码示例。如果您正苦于以下问题:Python JIRA.add_watcher方法的具体用法?Python JIRA.add_watcher怎么用?Python JIRA.add_watcher使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jira.JIRA
的用法示例。
在下文中一共展示了JIRA.add_watcher方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_jira_ticket
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_watcher [as 别名]
def create_jira_ticket(summary, description, **kwargs):
"""
Create a new jira ticket, returning the associated number.
Examples:
Synchronously create a jira ticket::
create_jira_ticket("Test Ticket", "This is a test")
Asynchronously create a jira ticket::
create_jira_ticket.delay("Test Ticket", "This is a test")
Inputs:
.. note:: watchers and watcher_group are mutually exclusive.
:summary: The ticket summary
:description: The ticket description
:assignee: Who the ticket should be assigned to. Defaults to "-1" which
is analogous to selecting "automatic" on the JIRA web form.
:reporter: Who created the ticket (or is responsible for QCing it).
Defaults to "automaticagent".
:issuetype: The type of issue. Defaults to "Task".
:project: The project the ticket should be created in. Defaults to
"ST", which is Product Support.
:priority: Ticket Priority. Defaults to "Major".
:components: A list of components this ticket belongs to.
:watchers: A list of user names to add as watchers of this ticket.
:watcher_group: A group to assign as watchesr.
Output:
.. note:: The instance isn't returned because we need the ability to pass
the results to another asynchronous task without blocking, which
requires that all arguments be serializable.
The ticket key which corresponds to the created JIRA ticket.
"""
jira = JIRA(options=options, basic_auth=housekeeping_auth)
assignee = {'name': kwargs.setdefault('assignee', '-1')}
reporter = {'name': kwargs.setdefault('reporter', 'automationagent')}
issuetype = {'name': kwargs.setdefault('issuetype', 'Task')}
project = {'key': kwargs.setdefault('project', 'ST')}
priority = {'name': kwargs.setdefault('priority', 'Major')}
components = [{'name': name}
for name in kwargs.setdefault('components', [])]
watchers = kwargs.setdefault('watchers', set())
if 'watcher_group' in kwargs:
watchers = watchers.union(
jira.group_members(kwargs['watcher_group']).keys())
if assignee == reporter:
raise ValueError("Assignee and reporter must be different.")
fields = {
'project': project,
'summary': summary,
'description': description,
'issuetype': issuetype,
'priority': priority,
'reporter': reporter,
'assignee': assignee,
'components': components,
}
issue = jira.create_issue(fields=fields)
for watcher in watchers:
jira.add_watcher(issue, watcher)
return issue.key
示例2: JiraTicket
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_watcher [as 别名]
#.........这里部分代码省略.........
else:
basic_auth = credentials
if not watchers:
watchers = []
if not pri_mapping:
pri_mapping = {
'NO-IMPACT': {'name': 'Low'},
'REDUCED-REDUNDANCY': {'name': 'Medium'},
'DEGRADED': {'name': 'High'},
'OUTAGE': {'name': 'Highest'},
}
self.jira = JIRA(url, basic_auth=basic_auth)
self.project = project
self.issuetype = issuetype
self.finished_transition = finished_transition
self.watchers = watchers
self.pri_mapping = pri_mapping
def exists(self):
"""Return bool for whether maintenance issue exists for this event
Improvements: Currently not handling the case where multiple issues are
returned which may hint that the key used isn't unique enough or people
have manually added the same label to other things. Also no exception
handling mostly because the exception return by JIRA is pretty
descriptive
Returns:
exists (bool)
"""
existing = self.jira.search_issues('labels = {}'.format(self.key))
if existing:
self.ticket = existing[0]
return True if existing else False
def create(self):
"""Create issue for event
Pre-check factors such as chehcking if this is a duplicate. If so, stop
further actions.
Returns:
success (bool)
"""
jira = self.jira
# If issue doesn't exist, create it. Else return False for inability
# Add watchers to the new ticket
if not self.exists():
options = {
'project': self.project,
'summary': self.title,
'labels': [self.key],
'description': self.body,
'issuetype': {'name': self.issuetype},
'priority': self.pri_mapping[self.impact],
}
new_issue = jira.create_issue(fields=options)
self.ticket = new_issue
[self._add_watcher(new_issue, w) for w in self.watchers]
return True
else:
return False
def close(self):
"""Return bool representing success or failure for closing issue
If issue doesn't exist, will return False because it can't close.
Returns:
success (bool)
"""
jira = self.jira
finished_transition = self.finished_transition
if self.exists():
# Fetch the transitions that we can put the current issue into.
# Search through these for the provided ``finished_transition``
# from init. If not found, raise error.
tkt = self.ticket
transitions = jira.transitions(tkt)
transition_ids = [
t['id'] for t in transitions
if t['name'] == self.finished_transition
]
if not transition_ids:
raise ValueError(
'Transition "{}" not found'.format(finished_transition)
)
t = transition_ids[0]
jira.transition_issue(tkt, t)
else:
return False
def _add_watcher(self, issue, watcher):
"""Add watcher to issue"""
self.jira.add_watcher(issue, watcher)