当前位置: 首页>>代码示例>>Python>>正文


Python comments.CommentAPI类代码示例

本文整理汇总了Python中osclib.comments.CommentAPI的典型用法代码示例。如果您正苦于以下问题:Python CommentAPI类的具体用法?Python CommentAPI怎么用?Python CommentAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CommentAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_select_comments

    def test_select_comments(self):
        c_api = CommentAPI(self.api.apiurl)
        staging_b = 'openSUSE:Factory:Staging:B'
        comments = c_api.get_comments(project_name=staging_b)

        # First select
        self.assertEqual(True, SelectCommand(self.api).perform(staging_b, ['gcc', 'wine']))
        first_select_comments = c_api.get_comments(project_name=staging_b)
        last_id = sorted(first_select_comments.keys())[-1]
        first_select_comment = first_select_comments[last_id]
        # Only one comment is added
        self.assertEqual(len(first_select_comments), len(comments) + 1)
        # With the right content
        self.assertTrue('Request#123 for package gcc submitted by @Admin' in first_select_comment['comment'])

        # Second select
        self.assertEqual(True, SelectCommand(self.api).perform(staging_b, ['puppet']))
        second_select_comments = c_api.get_comments(project_name=staging_b)
        last_id = sorted(second_select_comments.keys())[-1]
        second_select_comment = second_select_comments[last_id]
        # The number of comments remains, but they are different
        self.assertEqual(len(second_select_comments), len(first_select_comments))
        self.assertNotEqual(second_select_comment['comment'], first_select_comment['comment'])
        # The new comments contents both old and new information
        self.assertTrue('Request#123 for package gcc submitted by @Admin' in second_select_comment['comment'])
        self.assertTrue('Request#321 for package puppet submitted by @Admin' in second_select_comment['comment'])
开发者ID:ancorgs,项目名称:osc-plugin-factory,代码行数:26,代码来源:select_tests.py

示例2: IgnoreCommand

class IgnoreCommand(object):
    MESSAGE = 'Ignored: removed from active backlog.'

    def __init__(self, api):
        self.api = api
        self.comment = CommentAPI(self.api.apiurl)

    def perform(self, requests, message=None):
        """
        Ignore a request from "list" and "adi" commands until unignored.
        """

        requests_ignored = self.api.get_ignored_requests()
        length = len(requests_ignored)

        for request_id in RequestFinder.find_sr(requests, self.api):
            if request_id in requests_ignored:
                print('{}: already ignored'.format(request_id))
                continue

            print('{}: ignored'.format(request_id))
            requests_ignored[request_id] = message
            comment = message if message else self.MESSAGE
            self.comment.add_comment(request_id=str(request_id), comment=comment)

        diff = len(requests_ignored) - length
        if diff > 0:
            self.api.set_ignored_requests(requests_ignored)
            print('Ignored {} requests'.format(diff))
        else:
            print('No new requests to ignore')

        return True
开发者ID:dirkmueller,项目名称:osc-plugin-factory,代码行数:33,代码来源:ignore_command.py

示例3: test_select_comments

    def test_select_comments(self):
        self.wf.setup_rings()

        staging_b = self.wf.create_staging('B', freeze=True)

        c_api = CommentAPI(self.wf.api.apiurl)
        comments = c_api.get_comments(project_name=staging_b.name)

        r1 = self.wf.create_submit_request('devel:wine', 'wine')
        r2 = self.wf.create_submit_request('devel:gcc', 'gcc')

        # First select
        self.assertEqual(True, SelectCommand(self.wf.api, staging_b.name).perform(['gcc', 'wine']))
        first_select_comments = c_api.get_comments(project_name=staging_b.name)
        last_id = sorted(first_select_comments.keys())[-1]
        first_select_comment = first_select_comments[last_id]
        # Only one comment is added
        self.assertEqual(len(first_select_comments), len(comments) + 1)
        # With the right content
        expected = 'request#{} for package gcc submitted by Admin'.format(r2.reqid)
        self.assertTrue(expected in first_select_comment['comment'])

        # Second select
        r3 = self.wf.create_submit_request('devel:gcc', 'gcc8')
        self.assertEqual(True, SelectCommand(self.wf.api, staging_b.name).perform(['gcc8']))
        second_select_comments = c_api.get_comments(project_name=staging_b.name)
        last_id = sorted(second_select_comments.keys())[-1]
        second_select_comment = second_select_comments[last_id]
        # The number of comments increased by one
        self.assertEqual(len(second_select_comments) - 1, len(first_select_comments))
        self.assertNotEqual(second_select_comment['comment'], first_select_comment['comment'])
        # The new comments contains new, but not old
        self.assertFalse('request#{} for package gcz submitted by Admin'.format(r2.reqid) in second_select_comment['comment'])
        self.assertTrue('added request#{} for package gcc8 submitted by Admin'.format(r3.reqid) in second_select_comment['comment'])
开发者ID:openSUSE,项目名称:osc-plugin-factory,代码行数:34,代码来源:select_tests.py

示例4: test_select_comments

    def test_select_comments(self):
        c_api = CommentAPI(self.api.apiurl)
        staging_b = 'openSUSE:Factory:Staging:B'
        comments = c_api.get_comments(project_name=staging_b)

        # First select
        self.assertEqual(True, SelectCommand(self.api, staging_b).perform(['gcc', 'wine']))
        first_select_comments = c_api.get_comments(project_name=staging_b)
        last_id = sorted(first_select_comments.keys())[-1]
        first_select_comment = first_select_comments[last_id]
        # Only one comment is added
        self.assertEqual(len(first_select_comments), len(comments) + 1)
        # With the right content
        self.assertTrue('request#123 for package gcc submitted by Admin' in first_select_comment['comment'])

        # Second select
        self.assertEqual(True, SelectCommand(self.api, staging_b).perform(['puppet']))
        second_select_comments = c_api.get_comments(project_name=staging_b)
        last_id = sorted(second_select_comments.keys())[-1]
        second_select_comment = second_select_comments[last_id]
        # The number of comments increased by one
        self.assertEqual(len(second_select_comments) - 1, len(first_select_comments))
        self.assertNotEqual(second_select_comment['comment'], first_select_comment['comment'])
        # The new comments contains new, but not old
        self.assertFalse('request#123 for package gcc submitted by Admin' in second_select_comment['comment'])
        self.assertTrue('added request#321 for package puppet submitted by Admin' in second_select_comment['comment'])
开发者ID:,项目名称:,代码行数:26,代码来源:

示例5: check_comment

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
开发者ID:dirkmueller,项目名称:osc-plugin-factory,代码行数:11,代码来源:status.py

示例6: remind_comment

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)
开发者ID:,项目名称:,代码行数:30,代码来源:

示例7: setUp

 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)}
     }
开发者ID:dirkmueller,项目名称:osc-plugin-factory,代码行数:7,代码来源:comment_tests.py

示例8: __init__

 def __init__(self, *args, **kwargs):
     super(OpenQABot, self).__init__(*args, **kwargs)
     self.tgt_repo = {}
     self.project_settings = {}
     self.api_map = {}
     self.bot_name = 'openqa'
     self.force = False
     self.openqa = None
     self.commentapi = CommentAPI(self.apiurl)
开发者ID:dirkmueller,项目名称:osc-plugin-factory,代码行数:9,代码来源:openqabot.py

示例9: UnignoreCommand

class UnignoreCommand(object):
    MESSAGE = 'Unignored: returned to active backlog.'

    def __init__(self, api):
        self.api = api
        self.comment = CommentAPI(self.api.apiurl)

    def perform(self, requests, cleanup=False):
        """
        Unignore a request by removing from ignore list.
        """

        requests_ignored = self.api.get_ignored_requests()
        length = len(requests_ignored)

        if len(requests) == 1 and requests[0] == 'all':
            requests_ignored = {}
        else:
            for request_id in RequestFinder.find_sr(requests, self.api):
                if request_id in requests_ignored:
                    print('{}: unignored'.format(request_id))
                    del requests_ignored[request_id]
                    self.comment.add_comment(request_id=str(request_id), comment=self.MESSAGE)

        if cleanup:
            now = datetime.now()
            for request_id in set(requests_ignored):
                request = get_request(self.api.apiurl, str(request_id))
                if request.state.name not in ('new', 'review'):
                    changed = dateutil.parser.parse(request.state.when)
                    diff = now - changed
                    if diff.days > 3:
                        print('Removing {} which was {} {} days ago'
                              .format(request_id, request.state.name, diff.days))
                        del requests_ignored[request_id]

        diff = length - len(requests_ignored)
        if diff > 0:
            self.api.set_ignored_requests(requests_ignored)
            print('Unignored {} requests'.format(diff))
        else:
            print('No requests to unignore')

        return True
开发者ID:dirkmueller,项目名称:osc-plugin-factory,代码行数:44,代码来源:unignore_command.py

示例10: test_accept_comments

    def test_accept_comments(self):
        c_api = CommentAPI(self.api.apiurl)
        staging_c = 'openSUSE:Factory:Staging:C'
        comments = c_api.get_comments(project_name=staging_c)

        # Accept staging C (containing apparmor and mariadb)
        self.assertEqual(True, AcceptCommand(self.api).perform(staging_c))

        # Comments are cleared up
        accepted_comments = c_api.get_comments(project_name=staging_c)
        self.assertNotEqual(len(comments), 0)
        self.assertEqual(len(accepted_comments), 0)

        # But the comment was written at some point
        self.assertEqual(len(self.obs.comment_bodies), 1)
        comment = self.obs.comment_bodies[0]
        self.assertTrue('The following packages have been submitted to openSUSE:Factory' in comment)
        self.assertTrue('apparmor' in comment)
        self.assertTrue('mariadb' in comment)
