Example #1
0
    def run(self):
        """Starts a triage run"""
        self.repo = self._connect().get_repo("ansible/ansible-modules-%s" %
                                        self.github_repo)

        if self.number:
            issue = self.repo.get_issue(int(self.number))
            self.issue = IssueWrapper(repo=self.repo, issue=issue)
            self.issue.get_events()
            self.issue.get_comments()
            self.process()
        else:

            last_run = None
            now = self.get_current_time()
            #import epdb; epdb.st()
            last_run_file = '~/.ansibullbot/cache'
            last_run_file += '/ansible/ansible-modules-%s/' % self.github_repo
            last_run_file += 'issues/last_run.pickle'
            last_run_file = os.path.expanduser(last_run_file)
            if os.path.isfile(last_run_file):
                try:
                    with open(last_run_file, 'rb') as f:
                        last_run = pickle.load(f)
                except Exception as e:
                    print(e)
            #import epdb; epdb.st()

            if last_run:
                issues = self.repo.get_issues(since=last_run)
            else:
                issues = self.repo.get_issues()

            for issue in issues:
                if self.start_at and issue.number > self.start_at:
                    continue
                if self.is_pr(issue):
                    continue
                self.issue = IssueWrapper(repo=self.repo, issue=issue)
                self.issue.get_events()
                self.issue.get_comments()
                action_res = self.process()
                if action_res:
                    while action_res['REDO']:
                        issue = self.repo.get_issue(int(issue.number))
                        self.issue = IssueWrapper(repo=self.repo, issue=issue)
                        self.issue.get_events()
                        self.issue.get_comments()
                        action_res = self.process()
                        if not action_res:
                            action_res = {'REDO': False}

            # save this run time
            with open(last_run_file, 'wb') as f:
                pickle.dump(now, f)
Example #2
0
def get_triagermock_for_datafile(datafile):
    im = IssueMock(datafile)
    iw = IssueWrapper(repo=None, issue=im)
    triage = TriageIssuesMock(verbose=True)

    triage.issue = iw
    triage.issue.get_events()
    triage.issue.get_comments()

    # add additional mock data from fixture
    triage.force = True
    triage._now = im.ydata.get('_now', datetime.now())
    triage.number = im.ydata.get('number', 1)
    triage.github_repo = im.ydata.get('github_repo', 'core')
    triage.match = im.ydata.get('_match')
    triage.module_indexer.match = im.ydata.get('_match')
    if not im.ydata.get('_match'):
        triage.module_indexer.modules = {'xyz': SAMPLE_MODULE}
    else:
        triage.module_indexer.modules = {'NULL': triage.module_indexer.match}
    if im.ydata.get('_match'):
        triage._module = triage.match.get('name')
    else:
        triage._module = None
    triage._ansible_members = im.ydata.get('_ansible_members', [])
    triage._module_maintainers = im.ydata.get('_module_maintainers', [])

    return triage
