本文整理汇总了Python中jira.JIRA.add_comment方法的典型用法代码示例。如果您正苦于以下问题:Python JIRA.add_comment方法的具体用法?Python JIRA.add_comment怎么用?Python JIRA.add_comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jira.JIRA
的用法示例。
在下文中一共展示了JIRA.add_comment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_comment
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
def add_comment(find, note, force_push=False):
prod = Product.objects.get(engagement=Engagement.objects.get(test=find.test))
jpkey = JIRA_PKey.objects.get(product=prod)
jira_conf = jpkey.conf
if jpkey.push_notes or force_push == True:
jira = JIRA(server=jira_conf.url, basic_auth=(jira_conf.username, jira_conf.password))
j_issue = JIRA_Issue.objects.get(finding=find)
jira.add_comment(j_issue.jira_id, '(%s): %s' % (note.author.get_full_name(), note.entry))
示例2: updateIssues
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
def updateIssues(issuelist, NEXTorDOTX, description):
numExistingIssues = len(issuelist) if not issuelist == None else 0
if numExistingIssues > 0 :
if debug: print "[DEBUG] Move " + str(numExistingIssues) + " " + description
jira = JIRA(options={'server':jiraserver}, basic_auth=(jirauser, jirapwd))
cnt = 0
for s in issuelist :
key = components.getText(components.findChildNodeByName(s, 'key').childNodes)
issue = jira.issue(key)
cnt += 1
doThisJIRA = True
whichLabelSkipped = ""
for label in issue.fields.labels:
for skipLabel in skipLabels:
if label == skipLabel.strip():
whichLabelSkipped = label
doThisJIRA = False
linkURL = components.getText(components.findChildNodeByName(s, 'link').childNodes)
summary = components.getText(components.findChildNodeByName(s, 'summary').childNodes).strip()
operation = " + [" + str(cnt) + "/" + str(len(issuelist)) + "] Update " + linkURL + " : " + summary
if debug: operation = operation + " :: " + str(issue.fields.labels)
if doThisJIRA == False:
operation = " - [" + str(cnt) + "/" + str(len(issuelist)) + "] -Skip- " + linkURL + " (" + whichLabelSkipped + ") : " + summary
print operation
else:
if options.autoApplyChanges or options.dryrun:
print operation
yesno = ""
else:
yesno = raw_input(operation + " ? [y/N] ")
if options.autoApplyChanges or yesno.capitalize() in ["Y"]:
# move issue to next fixversion
if components.findChildNodeByName(s, 'project').attributes["key"].value == "JBIDE": # JBIDE or JBDS
fixversion = version_jbt
fixversion_NEXT = version_jbt_NEXT if NEXTorDOTX else version_jbt_DOTX
else:
fixversion = version_ds
fixversion_NEXT = version_ds_NEXT if NEXTorDOTX else version_ds_DOTX
fixVersions = []
# NOTE: if there is more than one fixversion, the others will not be changed
for version in issue.fields.fixVersions:
if version.name != fixversion:
fixVersions.append({'name': version.name})
fixVersions.append({'name': fixversion_NEXT})
issue.update(fields={'fixVersions': fixVersions})
# only for NEXT, not for .x
if NEXTorDOTX:
# move issue to new sprint
jira.add_issues_to_sprint(sprintId_NEXT, [key])
jira.add_comment(key, "[checkUnresolvedIssues.py] Slip to fixversion = *" + fixversion_NEXT + "* and sprint = *" + sprint_NEXT + "*")
else:
jira.add_comment(key, "[checkUnresolvedIssues.py] Slip to fixversion = *" + fixversion_NEXT + "*")
示例3: update_jira_story
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
def update_jira_story(story_id, transition_id, comment=None, **kwargs):
try:
jira = JIRA("https://thezebra.atlassian.net", basic_auth=(os.environ['username'], os.environ['password']))
issue = jira.issue(story_id)
allowed_transitions = {t['id'] for t in jira.transitions(issue)}
if str(transition_id) not in allowed_transitions:
app.logger.warn("Story %s cannot transition to %s" % (story_id, transition_id))
else:
jira.transition_issue(issue, transition_id)
if comment:
jira.add_comment(issue, comment)
except Exception as ex:
app.logger.error(ex)
示例4: add_jira_comment
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
def add_jira_comment(jira_id, comment):
if not settings.CASELINK_JIRA['ENABLE']:
return False
user = settings.CASELINK_JIRA['USER']
password = settings.CASELINK_JIRA['PASSWORD']
server = settings.CASELINK_JIRA['SERVER']
basic_auth = (user, password)
options = {
'server': server,
'verify': False,
}
jira = JIRA(options, basic_auth=basic_auth)
jira.add_comment(jira.issue(id=jira_id), comment)
return True
示例5: __init__
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
class Jira:
def __init__(self):
options = {
'server': jira_url, 'verify': False, 'check_update': False
}
self.jira = JIRA(options, basic_auth=(jira_user, jira_passwd))
def main(self, comment, group_name):
message = comment['message'].split('\n')[0]
commit_sha1 = comment['id']
author = comment['author_name']
commited_date = comment['committed_date'].split('+')[0]
date = datetime.datetime.strptime(commited_date, "%Y-%m-%dT%H:%M:%S.%f")
projects = self.jira.projects()
project_keys = sorted([project.key for project in projects])
for keys in project_keys:
if message.startswith(keys):
issue_id = message.split(' ')[0]
try:
comment_msg = ' '.join(message.split(' ')[1:])
except IndexError:
comment_msg = issue_id
compare_url = "%s/%s/%s/commit/%s" % (git_server_url, group_name, project_name, refs)
msg = '%s\n\nProject Repo: %s\nUser: %s\nCommit Time: %s\nCommit SHA1: [%s | %s]\n\n' %\
(comment_msg, project_name, author, date, commit_sha1, compare_url)
comment = self.jira.add_comment(issue_id, msg)
示例6: update_tickets_from_git
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
def update_tickets_from_git(self, from_commit=None, to_commit=None):
"""
Find all ticket numbers and update their status in Jira.
Run during a deployment.
Looks at all commits between now and the last deployment.
"""
from jira import JIRA, JIRAError
from burlap.git import gittracker, CURRENT_COMMIT
r = self.local_renderer
# get_current_commit = gittracker.get_current_commit
# GITTRACKER = gittracker.name.upper()
# Ensure this is only run once per role.
if self.genv.host_string != self.genv.hosts[-1]:
self.vprint('Not first server. Aborting.')
return
self.vprint('self.env.update_from_git:', self.env.update_from_git)
self.vprint('self.genv.jirahelper_update_from_git:', self.genv.jirahelper_update_from_git)
if not self.env.update_from_git:
self.vprint('Update from git disabled. Aborting.')
return
if not self.env.ticket_pattern:
self.vprint('No ticket pattern defined. Aborting.')
return
if not self.env.basic_auth_username or not self.env.basic_auth_password:
self.vprint('Username or password not given. Aborting.')
return
# During a deployment, we should be given these, but for testing,
# lookup the diffs dynamically.
last = gittracker.last_manifest
current = gittracker.current_manifest
last_commit = from_commit or last.current_commit#[CURRENT_COMMIT]
print('last_commit:', last_commit)
current_commit = to_commit or current[CURRENT_COMMIT]
print('current_commit:', current_commit)
if not last_commit or not current_commit:
print('Missing commit ID. Aborting.')
return
self.vprint('-'*80)
self.vprint('last.keys:', last.keys())
self.vprint('-'*80)
self.vprint('current.keys:', current.keys())
# try:
# last_commit = last['GITTRACKER']['current_commit']
# except KeyError:
# return
# current_commit = current['GITTRACKER']['current_commit']
# Find all tickets deployed between last deployment and now.
tickets = self.get_tickets_between_commits(current_commit, last_commit)
self.vprint('tickets:', tickets)
# Update all tickets in Jira.
jira = JIRA({
'server': self.env.server
}, basic_auth=(self.env.basic_auth_username, self.env.basic_auth_password))
for ticket in tickets:
# Mention this Jira updated.
r.env.role = r.genv.ROLE.lower()
comment = r.format(self.env.ticket_update_message_template)
print('Commenting on ticket %s: %s' % (ticket, comment))
if not self.dryrun:
jira.add_comment(ticket, comment)
# Update ticket status.
recheck = False
while 1:
print('Looking up jira ticket %s...' % ticket)
issue = jira.issue(ticket)
self.vprint('Ticket %s retrieved.' % ticket)
transition_to_id = dict((t['name'], t['id']) for t in jira.transitions(issue))
self.vprint('%i allowable transitions found:' % len(transition_to_id))
if self.verbose:
pprint(transition_to_id)
self.vprint('issue.fields.status.id:', issue.fields.status.id)
self.vprint('issue.fields.status.name:', issue.fields.status.name)
jira_status_id = issue.fields.status.name.title()
self.vprint('jira_status_id:', jira_status_id)
next_transition_name = self.env.deploy_workflow.get(jira_status_id)
self.vprint('next_transition_name:', next_transition_name)
next_transition_id = transition_to_id.get(next_transition_name)
self.vprint('next_transition_id:', next_transition_id)
if next_transition_name:
if issue.fields.assignee:
if issue.fields.assignee.raw:
assignee_name = issue.fields.assignee.name
else:
# Get assignee name directly
#.........这里部分代码省略.........
示例7: JIRA_PROJECT
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
class JIRA_PROJECT(object):
def __init__(self, server, project, basic_auth=()):
self.server = server
self.project = project
self.basic_auth = basic_auth
self._connect_to_jira()
def _connect_to_jira(self):
try:
print 'Tyring to connect JIRA server: {} and project: {}...'.format(self.server, self.project)
self.jira = JIRA(server=self.server, basic_auth=self.basic_auth)
print 'JIRA server connected successfully...'
except Exception as err:
print 'JIRA Connection error'
print err
sys.exit(1)
def get_defect_from_qc(self, qc_num):
# print getattr(issue.fields, 'summary')
# print getattr(issue.fields, '')
if self.project is not 'TDETS':
print 'Project is not TDETS'
sys.exit(0)
defects = self.jira.search_issues('project={}'.format(self.project), maxResults=5000)
for defect in defects:
print 'checking', defect.key
#defect = self.jira.issue(defect, fields='assignee,summary,status,customfield_13625,comment')
defect = self.jira.issue(defect.key, fields='customfield_13625,summary,status,assignee')
if (defect.fields.customfield_13625) and (qc_num in defect.fields.customfield_13625):
print defect.key
print defect.fields.customfield_13625
print defect.fields.summary
print defect.fields.status
print defect.fields.assignee
return defect.key
else:
print 'no matching QC found in TDETS'
return None
def get_my_defects(self):
# print getattr(issue.fields, 'summary')
# print getattr(issue.fields, 'customfield_13625')
defects = self.jira.search_issues('project={} and assignee = currentUser()'.format(self.project))
list_defects = []
for defect in defects:
defect = self.jira.issue(defect.key, fields='assignee,summary,status,customfield_13625,comment')
if defect.fields.comment.comments:
last_comment = defect.fields.comment.comments[-1].raw['body']
else:
last_comment = 'No Comment Yet'
qc_id = getattr('defect.fields', 'customfield_13625', 'NO QC ID')
#qc_id=defect.fields.customfield_13625
defect_summary = DEFECT_SUMMARY(id=defect.key,
qc_id=qc_id,
summary=defect.fields.summary,
status=defect.fields.status,
assignee=defect.fields.assignee,
last_comment=last_comment,
)
list_defects.append(defect_summary)
return list_defects
def get_all_issues(self):
pass
def create_new_issue(self):
pass
def update_defect(self, defect, new_comment=None, new_assignee=None):
#https://answers.atlassian.com/questions/8627641/update-custom-field-using-jira-python
if new_comment:
#how to check new comment is posted correctly
comment = self.jira.add_comment(defect, new_comment)
if isinstance(comment, jira.resources.Comment):
print 'Posted Comment:'
print comment.raw['body']
else:
print 'Failed'
return False
if new_assignee:
#update new assignee
if not self.jira.assign_issue(defect, new_assignee):
return False
return True
def get_defect_history(self, defect):
# https://answers.atlassian.com/questions/64708/is-it-possible-to-get-the-issue-history-using-the-rest-api
defect = self.jira.issue(defect, expand='changelog')
for history in defect.changelog.histories:
for item in history.items:
#.........这里部分代码省略.........
示例8: post_jira_comment
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
def post_jira_comment(server, username, password, ticketId, commentText):
jira = JIRA(server=server, basic_auth=(username, password), options={'verify':False})
jira.add_comment(ticketId, commentText)
示例9: __init__
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
class JiraCI:
resolution_state = {"fixed": "1", "wont fixed": "2", "duplicate": "3", "incomplete": "4", "cannot reproduce": "5",
"not a bug": "6", "done": "7"}
def __init__(self, jira_url, login, password):
if version_info[1] <= 6:
options = jira_url
else:
options = {"server": jira_url}
self.jira = JIRA(options, basic_auth=(login, password))
@staticmethod
def debug_jira(text):
stdout.write("[DEBUG JIRA]: {0}\n".format(text))
def check_issue_exist(self, issue_id):
try:
self.jira.issue(issue_id)
except JIRAError as e:
print "[-] : {0} - {1}".format(issue_id, e.text)
return False
else:
return True
def check_issue_state(self, issue_id, issue_state):
jira_issue = self.jira.issue(issue_id)
if jira_issue.fields.status.name.lower() == issue_state.lower():
return True
else:
return False
def add_comment(self, issue_id, comment, formatting=False):
jira_issue = self.jira.issue(issue_id)
if formatting:
comment = "{code}" + comment + "{code}"
if not self.check_comment_exist(issue_id, comment):
self.jira.add_comment(jira_issue, comment)
self.debug_jira("Comment (for {0}) : {1} added".format(issue_id, comment.rstrip()))
else:
self.debug_jira("Comment (for {0}) : {1} already exist".format(issue_id, comment.rstrip()))
def assign_issue(self, issue_id, assigned_user):
jira_issue = self.jira.issue(issue_id)
jira_issue.update(assignee={"name": assigned_user})
def add_link(self, issue_id, title, url):
url_object = {"url": url, "title": title}
if not self.check_link_exist(issue_id, title, url):
self.jira.add_remote_link(issue_id, url_object)
self.debug_jira("Link (for {0}) : {1} added".format(issue_id, url))
else:
self.debug_jira("Link (for {0}) : {1} already exist".format(issue_id, url))
def resolve_issue_to_reporter(self, issue_id):
reporter = self.get_reporter_issue(issue_id)
self.jira.transition_issue(issue_id, "5", resolution={"id": self.resolution_state["fixed"]})
self.assign_issue(issue_id, reporter)
def get_reporter_issue(self, issue_id):
jira_issue = self.jira.issue(issue_id)
return jira_issue.fields.reporter.name
def check_comment_exist(self, issue_id, new_comment):
comments = [c.body for c in self.jira.comments(issue_id)]
if new_comment in comments:
return True
return False
def check_link_exist(self, issue_id, title, url):
links = [l.raw["object"] for l in self.jira.remote_links(issue_id)]
for link in links:
if link["title"] == title and link["url"] == url:
return True
return False
def resolve_from_git(self, issue_id, short_commit_message, title_url, package_url):
if self.check_issue_exist(issue_id):
if not self.check_issue_state(issue_id, "resolved"):
self.resolve_issue_to_reporter(issue_id)
self.debug_jira("Issue {0} already resolve".format(issue_id))
else:
self.debug_jira("Issue {0} resolved".format(issue_id))
self.add_link(issue_id, title_url, package_url)
self.add_comment(issue_id, short_commit_message, formatting=True)
def refer_from_git(self, issue_id, commit_message):
if self.check_issue_exist(issue_id):
self.add_comment(issue_id, commit_message, formatting=True)
示例10: reopened_task
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
def reopened_task(branch):
jira = JIRA(options, basic_auth=(JIRA_USERNAME, PASSWORD))
issue = jira.issue(branch)
jira.transition_issue(issue, u'Reopened')
jira.add_comment(branch, 'Autotest fail')
示例11: Jira
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
class Jira(object):
"""
jira operation class
"""
def __init__(self, **args):
"""
Init JIRA connection
"""
self.server = settings.CASELINK_JIRA['SERVER']
self.username = settings.CASELINK_JIRA['USER']
self.password = settings.CASELINK_JIRA['PASSWORD']
self.verify = False # TODO: move to settings
self._jira = JIRA(options={
'server': self.server,
'verify': self.verify,
}, basic_auth=(self.username, self.password))
def search_issues(self, project_name, jql_str, fields=None):
"""
Search issue under the project and return result
"""
jql_str = "project = " + project_name + " and " + jql_str
return self.jira_.search_issues(jql_str, maxResults=-1, fields=fields)
def add_comment(self, issue, comment):
"""
Add comments in the issue
"""
if isinstance(issue, (str, unicode)):
issue = self._jira.issue(issue)
return self._jira.add_comment(issue, comment)
def transition_issue(self, issue, status):
"""
Transition issue status to another
"""
self.jira_.transition_issue(issue, status)
def get_watchers(self, issue):
"""
Get a watchers Resource from the server for an issue
"""
watcher_data = self.jira_.watchers(issue)
return [str(w.key) for w in watcher_data.watchers]
def add_watcher(self, issue, watchers):
"""
Append an issue's watchers list
"""
new_watchers = []
if isinstance(watchers, str):
new_watchers.append(watchers)
elif isinstance(watchers, list):
new_watchers = watchers
for watcher in new_watchers:
self.jira_.add_watcher(issue, watcher)
def remove_watcher(self, issue, watchers):
"""
Remove watchers from an issue's watchers list
"""
del_watchers = []
if isinstance(watchers, str):
del_watchers.append(watchers)
elif isinstance(watchers, list):
del_watchers = watchers
for watcher in del_watchers:
self.jira_.remove_watcher(issue, watcher)
def create_issue(self, issue_dict):
"""
Create Issue and apply some default properties
"""
dict_ = {
'project': {
'key': 'LIBVIRTAT',
},
'summary': None,
'description': None,
'priority': {
'name': 'Major',
},
'assignee': {
'name': None
},
}
parent_issue = issue_dict.pop('parent_issue', None) or settings.CASELINK_JIRA['DEFAULT_PARENT_ISSUE']
assignee = issue_dict.pop('assignee', None) or settings.CASELINK_JIRA['DEFAULT_ASSIGNEE']
dict_.update({
'assignee': {
'name': assignee
}
})
if parent_issue:
dict_.update({
'parent': {
'id': parent_issue
#.........这里部分代码省略.........
示例12: sorted
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
# Get all projects viewable by anonymous users.
projects = jira.projects()
# Sort available project keys, then return the second, third, and fourth keys.
keys = sorted([project.key for project in projects])[2:5]
# Get an issue.
issue = jira.issue('JRA-1330')
# Find all comments made by Atlassians on this issue.
atl_comments = [comment for comment in issue.fields.comment.comments
if re.search(r'@atlassian.com$', comment.author.emailAddress)]
# Add a comment to the issue.
jira.add_comment(issue, 'Comment text')
# Change the issue's summary and description.
issue.update(
summary="I'm different!", description='Changed the summary to be different.')
# Change the issue without sending updates
issue.update(notify=False, description='Quiet summary update.')
# You can update the entire labels field like this
issue.update(labels=['AAA', 'BBB'])
# Or modify the List of existing labels. The new label is unicode with no
# spaces
issue.fields.labels.append(u'new_text')
issue.update(fields={"labels": issue.fields.labels})
示例13: update_tickets_from_git
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
def update_tickets_from_git(last=None, current=None):
"""
Run during a deployment.
Looks at all commits between now and the last deployment.
Finds all ticket numbers and updates their status in Jira.
"""
from jira import JIRA, JIRAError
from burlap.deploy import get_last_current_diffs
from burlap.git import gittracker
get_current_commit = gittracker.get_current_commit
GITTRACKER = gittracker.name.upper()
dryrun = common.get_dryrun()
verbose = common.get_verbose()
# Ensure this is only run once per role.
if env.host_string != env.hosts[-1]:
return
if not env.jira_update_from_git:
return
if not env.jira_ticket_pattern:
return
if not env.jira_basic_auth_username or not env.jira_basic_auth_password:
return
# During a deployment, we should be given these, but for testing,
# lookup the diffs dynamically.
if not last or not current:
last, current = get_last_current_diffs(GITTRACKER)
if verbose:
print('-'*80)
print('last.keys:', last.keys())
print('-'*80)
print('current.keys:', current.keys())
try:
last_commit = last['GITTRACKER']['current_commit']
except KeyError:
return
current_commit = current['GITTRACKER']['current_commit']
# Find all tickets deployed between last deployment and now.
tickets = get_tickets_between_commits(current_commit, last_commit)
if verbose:
print('tickets:', tickets)
# Update all tickets in Jira.
jira = JIRA({
'server': env.jira_server
}, basic_auth=(env.jira_basic_auth_username, env.jira_basic_auth_password))
for ticket in tickets:
# Mention this Jira updated.
comment = env.jira_ticket_update_message_template % dict(role=env.ROLE.lower())
print('Commenting on ticket %s: %s' % (ticket, comment))
if not dryrun:
jira.add_comment(ticket, comment)
# Update ticket status.
recheck = False
while 1:
print('Looking up jira ticket %s...' % ticket)
issue = jira.issue(ticket)
print('Ticket %s retrieved.' % ticket)
transition_to_id = dict((t['name'], t['id']) for t in jira.transitions(issue))
print('%i allowable transitions found: %s' % (len(transition_to_id), ', '.join(transition_to_id.keys())))
next_transition_name = env.jira_deploy_workflow.get(issue.fields.status.name.title())
next_transition_id = transition_to_id.get(next_transition_name)
if next_transition_name:
new_fields = {}
# print('jira_assignee_by_status:', env.jira_assignee_by_status, issue.fields.status.name.title()
new_assignee = env.jira_assignee_by_status.get(
#issue.fields.status.name.title(),
next_transition_name,
issue.fields.assignee.name,
)
if new_assignee == 'reporter':
new_assignee = issue.fields.reporter.name
# print('new_assignee:', new_assignee)
print('Updating ticket %s to status %s and assigning it to %s.' \
% (ticket, next_transition_name, new_assignee))
if not dryrun:
try:
jira.transition_issue(
issue,
next_transition_id,
)
recheck = True
except AttributeError as e:
print('Unable to transition ticket %s to %s: %s' \
% (ticket, next_transition_name, e), file=sys.stderr)
# Note assignment should happen after transition, since the assignment may
#.........这里部分代码省略.........
示例14: JIRA
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
# -*- coding: utf-8 -*-
from jira import JIRA
jira_server = 'http://10.10.10.10:8080'
jira_username = 'ww'
jira_password = 'wwpwd'
myjira = JIRA(jira_server,basic_auth=(jira_username,jira_password))
myissue = myjira.issue('WWTES-69')
print (myissue)
myjira.add_comment(myissue, 'commented by python')
# missue = myissue.fields.customfield_13412.displayName
# summary = myissue.fields.customfield_13412;
# print(missue, summary)
示例15: update_or_create_jira_issue
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import add_comment [as 别名]
def update_or_create_jira_issue(study_id, user_token, is_curator):
try:
params = app.config.get('JIRA_PARAMS')
user_name = params['username']
password = params['password']
updated_studies = []
try:
jira = JIRA(options=options, basic_auth=(user_name, password))
except:
return False, 'Could not connect to JIRA server, incorrect username or password?', updated_studies
# Get the MetaboLights project
mtbls_project = jira.project(project)
studies = [study_id]
if not study_id and is_curator:
studies = get_all_studies(user_token)
for study in studies:
study_id = study[0]
user_name = study[1]
release_date = study[2]
update_date = study[3]
study_status = study[4]
curator = study[5]
issue = []
summary = None
# Get an issue based on a study accession search pattern
search_param = "project='" + mtbls_project.key + "' AND summary ~ '" + study_id + " \\\-\\\ 20*'"
issues = jira.search_issues(search_param) # project = MetaboLights AND summary ~ 'MTBLS121 '
new_summary = study_id + ' - ' + release_date.replace('-', '') + ' - ' + \
study_status + ' (' + user_name + ')'
try:
if issues:
issue = issues[0]
else:
if study_status == 'Submitted':
logger.info("Could not find Jira issue for " + search_param)
print("Creating new Jira issue for " + search_param)
issue = jira.create_issue(project=mtbls_project.key, summary='MTBLS study - To be updated',
description='Created by API', issuetype={'name': 'Story'})
else:
continue # Only create new cases if the study is in status Submitted
except Exception: # We could not find or create a Jira issue
continue
summary = issue.fields.summary # Follow pattern 'MTBLS123 - YYYYMMDD - Status'
try:
assignee = issue.fields.assignee.name
except:
assignee = ""
valid_curator = False
jira_curator = ""
if curator:
if curator.lower() == 'mark':
jira_curator = 'mwilliam'
valid_curator = True
elif curator.lower() == 'keeva':
jira_curator = 'keeva'
valid_curator = True
else:
jira_curator = ""
# Release date or status has changed, or the assignee (curator) has changed
if summary.startswith('MTBLS') and (summary != new_summary or assignee != jira_curator):
# Add "Curation" Epic
issues_to_add = [issue.key]
jira.add_issues_to_epic(curation_epic, issues_to_add) # Add the Curation Epic
labels = maintain_jira_labels(issue, study_status, user_name)
# Add a comment to the issue.
comment_text = 'Status ' + study_status + '. Database update date ' + update_date
jira.add_comment(issue, comment_text)
# Change the issue's summary, comments and description.
issue.update(summary=new_summary, fields={"labels": labels}, notify=False)
if valid_curator: # ToDo, what if the curation log is not up to date?
issue.update(assignee={'name': jira_curator})
updated_studies.append(study_id)
logger.info('Updated Jira case for study ' + study_id)
print('Updated Jira case for study ' + study_id)
except Exception:
return False, 'Update failed', updated_studies
return True, 'Ticket(s) updated successfully', updated_studies