开发者ID:bluca,项目名称:osc-plugin-factory,代码行数:19,代码来源:accept_tests.py

示例11: setUp

    def setUp(self):
        super(TestReviewBotComment, 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))])
        self.review_bot = ReviewBot(self.apiurl, logger=logging.getLogger(self.bot))
        self.review_bot.bot_name = self.bot

        self.osc_user('factory-auto')
开发者ID:,项目名称:,代码行数:10,代码来源:

示例12: setUp

 def setUp(self):
     super(TestCommentOBS, self).setUp()
     self.wf = OBSLocal.StagingWorkflow()
     self.wf.create_user('factory-auto')
     self.wf.create_user('repo-checker')
     self.wf.create_user('staging-bot')
     self.wf.create_group('factory-staging', ['staging-bot'])
     self.wf.create_project(PROJECT, maintainer={'groups': ['factory-staging']})
     self.api = CommentAPI(self.apiurl)
     # Ensure different test runs operate in unique namespace.
     self.bot = '::'.join([type(self).__name__, str(random.getrandbits(8))])
开发者ID:openSUSE,项目名称:osc-plugin-factory,代码行数:11,代码来源:comment_tests.py

示例13: TestAccept

class TestAccept(unittest.TestCase):

    def setup_vcr(self):
        wf = OBSLocal.StagingWorkflow()
        wf.setup_rings()

        self.c_api = CommentAPI(wf.api.apiurl)

        staging_b = wf.create_staging('B', freeze=True)
        self.prj = staging_b.name

        self.winerq = wf.create_submit_request('devel:wine', 'wine', text='Hallo World')
        self.assertEqual(True, SelectCommand(wf.api, self.prj).perform(['wine']))
        self.comments = self.c_api.get_comments(project_name=self.prj)
        self.assertGreater(len(self.comments), 0)
        return wf

    def test_accept_comments(self):
        wf = self.setup_vcr()

        self.assertEqual(True, AcceptCommand(wf.api).perform(self.prj))

        # Comments are cleared up
        accepted_comments = self.c_api.get_comments(project_name=self.prj)
        self.assertEqual(len(accepted_comments), 0)

    def test_accept_final_comment(self):
        wf = self.setup_vcr()

        # snipe out cleanup to see the comments before the final countdown
        wf.api.staging_deactivate = MagicMock(return_value=True)

        self.assertEqual(True, AcceptCommand(wf.api).perform(self.prj))

        comments = self.c_api.get_comments(project_name=self.prj)
        self.assertGreater(len(comments), len(self.comments))

        # check which id was added
        new_id = (set(comments.keys()) - set(self.comments.keys())).pop()
        comment = comments[new_id]['comment']
        self.assertEqual('Project "{}" accepted. The following packages have been submitted to openSUSE:Factory: wine.'.format(self.prj), comment)
开发者ID:openSUSE,项目名称:osc-plugin-factory,代码行数:41,代码来源:accept_tests.py

示例14: setUp

    def setUp(self):
        super(TestReviewBotComment, self).setUp()
        self.api = CommentAPI(self.apiurl)
        self.wf = OBSLocal.StagingWorkflow()
        self.wf.create_user('factory-auto')
        self.project = self.wf.create_project(PROJECT)

        # Ensure different test runs operate in unique namespace.
        self.bot = '::'.join([type(self).__name__, str(random.getrandbits(8))])
        self.review_bot = ReviewBot(self.apiurl, logger=logging.getLogger(self.bot))
        self.review_bot.bot_name = self.bot

        self.osc_user('factory-auto')
开发者ID:openSUSE,项目名称:osc-plugin-factory,代码行数:13,代码来源:ReviewBot_tests.py

示例15: setup_vcr

    def setup_vcr(self):
        wf = OBSLocal.StagingWorkflow()
        wf.setup_rings()

        self.c_api = CommentAPI(wf.api.apiurl)

        staging_b = wf.create_staging('B', freeze=True)
        self.prj = staging_b.name

        self.winerq = wf.create_submit_request('devel:wine', 'wine', text='Hallo World')
        self.assertEqual(True, SelectCommand(wf.api, self.prj).perform(['wine']))
        self.comments = self.c_api.get_comments(project_name=self.prj)
        self.assertGreater(len(self.comments), 0)
        return wf
开发者ID:openSUSE,项目名称:osc-plugin-factory,代码行数:14,代码来源:accept_tests.py


注:本文中的osclib.comments.CommentAPI类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。