本文整理汇总了Python中osclib.comments.CommentAPI.add_marker方法的典型用法代码示例。如果您正苦于以下问题:Python CommentAPI.add_marker方法的具体用法?Python CommentAPI.add_marker怎么用?Python CommentAPI.add_marker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osclib.comments.CommentAPI
的用法示例。
在下文中一共展示了CommentAPI.add_marker方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remind_comment
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import add_marker [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: StagingReport
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import add_marker [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()
#.........这里部分代码省略.........
示例3: TestComment
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import add_marker [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)
示例4: TestCommentOBS
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import add_marker [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: ReviewBot
# 需要导入模块: from osclib.comments import CommentAPI [as 别名]
# 或者: from osclib.comments.CommentAPI import add_marker [as 别名]
#.........这里部分代码省略.........
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:
self.comment_api.add_comment(comment=message, **kwargs)
self.comment_handler_remove()
def _check_matching_srcmd5(self, project, package, rev, history_limit = 5):
"""check if factory sources contain the package and revision. check head and history"""