Пример #1
0
    def test_is_clone(self):
        commit = self._create_commit()[0]
        ok_(not commit.is_clone())

        commit = self._create_commit(git_url="http://github.com/dinoboff/github/")[0]
        ok_(commit.is_clone())

        data = COMMITS[0]
        commit = GitHubCommit(self.env, **data)
        ok_(commit.is_clone())
Пример #2
0
 def test_render_xss_event(self):
     commit = GitHubCommit(self.env, git_url=GIT_URL, **COMMITS[0])
     commit.url = """http://example" onclick="alert('xss')"""
     commit.id = """1234567<script>alert('xss')</script>"""
     commit.message = """<a href="http://example" onclick="alert('xss')">foo</a><script>alert('xss')</script>"""
     def render(field):
         return str(self.github_event_provider.render_timeline_event({}, field, ('','','',commit)))
     eq_("Revision <em>1234567&lt;script&gt;alert('xss')&lt;/script&gt;</em>", render('title'))
     eq_(
         """&lt;a href="http://example" onclick="alert(\'xss\')"&gt;foo&lt;/a&gt;&lt;script&gt;alert(\'xss\')&lt;/script&gt;""",
         render('description'))        
Пример #3
0
 def _create_commit(self):
     c = GitHubCommit(self.env, git_url=GIT_URL, **COMMITS[0])
     c.time = self.now
     c.save()
     c = GitHubCommit(self.env, git_url=GIT_URL, **COMMITS[1])
     c.time = self.now + 5
     c.url = 'http://example.com/example.git'
     c.save()
Пример #4
0
 def test_filter_fields(self):
     data = simplejson.loads(INVALID_JSON_COMMITS)
     GitHubCommit.filter_fields(data)
     eq_(None, data["repository"]["url"])
     eq_(None, data["repository"]["owner"]["email"])
     eq_("FILTERED", data["repository"]["owner"]["name"])
     eq_("*****@*****.**", data["commits"][0]["author"]["email"])
     eq_("41a212ee83ca127e3c8cf465891ab7216a705f59", data["commits"][0]["id"])
     eq_(
         "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
         data["commits"][0]["url"],
     )
     eq_("*****@*****.**", data["commits"][0]["author"]["email"])
Пример #5
0
    def get_timeline_events(self, req, start, stop, filters):
        """
        Return a list of events in the time range given by the `start` and
        `stop` parameters.

        The `filters` parameters is a list of the enabled filters, each item
        being the name of the tuples returned by `get_timeline_filters`.

        Since 0.11, the events are `(kind, date, author, data)` tuples,
        where `kind` is a string used for categorizing the event, `date`
        is a `datetime` object, `author` is a string and `data` is some
        private data that the component will reuse when rendering the event.

        When the event has been created indirectly by another module,
        like this happens when calling `AttachmentModule.get_timeline_events()`
        the tuple can also specify explicitly the provider by returning tuples
        of the following form: `(kind, date, author, data, provider)`.
        """
        if 'main_git_repository' in filters or \
            'cloned_git_repository' in filters:
            
            for event in GitHubEvent.get_commit_by_date(
                self.env, to_timestamp(start), to_timestamp(stop), git_url=self.github_url):
                
                if event.is_clone() and 'cloned_git_repository' in filters:
                    yield ('cloned_git_repository',
                        datetime.fromtimestamp(event.time, utc),
                        event.author,
                        event)
                elif not event.is_clone() and 'main_git_repository' in filters:
                    yield ('main_git_repository',
                        datetime.fromtimestamp(event.time, utc),
                        event.author,
                        event) # TODO: only sent needed data
