本文整理汇总了Python中jira.JIRA.comments方法的典型用法代码示例。如果您正苦于以下问题:Python JIRA.comments方法的具体用法?Python JIRA.comments怎么用?Python JIRA.comments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jira.JIRA
的用法示例。
在下文中一共展示了JIRA.comments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestIssues
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import comments [as 别名]
class TestIssues(unittest.TestCase):
def setUp(self):
self.jira = JIRA(options=dict(server=TEST_URL, verify=False), basic_auth=(TEST_USERNAME, TEST_PASSWORD))
self.issue1 = self.jira.create_issue(
project='KB',
summary='Test-1',
issuetype={'name': 'Bug'},
)
self.issue2 = self.jira.create_issue(
project='KB',
summary='Test-2',
issuetype={'name': 'Bug'},
)
def tearDown(self):
issues = self.jira.search_issues('project = "KB" AND summary ~ "Test*"', fields=['key'])
for _ in issues:
_.delete()
def assert_single_attachment(self):
# TODO - Find how to test this automatically
pass
def assert_single_comment_with(self, text):
comments = self.jira.comments(self.issue1.key)
self.assertEqual(len(comments), 1)
self.assertIn(text, comments[0].body)
def test_new(self):
result = CliRunner().invoke(topcli, ['issue', 'new', 'KB', 'task', 'Test-new'])
self.assertEqual(result.exit_code, 0)
issues = self.jira.search_issues('project = "KB" AND summary ~ "Test-new"', fields=['key', 'summary'])
self.assertEqual(len(issues), 1)
self.assertIn(issues[0].key, result.output)
def test_transition(self):
result = CliRunner().invoke(topcli, ['issue', 'transition', self.issue1.key, 'Done'])
self.assertEqual(result.exit_code, 0)
def test_assign(self):
result = CliRunner().invoke(topcli, ['issue', 'assign', self.issue1.key, TEST_USERNAME])
self.assertEqual(result.exit_code, 0)
assignee = self.jira.issue(self.issue1.key, fields=['assignee']).fields.assignee
self.assertEqual(assignee.key, TEST_USERNAME)
def test_unassign(self):
result = CliRunner().invoke(topcli, ['issue', 'assign', self.issue1.key, TEST_USERNAME])
result = CliRunner().invoke(topcli, ['issue', 'unassign', self.issue1.key])
self.assertEqual(result.exit_code, 0)
assignee = self.jira.issue(self.issue1.key, fields=['assignee']).fields.assignee
self.assertIsNone(assignee)
def test_attach_file(self):
with CliRunner().isolated_filesystem() as dir_path:
with open('data.txt', 'w') as f:
print('abc', file=f)
result = CliRunner().invoke(topcli, ['issue', 'attach', self.issue1.key, 'data.txt'])
self.assertEqual(result.exit_code, 0)
self.assert_single_attachment()
def test_comment_args(self):
result = CliRunner().invoke(topcli, ['issue', 'comment', self.issue1.key, 'Comment', 'from args'])
self.assertEqual(result.exit_code, 0)
self.assert_single_comment_with('Comment from args')
def test_comment_file(self):
with CliRunner().isolated_filesystem() as dir_path:
with open('comment.txt', 'w') as f:
print('Comment from file', file=f)
result = CliRunner().invoke(topcli, ['issue', 'comment', self.issue1.key, 'comment.txt'])
self.assertEqual(result.exit_code, 0)
self.assert_single_comment_with('Comment from file')
def test_comment_prompt(self):
result = CliRunner().invoke(topcli, ['issue', 'comment', self.issue1.key], input='Comment from prompt\n')
self.assertEqual(result.exit_code, 0)
self.assert_single_comment_with('Comment from prompt')
def test_comment_stdin(self):
result = CliRunner().invoke(topcli, ['issue', 'comment', self.issue1.key, '-'], input='Comment\nfrom\nstdin')
self.assertEqual(result.exit_code, 0)
self.assert_single_comment_with('Comment\nfrom\nstdin')
def test_link(self):
result = CliRunner().invoke(topcli, ['issue', 'link', self.issue1.key, self.issue2.key, '-t', 'duplicates'])
self.assertEqual(result.exit_code, 0)
links = self.jira.issue(self.issue1.key, fields=['issuelinks']).fields.issuelinks
self.assertEqual(len(links), 1)
self.assertEqual(links[0].outwardIssue.key, self.issue2.key)
self.assertEqual(links[0].type.outward, 'duplicates')
def test_unlink(self):
result = CliRunner().invoke(topcli, ['issue', 'link', self.issue1.key, self.issue2.key, '-t', 'duplicates'])
self.assertEqual(result.exit_code, 0)
result = CliRunner().invoke(topcli, ['issue', 'unlink', self.issue1.key, self.issue2.key])
links = self.jira.issue(self.issue1.key, fields=['issuelinks']).fields.issuelinks
self.assertEqual(len(links), 0)
def test_search_issue(self):
result = CliRunner().invoke(topcli, ['issue', 'search'])
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from jira import JIRA [as 别名]
# 或者: from jira.JIRA import comments [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)