예제 #1
0
    def git_poller(self):
        logging.debug('Poll the git repos')
        history_msgs = {}

        for human_name in self:
            initial_state = self[human_name]
            initial_state_dict = dict(initial_state)
            logging.debug('fetch all heads of %s... ' % human_name)
            fetch_all_heads(human_name)
            new_state_dict = {head: rev for head, rev in get_heads_revisions(human_name)}
            history_msg = ''
            new_stuff = False
            for head in initial_state_dict:
                if initial_state_dict[head] != new_state_dict[head]:
                    logging.debug('%s: %s -> %s' % (head, initial_state_dict[head].encode("hex"), new_state_dict[head].encode("hex")))
                    new_stuff = True

            if new_stuff:
                log = git_log(history_since_rev(human_name, initial_state))
                for head in log:
                    if log[head]: # don't log the empty branches
                        history_msg += '  Branch ' + head + ':\n    '
                        history_msg += '\n    '.join(log[head]) + '\n'
                history_msgs[human_name] = history_msg
            logging.debug('Saving the shelf')
            self[human_name] = [(head, sha) for head, sha in new_state_dict.items() if head in initial_state_dict]
        if history_msgs:
            if CHATROOM_PRESENCE:
                room = CHATROOM_PRESENCE[0]
                self.send(room, '/me is about to give you the latest git repo news ...', message_type='groupchat')
                for repo, changes in history_msgs.iteritems():
                    msg = ('%s:\n' % repo) + changes
                    logging.debug('Send:\n%s' % msg)
                    self.send(room, msg, message_type='groupchat')
예제 #2
0
    def git_poller(self):
        try:
            with self.ggl:
                logging.debug('Poll the git repos')
                history_msgs = {}

                for human_name in self.shelf:
                    initial_state = self.shelf[human_name]
                    initial_state_dict = dict(initial_state)
                    logging.debug('fetch all heads of %s... ' % human_name)
                    fetch_all_heads(human_name)
                    new_state_dict = {
                        head: rev
                        for head, rev in get_heads_revisions(human_name)
                    }
                    history_msg = ''
                    new_stuff = False
                    for head in initial_state_dict:
                        if initial_state_dict[head] != new_state_dict[head]:
                            logging.debug(
                                '%s: %s -> %s' %
                                (head, initial_state_dict[head].encode("hex"),
                                 new_state_dict[head].encode("hex")))
                            new_stuff = True

                    if new_stuff:
                        log = git_log(
                            history_since_rev(human_name, initial_state))
                        for head in log:
                            if log[head]:  # don't log the empty branches
                                history_msg += '  Branch ' + head + ':\n    '
                                history_msg += '\n    '.join(log[head]) + '\n'
                        history_msgs[human_name] = history_msg
                    logging.debug('Saving the shelf')
                    self.shelf[human_name] = [
                        (head, sha) for head, sha in new_state_dict.items()
                        if head in initial_state_dict
                    ]
                    self.shelf.sync()
                    logging.debug('Syncing the shelf')
                if history_msgs:
                    if CHATROOM_PRESENCE:
                        room = CHATROOM_PRESENCE[0]
                        self.send(
                            room,
                            '/me is about to give you the latest git repo news ...',
                            message_type='groupchat')
                        for repo, changes in history_msgs.iteritems():
                            msg = ('%s:\n' % repo) + changes
                            logging.debug('Send:\n%s' % msg)
                            self.send(room, msg, message_type='groupchat')
            logging.debug('Program the next poll')
            self.program_next_poll()
        except Exception, e:
            logging.exception('poller exploded')
예제 #3
0
    def _git_follow_url(self, git_url, heads_to_follow):
        human_name = human_name_for_git_url(git_url)
        if self.has_key(human_name):
            fetch_all_heads(human_name)
            current_entry = self[human_name]
        else:
            human_name = clone(git_url)
            current_entry = []

        current_entry_dict = dict(current_entry)
        current_entry = [pair for pair in get_heads_revisions(human_name) if pair[0] in heads_to_follow or pair[0] in current_entry_dict] if heads_to_follow else get_heads_revisions(human_name)
        self[human_name] = current_entry
        return self.git_following(None, None)
예제 #4
0
    def _git_follow_url(self, git_url, heads_to_follow):
        human_name = human_name_for_git_url(git_url)
        with self.ggl:
            if self.shelf.has_key(human_name):
                fetch_all_heads(human_name)
                current_entry = self.shelf[human_name]
            else:
                human_name = clone(git_url)
                current_entry = []

            current_entry_dict = dict(current_entry)
            current_entry = [
                pair for pair in get_heads_revisions(human_name)
                if pair[0] in heads_to_follow or pair[0] in current_entry_dict
            ] if heads_to_follow else get_heads_revisions(human_name)
            self.shelf[human_name] = current_entry
            self.shelf.sync()

            return self.following(None, None)