Exemplo n.º 1
0
 def __init__(self) -> None:
     self.loop = asyncio.get_event_loop()
     self.g = GerritStreamEvents()
     self.parser = GerritStreamParser()
     self.args = Args()
     log.info("Using '%s' configuration", self.args.config_section)
     config = Config(self.args.config_section)
     self.jira_closer = JiraCloser(config)
Exemplo n.º 2
0
class Bot:
    def __init__(self) -> None:
        self.loop = asyncio.get_event_loop()
        self.g = GerritStreamEvents()
        self.parser = GerritStreamParser()
        self.args = Args()
        log.info("Using '%s' configuration", self.args.config_section)
        config = Config(self.args.config_section)
        self.jira_closer = JiraCloser(config)

    async def update_project(self,
                             name: str,
                             since: Optional[str] = None) -> None:
        async with Repository(name) as repo:
            changes = await repo.new_changes(since=since)
            for change in changes:
                log.info("Checking changes for relevant tags: '%s'", change)
                # check commit message
                fixes = await repo.parse_commit_messages(change)
                for fix in fixes:
                    # do jira magic
                    self.jira_closer.run(fix)

    async def event_handler(self, data: str) -> None:
        event = self.parser.parse(data)
        log.debug(event)
        log.debug("Raw data: >>>%s<<<", data)
        if event and event.type == 'ref-updated' and 'staging' not in event.branch:
            log.info(event)
            await self.update_project(event.project)

    async def check_gerrit_projects(self) -> None:
        projects = await (self.g.list_all_projects())
        # we could parallelize, but we cannot have too many git connections
        # at the same time, and this is not the common case, so do it sequential for now.
        # updates = []
        # for project in projects:
        #     updates.append(self.update_project(project))
        # await asyncio.gather(*updates)
        for project in projects:
            await self.update_project(project, since=self.args.since)

    def run(self) -> None:
        while True:
            try:
                check_projects_on_startup = asyncio.ensure_future(
                    self.check_gerrit_projects())
                self.g.setDataCallback(self.event_handler)
                run_monitor = asyncio.ensure_future(self.g.run())
                self.loop.run_until_complete(
                    asyncio.gather(check_projects_on_startup, run_monitor))
            except Exception as exc:
                log.exception('Caught exception: ' + str(exc))
Exemplo n.º 3
0
Arquivo: bot.py Projeto: qt/qtqa
class Bot:
    def __init__(self) -> None:
        self.loop = asyncio.get_event_loop()
        self.g = GerritStreamEvents()
        self.parser = GerritStreamParser()
        self.args = Args()
        log.info("Using '%s' configuration", self.args.config_section)
        config = Config(self.args.config_section)
        self.jira_closer = JiraCloser(config)

    async def update_project(self, name: str, since: Optional[str] = None) -> None:
        async with Repository(name) as repo:
            changes = await repo.new_changes(since=since)
            for change in changes:
                log.info("Checking changes for relevant tags: '%s'", change)
                # check commit message
                fixes = await repo.parse_commit_messages(change)
                for fix in fixes:
                    # do jira magic
                    self.jira_closer.run(fix)

    async def event_handler(self, data: str) -> None:
        event = self.parser.parse(data)
        log.debug(event)
        log.debug("Raw data: >>>%s<<<", data)
        if event and event.type == 'ref-updated' and 'staging' not in event.branch:
            log.info(event)
            await self.update_project(event.project)

    async def check_gerrit_projects(self) -> None:
        projects = await(self.g.list_all_projects())
        # we could parallelize, but we cannot have too many git connections
        # at the same time, and this is not the common case, so do it sequential for now.
        # updates = []
        # for project in projects:
        #     updates.append(self.update_project(project))
        # await asyncio.gather(*updates)
        for project in projects:
            await self.update_project(project, since=self.args.since)

    def run(self) -> None:
        while True:
            try:
                check_projects_on_startup = asyncio.ensure_future(self.check_gerrit_projects())
                self.g.setDataCallback(self.event_handler)
                run_monitor = asyncio.ensure_future(self.g.run())
                self.loop.run_until_complete(asyncio.gather(check_projects_on_startup, run_monitor))
            except Exception as exc:
                log.exception('Caught exception: ' + str(exc))
Exemplo n.º 4
0
Arquivo: bot.py Projeto: qt/qtqa
 def __init__(self) -> None:
     self.loop = asyncio.get_event_loop()
     self.g = GerritStreamEvents()
     self.parser = GerritStreamParser()
     self.args = Args()
     log.info("Using '%s' configuration", self.args.config_section)
     config = Config(self.args.config_section)
     self.jira_closer = JiraCloser(config)