Example #3
0
    def run(self, useapiwrapper=True):
        """Starts a triage run"""

        # how many issues have been processed
        self.icount = 0

        # Create the api connection
        if not useapiwrapper:
            # use the default non-caching connection
            self.repo = self._connect().get_repo(self._get_repo_path())
        else:
            # make use of the special caching wrapper for the api
            self.gh = self._connect()
            self.ghw = GithubWrapper(self.gh)
            self.repo = self.ghw.get_repo(self._get_repo_path())

        # extend the ignored labels by repo
        if hasattr(self, 'IGNORE_LABELS_ADD'):
            self.IGNORE_LABELS.extend(self.IGNORE_LABELS_ADD)

        if self.number:
            issue = self.repo.get_issue(int(self.number))
            self.issue = IssueWrapper(repo=self.repo, issue=issue, cachedir=self.cachedir)
            self.issue.get_events()
            self.issue.get_comments()
            self.process()
        else:

            last_run = None
            now = self.get_current_time()
            last_run_file = '~/.ansibullbot/cache'
            if self.github_repo == 'ansible':
                last_run_file += '/ansible/ansible/'
            else:
                last_run_file += '/ansible/ansible-modules-%s/' % self.github_repo
            last_run_file += 'issues/last_run.pickle'
            last_run_file = os.path.expanduser(last_run_file)
            if os.path.isfile(last_run_file):
                try:
                    with open(last_run_file, 'rb') as f:
                        last_run = pickle.load(f)
                except Exception as e:
                    print(e)

            if last_run and not self.no_since:
                self.debug('Getting issues updated/created since %s' % last_run)
                issues = self.repo.get_issues(since=last_run)
            else:
                self.debug('Getting ALL issues')
                issues = self.repo.get_issues()

            for issue in issues:
                self.icount += 1
                if self.start_at and issue.number > self.start_at:
                    continue
                if self.is_pr(issue):
                    continue
                self.issue = IssueWrapper(repo=self.repo, issue=issue, cachedir=self.cachedir)
                self.issue.get_events()
                self.issue.get_comments()
                action_res = self.process()
                if action_res:
                    while action_res['REDO']:
                        issue = self.repo.get_issue(int(issue.number))
                        self.issue = IssueWrapper(repo=self.repo, issue=issue, cachedir=self.cachedir)
                        self.issue.get_events()
                        self.issue.get_comments()
                        action_res = self.process()
                        if not action_res:
                            action_res = {'REDO': False}

            # save this run time
            with open(last_run_file, 'wb') as f:
                pickle.dump(now, f)
Example #4
0
    def run(self, useapiwrapper=True):
        # how many issues have been processed
        self.icount = 0

        # Create the api connection
        if not useapiwrapper:
            # use the default non-caching connection
            self.repo = self._connect().get_repo(self._get_repo_path())
        else:
            # make use of the special caching wrapper for the api
            self.gh = self._connect()
            self.ghw = GithubWrapper(self.gh)
            self.repo = self.ghw.get_repo(self._get_repo_path())

        # make a list of valid assignees
        print('Getting valid assignees')
        self.valid_assignees = [x.login for x in self.repo.get_assignees()]

        # extend the ignored labels by repo
        if hasattr(self, 'IGNORE_LABELS_ADD'):
            self.IGNORE_LABELS.extend(self.IGNORE_LABELS_ADD)

        if self.number:

            # get the issue
            issue = self.repo.get_issue(int(self.number))
            self.issue = IssueWrapper(repo=self.repo,
                                      issue=issue,
                                      cachedir=self.cachedir)
            self.issue.MUTUALLY_EXCLUSIVE_LABELS = self.MUTUALLY_EXCLUSIVE_LABELS
            self.issue.valid_assignees = self.valid_assignees
            self.issue.get_events()
            self.issue.get_comments()

            # get the PR and it's properties
            self.issue.pullrequest = self.repo.get_pullrequest(int(
                self.number))
            self.issue.get_commits()
            self.issue.get_files()
            self.issue.get_review_comments()

            # do the work
            self.process()

        else:

            # need to get the PRs
            print('Getting ALL pullrequests')
            pullrequests = self.repo.get_pullrequests(since=None)

            # iterate
            for idp, pr in enumerate(pullrequests):
                # get the issue and make a wrapper
                issue = self.repo.get_issue(int(pr.number))
                self.issue = IssueWrapper(repo=self.repo,
                                          issue=issue,
                                          cachedir=self.cachedir)
                self.issue.MUTUALLY_EXCLUSIVE_LABELS = self.MUTUALLY_EXCLUSIVE_LABELS
                self.issue.valid_assignees = self.valid_assignees
                self.issue.get_events()
                self.issue.get_comments()

                # get the PR and it's properties
                self.issue.pullrequest = pr
                self.issue.get_commits()
                self.issue.get_files()
                self.issue.get_review_comments()

                # do the work
                self.process()