Пример #6
0
 def test_process_commit(self):
     commits = []
     time = self.now
     for data in COMMITS:
         c = GitHubCommit(self.env, git_url=GIT_URL, **data)
         c.time = time
         c.save()
         commits.append(c)
         time = time + 60
     
     # parse commit for the first time (with a clone)
     self.ticker_updater.process_commit(commits[0])
     tkt1 = Ticket(self.env, 1)
     change_log = tkt1.get_changelog()
     eq_(1, len(change_log))
     eq_('Damien Lebrun <*****@*****.**>', change_log[0][1])
     eq_(
         'Commit %(id)s:\n\n%(message)s\n\nSource: [%(url)s]' % COMMITS[0],
         change_log[0][4])
     
     # parse same commit (still clone),
     # should not update the ticket
     self.ticker_updater.process_commit(commits[1])
     tkt1 = Ticket(self.env, 1)
     change_log = tkt1.get_changelog()
     eq_(1, len(change_log))
     
     # parse the commit from the main git repository
     # Should update the repository
     self.ticker_updater.process_commit(commits[2])
     tkt1 = Ticket(self.env, 1)
     change_log = tkt1.get_changelog()
     eq_(3, len(change_log))
     eq_('Damien Lebrun <*****@*****.**>', change_log[1][1])
     eq_(
         'Commit %(id)s:\n\n%(message)s\n\nSource: [%(url)s]' % COMMITS[2],
         change_log[1][4])
     eq_('Damien Lebrun <*****@*****.**>', change_log[2][1])
     eq_('resolution',change_log[2][2])
     eq_('fixed',change_log[2][4])
         
Пример #7
0
    def test_create_from_json(self):
        commits = GitHubCommit.create_from_json(self.env, JSON_COMMITS, git_url=GIT_URL)
        for x in range(2):
            commit = commits.next()
            eq_(self.env, commit.env)
            eq_(COMMITS[x]["id"], commit.id)
            eq_(COMMITS[x]["url"], commit.url)
            eq_(COMMITS[x]["message"], commit.message)
            eq_(COMMITS[x]["author"]["name"], commit.name)
            eq_(COMMITS[x]["author"]["email"], commit.email)
            ok_(not commit.is_clone())

        commits.next()  # should raise an exception
Пример #8
0
 def process_request(self, req):
     """
     Parse Github post and call all components implementing IGitHubPostObserver.
     """
     msg = 'ok'
     status = 200
     db = self.env.get_db_cnx()
     try:
         json = req.args.get('payload')
         for commit in GitHubCommit.create_from_json(self.env, json, git_url=self.github_url, db=db):
             self.env.log.debug("Calling observer(s) for commit: %s" % commit.url)
             for observer in self.observers:
                 observer.process_commit(commit)
             
     except (GitHubCommitException), e:
         db.rollback()
         self.env.log.error('An error occurred: %s' % str(e))
         msg = 'An error occurred: %s' % str(e)
         status = 404
Пример #9
0
    def test_get_commit_by_date(self):
        # create two commit, one 5 sec younger than the other
        db = self.env.get_db_cnx()
        now = to_timestamp(datetime.now(utc))
        data1 = COMMITS[0]
        commit1 = GitHubCommit(self.env, git_url=GIT_URL, **data1)
        commit1.time = now
        commit1.save(db=db)
        data2 = COMMITS[1]
        commit2 = GitHubCommit(self.env, git_url=GIT_URL, **data2)
        commit2.time = now + 5
        commit2.save(db=db)
        db.commit()

        commit_before_now = GitHubCommit.get_commit_by_date(self.env, now - 1, now, git_url=GIT_URL)
        commit_before_now = [x for x in commit_before_now]
        eq_(1, len(commit_before_now))
        eq_(commit1.url, commit_before_now[0].url)

        commit_now = GitHubCommit.get_commit_by_date(self.env, now, now + 5, git_url=GIT_URL)
        commit_now = [x for x in commit_now]
        eq_(2, len(commit_now))

        future_commit = GitHubCommit.get_commit_by_date(self.env, now + 6, now + 7, git_url=GIT_URL)
        future_commit = [x for x in future_commit]
        eq_(0, len(future_commit))