Exemplo n.º 5
0
def test_close_issue():
    config = Config('test')
    j = JiraCloser(config)
    issue_key = 'QTBUG-4795'

    issue = j.jira_client.issue(issue_key)

    if issue.fields.status.name != 'Open':
        log.info('Re-opening issue from "%s"', issue.fields.status)
        if issue.fields.status.name == 'In Progress':
            j.jira_client.transition_issue(issue.key, transition='Stop Work')
        else:
            j.jira_client.transition_issue(issue_key, transition='Re-open')
    # clear fix versions and commits
    issue.update(fields={'fixVersions': [], 'customfield_10142': ''})

    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Open'
    fix = FixedByTag(repository='foo/bar',
                     branch='dev',
                     version='5.13.0',
                     sha1='bd0279c4173eb627d432d9a05411bbc725240d4e',
                     task_numbers=[],
                     fixes=['CON-5'],
                     author='Some One',
                     subject='Close a test issue')
    j._update_issue_with_retry(fix, issue_key, fixes=True)

    # This issue was re-opened, by default we will only post a comment but not re-open it again
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Open'

    j._update_issue_with_retry(fix,
                               issue_key,
                               fixes=True,
                               ignore_reopened=True)

    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Closed'
    assert issue.fields.resolution.name == 'Done'
    assert len(issue.fields.fixVersions) == 1
    assert issue.fields.fixVersions[0].name.startswith('5.13.0')
    assert issue.fields.customfield_10142 == 'bd0279c4173eb627d432d9a05411bbc725240d4e (foo/bar/dev)'

    j.jira_client.transition_issue(issue_key, transition='Re-open')
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Open'
    assert not issue.fields.resolution

    # Assign to bot and start work
    assert j.jira_client.assign_issue(issue.key, assignee='qtgerritbot')
    j.jira_client.transition_issue(issue_key, transition='Start Work')
    j._update_issue_with_retry(fix, issue_key, True, ignore_reopened=True)
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Closed'
    assert issue.fields.resolution.name == 'Done'

    # Close it a second time (and that should just do nothing, not raise an exception)
    j._update_issue_with_retry(fix, issue_key, True)
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Closed'
    assert issue.fields.resolution.name == 'Done'

    # Sometimes we have less sensical fix versions set already, such as "Some future release".
    # Make sure that doesn't bother the bot.
    j.jira_client.transition_issue(issue_key, transition='Re-open')
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Open'
    assert not issue.fields.resolution
    version_some_future_release = '11533'
    issue.update(fields={'fixVersions': [{'id': version_some_future_release}]})
    issue = j.jira_client.issue(issue_key)
    assert len(issue.fields.fixVersions) == 1

    j._update_issue_with_retry(fix, issue_key, True, ignore_reopened=True)
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Closed'
    assert issue.fields.resolution.name == 'Done'
    # Verify that the new fix version was added and the "some future release" is still there.
    assert len(issue.fields.fixVersions) == 2
Exemplo n.º 6
0
def test_close_issue():
    config = Config('test')
    j = JiraCloser(config)
    issue_key = 'QTBUG-4795'

    issue = j.jira_client.issue(issue_key)

    if issue.fields.status.name != 'Open':
        log.info('Re-opening issue from "%s"', issue.fields.status)
        if issue.fields.status.name == 'In Progress':
            j.jira_client.transition_issue(issue.key, transition='Stop Work')
        else:
            j.jira_client.transition_issue(issue_key, transition='Re-open')
    # clear fix versions and commits
    issue.update(fields={'fixVersions': [], 'customfield_10142': ''})

    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Open'
    fix = FixedByTag(repository='foo/bar', branch='dev', version='5.13.0',
                     sha1='bd0279c4173eb627d432d9a05411bbc725240d4e', task_numbers=[], fixes=['CON-5'],
                     author='Some One', subject='Close a test issue')
    j._update_issue_with_retry(fix, issue_key, fixes=True)

    # This issue was re-opened, by default we will only post a comment but not re-open it again
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Open'

    j._update_issue_with_retry(fix, issue_key, fixes=True, ignore_reopened=True)

    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Closed'
    assert issue.fields.resolution.name == 'Done'
    assert len(issue.fields.fixVersions) == 1
    assert issue.fields.fixVersions[0].name.startswith('5.13.0')
    assert issue.fields.customfield_10142 == 'bd0279c4173eb627d432d9a05411bbc725240d4e (foo/bar/dev)'

    j.jira_client.transition_issue(issue_key, transition='Re-open')
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Open'
    assert not issue.fields.resolution

    # Assign to bot and start work
    assert j.jira_client.assign_issue(issue.key, assignee='qtgerritbot')
    j.jira_client.transition_issue(issue_key, transition='Start Work')
    j._update_issue_with_retry(fix, issue_key, True, ignore_reopened=True)
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Closed'
    assert issue.fields.resolution.name == 'Done'

    # Close it a second time (and that should just do nothing, not raise an exception)
    j._update_issue_with_retry(fix, issue_key, True)
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Closed'
    assert issue.fields.resolution.name == 'Done'

    # Sometimes we have less sensical fix versions set already, such as "Some future release".
    # Make sure that doesn't bother the bot.
    j.jira_client.transition_issue(issue_key, transition='Re-open')
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Open'
    assert not issue.fields.resolution
    version_some_future_release = '11533'
    issue.update(fields={'fixVersions': [{'id': version_some_future_release}]})
    issue = j.jira_client.issue(issue_key)
    assert len(issue.fields.fixVersions) == 1

    j._update_issue_with_retry(fix, issue_key, True, ignore_reopened=True)
    issue = j.jira_client.issue(issue_key)
    assert issue.fields.status.name == 'Closed'
    assert issue.fields.resolution.name == 'Done'
    # Verify that the new fix version was added and the "some future release" is still there.
    assert len(issue.fields.fixVersions) == 2
Exemplo n.º 7
0
##
## $QT_END_LICENSE$
##
#############################################################################

from distutils.version import LooseVersion
from typing import List, Tuple
from config import Config
from jiracloser import JiraCloser


""" Debugging helper to test the other code when working on these scripts. """


def print_versions(version_list: List[Tuple[LooseVersion, str, bool]]) -> None:
    print("    {name:35}{description:35}{released}".format(name="Version", description="Stuff", released="Released", width=30))
    for version in version_list:
        print("    {name:35}{description:35}{released}".format(name=version[0].vstring, description=version[1], released=str(version[2]), width=30))


if __name__ == "__main__":
    config = Config('test')
    j = JiraCloser(config)
    print("Fix versions for QTBUG:")
    issue = j.jira_client.issue('QTBUG-1')
    print_versions(j._jira_version_list(issue))

    print("Fix versions for QTCREATORBUG:")
    issue = j.jira_client.issue('QTCREATORBUG-1')
    print_versions(j._jira_version_list(issue))