示例#1
0
 def __init__(self):
     self._github = GitHub.GitHub(username=self.params['github_username'], password=self.params['github_password'],
                                  token=self.params['token'])
     self.response = {}
     self.worklog = None
     self.repo_org = self.params['repo_organization']
     self.repo = self.params['repo']
示例#2
0
    async def post(self, request):
        if not self.gh:
            self.gh = GitHub(self.token)

        sig = request.headers.get('X-Hub-Signature')
        body = await request.content.read()
        our_sig = self.get_signature(body)
        if not hmac.compare_digest(sig, our_sig):
            logger.error('signature mismatch: %r != %r', sig, our_sig)
            return web.Response(status=500)

        res = await self.process(request, body)
        if res is None:
            res = web.Response(status=204)
        return res
示例#3
0
async def process_issue(gh: GitHub, issue_dict: Dict[str, Any],
                        edited: bool) -> None:
    issue = Issue(issue_dict, gh)
    if issue.number < 700:
        return

    body = issue.body
    issuetype, packages = parse_issue_text(body)

    if edited:
        async for c in gh.get_issue_comments(config.REPO_NAME, issue.number):
            if c.author == config.MY_GITHUB:
                await c.delete()
                break

    if issuetype is None or (not packages and issuetype in [
            IssueType.OutOfDate, IssueType.Orphaning, IssueType.Official
    ]):
        if edited:
            await issue.comment(_CANT_PARSE_EDITED)
        else:
            await issue.comment(_CANT_PARSE_NEW)
        await issue.close()
        return

    find_assignees = True
    assignees = set()
    comment = None
    if issuetype == IssueType.PackageRequest:
        find_assignees = False
        labels = ['package-request']
    elif issuetype == IssueType.OutOfDate:
        labels = ['out-of-date']
    elif issuetype == IssueType.Orphaning:
        labels = ['orphaning']
        find_assignees = False
        assignees.add('lilacbot')
    elif issuetype == IssueType.Official:
        labels = ['in-official-repos']
        assignees.add('lilacbot')
    else:
        labels = []

    if packages:
        if find_assignees:
            await git.pull_repo(config.REPODIR, config.REPO_URL)

            for pkg in packages:
                try:
                    maintainers = await lilac.find_maintainers(REPO, pkg)
                except FileNotFoundError:
                    continue

                assignees.update(x.github for x in maintainers
                                 if x.github is not None)

            if issuetype == IssueType.OutOfDate and packages:
                try:
                    logs = await files.find_build_log(
                        config.REPODIR,
                        config.BUILDLOG,
                        packages,
                    )
                except LookupError:
                    pass
                else:
                    logs2 = [
                        line for name, line in logs.items() if name in packages
                    ]
                    logs3 = '\n'.join(sorted(logs2))
                    comment = f'''build log for auto building out-of-date packages:
```
{logs3}
```
'''

    if labels:
        await issue.add_labels(labels)
    if assignees:
        await issue.assign(list(assignees))
    if comment:
        await issue.comment(comment)

    if issue.closed:
        await issue.reopen()
示例#4
0
async def process_issue(gh: GitHub, issue_dict: Dict[str, Any],
                        edited: bool) -> None:
    issue = Issue(issue_dict, gh)
    if issue.number < 700 or 'no-lilac' in issue.labels:
        return

    body = issue.body
    issuetype, packages = parse_issue_text(body)

    existing_comment = None
    idx = 0
    try:
        async for c in gh.get_issue_comments(config.REPO_NAME, issue.number):
            idx += 1
            if c.author == config.MY_GITHUB:
                existing_comment = c
                break
            elif idx > 20:  # check no further
                break
    except GitHubError:
        pass  # not found

    if issuetype is None or (not packages and issuetype in [
            IssueType.OutOfDate, IssueType.Orphaning, IssueType.Official
    ]):
        await edit_or_add_comment(
            issue,
            existing_comment,
            _CANT_PARSE_EDITED if edited else _CANT_PARSE_NEW,
        )
        await issue.close()
        return

    find_assignees = True
    assignees = set()
    comment = ''
    if issuetype == IssueType.PackageRequest:
        find_assignees = False
        labels = ['package-request']
    elif issuetype == IssueType.OutOfDate:
        labels = ['out-of-date']
    elif issuetype == IssueType.Orphaning:
        labels = ['orphaning']
        find_assignees = True
        assignees.add(config.MY_GITHUB)
    elif issuetype == IssueType.Official:
        labels = ['in-official-repos']
        assignees.add(config.MY_GITHUB)
    else:
        labels = []

    if packages:
        if find_assignees:
            unmaintained = []
            for pkg in packages:
                try:
                    maintainers = await lilac.find_maintainers(pkg)
                except FileNotFoundError:
                    continue

                if not maintainers:
                    unmaintained.append(pkg)

                assignees.update(x for x in maintainers)

            if issuetype == IssueType.Orphaning:
                comment = await process_orphaning(
                    issue.author,
                    edited,
                    packages,
                    assignees,
                    maintainers,
                )

            elif unmaintained:
                depinfo = {
                    pkg: await lilac.find_dependent_packages_ext_async(pkg)
                    for pkg in unmaintained
                }

                comment_parts = [
                    'NOTE: some affected packages are unmaintained:\n'
                ]
                for p, ds in depinfo.items():
                    ds_str = ', '.join(
                        annotate_maints(d.pkgbase, d.maintainers) for d in ds)
                    c2 = f'* {p} is depended by {ds_str}'
                    comment_parts.append(c2)
                comment += '\n'.join(comment_parts) + '\n\n'

            if issuetype == IssueType.OutOfDate and packages:
                comment += config.gen_log_comment(packages)

    if labels:
        await issue.add_labels(labels)
    if assignees:
        r = await issue.assign(list(assignees))
        assigned = {x['login'] for x in r['assignees']}
        failed = assignees - assigned
        if failed:
            if comment:
                comment += '\n\n'
            comment += 'Some maintainers (perhaps outside contributors) cannot be assigned: ' + ', '.join(
                f'@{x}' for x in failed)
    if comment:
        await edit_or_add_comment(issue, existing_comment, comment)

    if issue.closed:
        # webhook issues don't have "closed_by" info
        issue2 = await gh.get_issue(config.REPO_NAME, issue.number)
        if issue2.closed_by == config.MY_GITHUB and 'request-failed' not in issue.labels:
            await issue.reopen()
            if existing_comment and 'cannot parse' in existing_comment.body:
                await existing_comment.delete()