Exemplo n.º 1
0
 def get_timeline_events(self, req, start, stop, filters):
     rm = RepositoryManager(self.env)
     events = super(GitHubBrowser, self).get_timeline_events(req, start, stop, filters)
     for event in events:
         if event[0] != 'changeset':
             yield event
             continue
         allow = True
         for changeset in event[3][0]:
             reponame = changeset[2][0]
             repos = rm.get_repository(reponame)
             key = 'branches' if is_default(reponame) else '%s.branches' % reponame
             branches = self.config.getlist('github', key, sep=' ')
             if branches:
                 allow = allow and allow_revision(changeset[0].rev, repos, branches)
         if allow:
             yield event
Exemplo n.º 2
0
    def process_request(self, req):
        if not self.repository:                             # pragma: no cover
            return super(GitHubBrowser, self).process_request(req)

        rev = req.args.get('rev')
        path = req.args.get('path')

        rm = RepositoryManager(self.env)
        reponame, repos, path = rm.get_repository_by_path(path)

        key = 'repository' if is_default(reponame) else '%s.repository' % reponame
        gh_repo = self.config.get('github', key)

        try:
            rev = repos.normalize_rev(rev)
        except NoSuchChangeset, e:
            raise ResourceNotFound(e.message, _('Invalid Changeset Number'))
Exemplo n.º 3
0
    def _do_resync(self, reponame):
        rm = RepositoryManager(self.env)
        if reponame == '*':
            repositories = rm.get_real_repositories()
        else:
            if is_default(reponame):
                reponame = ''
            repos = rm.get_repository(reponame)
            if repos is None:
                raise TracError(
                    _("Repository '%(repo)s' not found",
                      repo=reponame or '(default)'))
            repositories = [repos]

        Changeset = namedtuple('changeset', 'repos rev message author date')
        for repos in sorted(repositories, key=lambda r: r.reponame):
            printout(
                _('Resyncing repository history for %(reponame)s... ',
                  reponame=repos.reponame or '(default)'))
            with self.env.db_transaction as db:
                db(
                    """
                    DELETE FROM codereviewer_map WHERE repo=%s
                    """, (repos.reponame, ))
                for time, author, message, rev in db(
                        """
                        SELECT time, author, message, rev FROM revision
                        WHERE repos=%s ORDER BY time
                        """, (repos.id, )):
                    cset = Changeset(repos, rev, message, author,
                                     from_utimestamp(time))
                    self._map(repos.reponame, cset)
                    self._sync_feedback(rev)

            for cnt, in self.env.db_query(
                    "SELECT count(rev) FROM revision WHERE repos=%s",
                (repos.id, )):
                printout(
                    ngettext('%(num)s revision cached.',
                             '%(num)s revisions cached.',
                             num=cnt))
        printout(_("Done."))
Exemplo n.º 4
0
 def get_branches(self, reponame):
     key = 'branches' if is_default(reponame) else '%s.branches' % reponame
     return self.config.getlist('github', key, sep=' ')
Exemplo n.º 5
0
 def get_gh_repo(self, reponame):
     key = 'repository' if is_default(reponame) else '%s.repository' % reponame
     return self.config.get('github', key)
Exemplo n.º 6
0
 def get_branches(self, reponame):
     key = "branches" if is_default(reponame) else "%s.branches" % reponame
     return self.config.getlist("github", key, sep=" ")
Exemplo n.º 7
0
 def get_gh_repo(self, reponame):
     key = "repository" if is_default(reponame) else "%s.repository" % reponame
     return self.config.get("github", key)
Exemplo n.º 8
0
 def get_branches(self, reponame):
     key = 'branches' if is_default(reponame) else '%s.branches' % reponame
     return self.config.getlist('github', key, sep=' ')
Exemplo n.º 9
0
 def get_gh_repo(self, reponame):
     key = 'repository' if is_default(
         reponame) else '%s.repository' % reponame
     return self.config.get('github', key)
Exemplo n.º 10
0
    def process_request(self, req):
        if req.method != 'POST':
            msg = u'Method not allowed (%s)\n' % req.method
            self.log.warning(msg.rstrip('\n'))
            req.send(msg.encode('utf-8'), 'text/plain', 405)

        path = req.args['path']

        rm = RepositoryManager(self.env)
        reponame, repos, path = rm.get_repository_by_path(path)

        key = 'branches' if is_default(reponame) else '%s.branches' % reponame
        branches = self.config.getlist('github', key, sep=' ')

        if path != '/':
            msg = u'No such repository (%s)\n' % path
            self.log.warning(msg.rstrip('\n'))
            req.send(msg.encode('utf-8'), 'text/plain', 400)

        output = u'Running hook on %s\n' % (reponame or '(default)')

        output += u'* Updating clone\n'
        output += repos.git.repo.remote('update', '--prune')

        try:
            payload = json.loads(req.args['payload'])
            revs = [commit['id'] for commit in payload['commits']]
        except (ValueError, KeyError):
            msg = u'Invalid payload\n'
            self.log.warning(msg.rstrip('\n'))
            req.send(msg.encode('utf-8'), 'text/plain', 400)

        if branches:
            added_revs, skipped_revs = [], []
            for rev in revs:
                if allow_revision(rev, repos, branches):
                    added_revs.append(rev)
                else:
                    skipped_revs.append(rev)
        else:
            added_revs, skipped_revs = revs, []

        if added_revs:
            if len(added_revs) == 1:
                output += u'* Adding commit %s\n' % added_revs[0]
            else:
                output += u'* Adding commits %s\n' % u', '.join(added_revs)

            # This is where Trac gets notified of the commits in the changeset
            rm.notify('changeset_added', reponame, added_revs)

        if skipped_revs:
            if len(skipped_revs) == 1:
                output += u'* Skipping commit %s\n' % skipped_revs[0]
            else:
                output += u'* Skipping commits %s\n' % u', '.join(skipped_revs)

        for line in output.splitlines():
            self.log.debug(line)

        req.send(output.encode('utf-8'), 'text/plain', 200 if output else 204)