本文整理汇总了Python中osclib.comments.CommentAPI.comment_find方法的典型用法代码示例。如果您正苦于以下问题:Python CommentAPI.comment_find方法的具体用法?Python CommentAPI.comment_find怎么用?Python CommentAPI.comment_find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osclib.comments.CommentAPI
的用法示例。
在下文中一共展示了CommentAPI.comment_find方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remind_comment
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import comment_find [as 别名]
def remind_comment(apiurl, repeat_age, request_id, project, package=None):
comment_api = CommentAPI(apiurl)
comments = comment_api.get_comments(request_id=request_id)
comment, _ = comment_api.comment_find(comments, BOT_NAME)
if comment:
delta = datetime.utcnow() - comment['when']
if delta.days < repeat_age:
print(' skipping due to previous reminder from {} days ago'.format(delta.days))
return
# Repeat notification so remove old comment.
try:
comment_api.delete(comment['id'])
except HTTPError as e:
if e.code == 403:
# Gracefully skip when previous reminder was by another user.
print(' unable to remove previous reminder')
return
raise e
userids = sorted(maintainers_get(apiurl, project, package))
if len(userids):
users = ['@' + userid for userid in userids]
message = '{}: {}'.format(', '.join(users), REMINDER)
else:
message = REMINDER
print(' ' + message)
message = comment_api.add_marker(message, BOT_NAME)
comment_api.add_comment(request_id=request_id, comment=message)
示例2: check_comment
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import comment_find [as 别名]
def check_comment(apiurl, bot, **kwargs):
if not len(kwargs):
return False
api = CommentAPI(apiurl)
comments = api.get_comments(**kwargs)
comment = api.comment_find(comments, bot)[0]
if comment:
return (datetime.utcnow() - comment['when']).total_seconds()
return False
示例3: StagingReport
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import comment_find [as 别名]
class StagingReport(object):
def __init__(self, api):
self.api = api
self.comment = CommentAPI(api.apiurl)
def _package_url(self, package):
link = '/package/live_build_log/%s/%s/%s/%s'
link = link % (package['project'],
package['package'],
package['repository'],
package['arch'])
text = '[%s](%s)' % (package['arch'], link)
return text
def old_enough(self, _date):
time_delta = datetime.utcnow() - _date
safe_margin = timedelta(hours=MARGIN_HOURS)
return safe_margin <= time_delta
def update_status_comment(self, project, report, force=False, only_replace=False):
report = self.comment.add_marker(report, MARKER)
comments = self.comment.get_comments(project_name=project)
comment, _ = self.comment.comment_find(comments, MARKER)
if comment:
write_comment = (report != comment['comment'] and self.old_enough(comment['when']))
else:
write_comment = not only_replace
if write_comment or force:
if osc.conf.config['debug']:
print('Updating comment')
if comment:
self.comment.delete(comment['id'])
self.comment.add_comment(project_name=project, comment=report)
def _report_broken_packages(self, info):
broken_package_status = info['broken_packages']
# Group packages by name
groups = defaultdict(list)
for package in broken_package_status:
groups[package['package']].append(package)
failing_lines = [
'* Build failed %s (%s)' % (key, ', '.join(self._package_url(p) for p in value))
for key, value in groups.iteritems()
]
report = '\n'.join(failing_lines[:MAX_LINES])
if len(failing_lines) > MAX_LINES:
report += '* and more (%s) ...' % (len(failing_lines) - MAX_LINES)
return report
def report_checks(self, info):
failing_lines, green_lines = [], []
links_state = {}
for check in info['checks']:
links_state.setdefault(check['state'], [])
links_state[check['state']].append('[{}]({})'.format(check['name'], check['url']))
lines = []
failure = False
for state, links in links_state.items():
if len(links) > MAX_LINES:
extra = len(links) - MAX_LINES
links = links[:MAX_LINES]
links.append('and {} more...'.format(extra))
lines.append('- {}'.format(state))
if state != 'success':
lines.extend([' - {}'.format(link) for link in links])
failure = True
else:
lines[-1] += ': {}'.format(', '.join(links))
return '\n'.join(lines).strip(), failure
def report(self, project, aggregate=True, force=False):
info = self.api.project_status(project, aggregate)
# Do not attempt to process projects without staging info, or projects
# in a pending state that will change before settling. This avoids
# intermediate notifications that may end up being spammy and for
# long-lived stagings where checks may be re-triggered multiple times
# and thus enter pending state (not seen on first run) which is not
# useful to report.
if not info or not self.api.project_status_final(info):
return
report_broken_packages = self._report_broken_packages(info)
report_checks, check_failure = self.report_checks(info)
if report_broken_packages or check_failure:
if report_broken_packages:
report_broken_packages = 'Broken:\n\n' + report_broken_packages
if report_checks:
report_checks = 'Checks:\n\n' + report_checks
report = '\n\n'.join((report_broken_packages, report_checks))
report = report.strip()
#.........这里部分代码省略.........
示例4: TestCommentOBS
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import comment_find [as 别名]
class TestCommentOBS(OBSLocalTestCase):
def setUp(self):
super(TestCommentOBS, self).setUp()
self.api = CommentAPI(self.apiurl)
# Ensure different test runs operate in unique namespace.
self.bot = '::'.join([type(self).__name__, str(random.getrandbits(8))])
def test_basic(self):
self.osc_user('staging-bot')
self.assertFalse(self.comments_filtered(self.bot)[0])
self.assertTrue(self.api.add_comment(
project_name=PROJECT, comment=self.api.add_marker(COMMENT, self.bot)))
comment, _ = self.comments_filtered(self.bot)
self.assertTrue(comment)
self.assertTrue(self.api.delete(comment['id']))
self.assertFalse(self.comments_filtered(self.bot)[0])
def test_delete_nested(self):
self.osc_user('staging-bot')
comment_marked = self.api.add_marker(COMMENT, self.bot)
# Allow for existing comments by basing assertion on delta from initial count.
comment_count = len(self.api.get_comments(project_name=PROJECT))
self.assertFalse(self.comments_filtered(self.bot)[0])
self.assertTrue(self.api.add_comment(project_name=PROJECT, comment=comment_marked))
comment, _ = self.comments_filtered(self.bot)
self.assertTrue(comment)
for i in range(0, 3):
self.assertTrue(self.api.add_comment(
project_name=PROJECT, comment=comment_marked, parent_id=comment['id']))
comments = self.api.get_comments(project_name=PROJECT)
parented_count = 0
for comment in comments.values():
if comment['parent']:
parented_count += 1
self.assertEqual(parented_count, 3)
self.assertTrue(len(comments) == comment_count + 4)
self.api.delete_from(project_name=PROJECT)
self.assertFalse(len(self.api.get_comments(project_name=PROJECT)))
def test_delete_batch(self):
users = ['factory-auto', 'repo-checker', 'staging-bot']
for user in users:
self.osc_user(user)
from osc import conf
bot = '::'.join([self.bot, user])
comment = self.api.add_marker(COMMENT, bot)
self.assertFalse(self.comments_filtered(bot)[0])
self.assertTrue(self.api.add_comment(project_name=PROJECT, comment=comment))
self.assertTrue(self.comments_filtered(bot)[0])
# Allow for existing comments by basing assertion on delta from initial count.
comment_count = len(self.api.get_comments(project_name=PROJECT))
self.assertTrue(comment_count >= len(users))
self.api.delete_from_where_user(users[0], project_name=PROJECT)
self.assertTrue(len(self.api.get_comments(project_name=PROJECT)) == comment_count - 1)
self.api.delete_from(project_name=PROJECT)
self.assertFalse(len(self.api.get_comments(project_name=PROJECT)))
def comments_filtered(self, bot):
comments = self.api.get_comments(project_name=PROJECT)
return self.api.comment_find(comments, bot)
示例5: TestComment
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import comment_find [as 别名]
class TestComment(unittest.TestCase):
def setUp(self):
self.api = CommentAPI('bogus')
self.bot = type(self).__name__
self.comments = {
1: {'comment': '<!-- {} -->\n\nshort comment'.format(self.bot)},
2: {'comment': '<!-- {} foo=bar distro=openSUSE -->\n\nshort comment'.format(self.bot)}
}
def test_truncate(self):
comment = "string of text"
for i in xrange(len(comment) + 1):
truncated = self.api.truncate(comment, length=i)
print(truncated)
self.assertEqual(len(truncated), i)
def test_truncate_pre(self):
comment = """
Some text.
<pre>
bar
mar
car
</pre>
## section 2
<pre>
more
lines
than
you
can
handle
</pre>
""".strip()
for i in xrange(len(comment) + len('...\n</pre>')):
truncated = self.api.truncate(comment, length=i)
print('=' * 80)
print(truncated)
self.assertTrue(len(truncated) <= i, '{} <= {}'.format(len(truncated), i))
self.assertEqual(truncated.count('<pre>'), truncated.count('</pre>'))
self.assertFalse(len(re.findall(r'</?\w+[^\w>]', truncated)))
tag_count = truncated.count('<pre>') + truncated.count('</pre>')
self.assertEqual(tag_count, truncated.count('<'))
self.assertEqual(tag_count, truncated.count('>'))
def test_add_marker(self):
comment_marked = self.api.add_marker(COMMENT, self.bot)
self.assertEqual(comment_marked, self.comments[1]['comment'])
comment_marked = self.api.add_marker(COMMENT, self.bot, COMMENT_INFO)
self.assertEqual(comment_marked, self.comments[2]['comment'])
def test_remove_marker(self):
comment = self.api.remove_marker(COMMENT)
self.assertEqual(comment, COMMENT)
comment = self.api.remove_marker(self.comments[1]['comment'])
self.assertEqual(comment, COMMENT)
comment = self.api.remove_marker(self.comments[2]['comment'])
self.assertEqual(comment, COMMENT)
def test_comment_find(self):
comment, info = self.api.comment_find(self.comments, self.bot)
self.assertEqual(comment, self.comments[1])
comment, info = self.api.comment_find(self.comments, self.bot, COMMENT_INFO)
self.assertEqual(comment, self.comments[2])
self.assertEqual(info, COMMENT_INFO)
info_partial = dict(COMMENT_INFO)
del info_partial['foo']
comment, info = self.api.comment_find(self.comments, self.bot, info_partial)
self.assertEqual(comment, self.comments[2])
self.assertEqual(info, COMMENT_INFO)
示例6: OpenQABot
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import comment_find [as 别名]
#.........这里部分代码省略.........
self.comment_write(state='done', message=msg, request=req, result='accepted')
return True
else:
self.logger.debug("request {} waits for build".format(req.reqid))
elif qa_state == QA_FAILED or qa_state == QA_PASSED:
if qa_state == QA_PASSED:
msg = "openQA tests passed\n"
result = 'accepted'
ret = True
else:
msg = "openQA tests problematic\n"
result = 'declined'
ret = False
msg += self.summarize_openqa_jobs(jobs)
self.comment_write(state='done', message=msg, result=result, request=req)
return ret
elif qa_state == QA_INPROGRESS:
self.logger.info("request %s still in progress", req.reqid)
else:
raise Exception("unknown QA state %d", qa_state)
except Exception:
import traceback
self.logger.error("unhandled exception in openQA Bot")
self.logger.error(traceback.format_exc())
return None
return
def find_obs_request_comment(self, request_id=None, project_name=None):
"""Return previous comments (should be one)."""
comments = self.commentapi.get_comments(request_id=request_id, project_name=project_name)
comment, info = self.commentapi.comment_find(comments, self.bot_name)
if comment:
# we only care for two fields
return {'id': comment['id'], 'revision': info['revision']}
return {}
def check_product_arch(self, job, product_prefix, pmap, arch):
need = False
settings = {'VERSION': pmap['version']}
settings['ARCH'] = arch if arch else 'x86_64'
settings['DISTRI'] = pmap.get('distri', 'sle')
issues = pmap.get('issues', {})
issues['OS_TEST_ISSUES'] = issues.get('OS_TEST_ISSUES', product_prefix)
required_issue = pmap.get('required_issue', False)
for key, prefix in issues.items():
# self.logger.debug("KP {} {}".format(key, prefix) + str(job))
channel = prefix
if arch:
channel += arch
if channel in job['channels']:
settings[key] = str(job['id'])
need = True
if required_issue:
if required_issue not in settings:
need = False
if not need:
return []
product_key = product_prefix
if arch:
product_key += arch
示例7: TestReviewBotComment
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import comment_find [as 别名]
#.........这里部分代码省略.........
# Only build change (expect no change).
info_extra = {'build': '2'}
self.review_bot.comment_write(state='seen', result='failed', identical=True,
info_extra=info_extra, info_extra_identical=False,
project=PROJECT, message=COMMENT)
comment, info_parsed = self.comments_filtered(self.bot)
self.assertTrue(comment['comment'].endswith(COMMENT))
self.assertEqual(info_parsed, info_merged)
# Build and comment (except comment replacement).
info_extra = {'build': '3'}
info_merged.update(info_extra)
self.review_bot.comment_write(state='seen', result='failed', identical=True,
info_extra=info_extra, info_extra_identical=False,
project=PROJECT, message=COMMENT + '3')
comment, info_parsed = self.comments_filtered(self.bot)
self.assertTrue(comment['comment'].endswith(COMMENT + '3'))
self.assertEqual(info_parsed, info_merged)
# Final build (except comment replacement).
info_extra = {'build': '4'}
info_merged.update(info_extra)
self.review_bot.comment_write(state='seen', result='failed', identical=True,
info_extra=info_extra, info_extra_identical=True,
project=PROJECT, message=COMMENT + '4')
comment, info_parsed = self.comments_filtered(self.bot)
self.assertTrue(comment['comment'].endswith(COMMENT + '4'))
self.assertEqual(info_parsed, info_merged)
# Final build (except comment replacement).
info = {'state': 'done', 'result': 'passed'}
info_extra = {'build': '5'}
info_merged = info.copy()
info_merged.update(info_extra)
self.review_bot.comment_write(state='done', result='passed', identical=True,
info_extra=info_extra, info_extra_identical=True,
only_replace=True,
project=PROJECT, message=COMMENT + '5')
comment, info_parsed = self.comments_filtered(self.bot)
self.assertTrue(comment['comment'].endswith(COMMENT + '5'))
self.assertEqual(info_parsed, info_merged)
# Should never be more than one new comment.
self.assertEqual(len(self.api.get_comments(project_name=PROJECT)), comment_count + 1)
def test_only_replace_none(self):
self.review_bot.comment_write(only_replace=True,
project=PROJECT, message=COMMENT)
self.assertFalse(self.comments_filtered(self.bot)[0])
def test_dryrun(self):
# dryrun = True, no comment.
self.review_bot.dryrun = True
self.review_bot.comment_write(project=PROJECT, message=COMMENT)
self.assertFalse(self.comments_filtered(self.bot)[0])
# dryrun = False, a comment.
self.review_bot.dryrun = False
self.review_bot.comment_write(project=PROJECT, message=COMMENT)
self.assertTrue(self.comments_filtered(self.bot)[0])
# dryrun = True, no replacement.
self.review_bot.dryrun = True
self.review_bot.comment_write(state='changed', project=PROJECT, message=COMMENT)
_, info = self.comments_filtered(self.bot)
self.assertEqual(info['state'], 'done')
# dryrun = False, replacement.
self.review_bot.dryrun = False
self.review_bot.comment_write(state='changed', project=PROJECT, message=COMMENT)
_, info = self.comments_filtered(self.bot)
self.assertEqual(info['state'], 'changed')
def test_bot_name_suffix(self):
suffix1 = 'suffix1'
bot_suffixed1 = '::'.join([self.bot, suffix1])
suffix2 = 'suffix2'
bot_suffixed2 = '::'.join([self.bot, suffix2])
self.review_bot.comment_write(bot_name_suffix=suffix1, project=PROJECT, message=COMMENT)
self.assertFalse(self.comments_filtered(self.bot)[0])
self.assertTrue(self.comments_filtered(bot_suffixed1)[0])
self.assertFalse(self.comments_filtered(bot_suffixed2)[0])
self.review_bot.comment_write(bot_name_suffix=suffix2, project=PROJECT, message=COMMENT)
self.assertFalse(self.comments_filtered(self.bot)[0])
self.assertTrue(self.comments_filtered(bot_suffixed1)[0])
self.assertTrue(self.comments_filtered(bot_suffixed2)[0])
self.review_bot.comment_write(bot_name_suffix=suffix1, project=PROJECT, message=COMMENT + '\nnew')
comment, _ = self.comments_filtered(bot_suffixed1)
self.assertTrue(comment['comment'].endswith(COMMENT + '\nnew'))
comment, _ = self.comments_filtered(bot_suffixed2)
self.assertTrue(comment['comment'].endswith(COMMENT))
def comments_filtered(self, bot):
comments = self.api.get_comments(project_name=PROJECT)
return self.api.comment_find(comments, bot)
示例8: ReviewBot
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import comment_find [as 别名]
#.........这里部分代码省略.........
may be set to True to automatically set one on each request.
The previous comment body line count is compared to see if too similar
to bother posting another comment which is useful for avoiding
re-posting comments that contain irrelevant minor changes. To force an
exact match use the identical flag to replace any non-identical
comment body.
"""
if project:
kwargs = {'project_name': project}
if package:
kwargs['package_name'] = package
else:
if request is None:
request = self.request
kwargs = {'request_id': request.reqid}
debug_key = '/'.join(kwargs.values())
if message is None:
if not len(self.comment_handler.lines):
self.logger.debug('skipping empty comment for {}'.format(debug_key))
return
message = '\n\n'.join(self.comment_handler.lines)
bot_name = self.bot_name
if bot_name_suffix:
bot_name = '::'.join([bot_name, bot_name_suffix])
info = {'state': state, 'result': result}
if info_extra and info_extra_identical:
info.update(info_extra)
comments = self.comment_api.get_comments(**kwargs)
comment, _ = self.comment_api.comment_find(comments, bot_name, info)
if info_extra and not info_extra_identical:
# Add info_extra once comment has already been matched.
info.update(info_extra)
message = self.comment_api.add_marker(message, bot_name, info)
message = self.comment_api.truncate(message.strip())
if (comment is not None and
((identical and
# Remove marker from comments since handled during comment_find().
self.comment_api.remove_marker(comment['comment']) ==
self.comment_api.remove_marker(message)) or
(not identical and comment['comment'].count('\n') == message.count('\n')))
):
# Assume same state/result and number of lines in message is duplicate.
self.logger.debug('previous comment too similar on {}'.format(debug_key))
return
if comment is None:
self.logger.debug('broadening search to include any state on {}'.format(debug_key))
comment, _ = self.comment_api.comment_find(comments, bot_name)
if comment is not None:
self.logger.debug('removing previous comment on {}'.format(debug_key))
if not self.dryrun:
self.comment_api.delete(comment['id'])
elif only_replace:
self.logger.debug('no previous comment to replace on {}'.format(debug_key))
return
self.logger.debug('adding comment to {}: {}'.format(debug_key, message))
if not self.dryrun: