Пример #1
0
 def post(self, request):
     payload = self.parse_payload(request)
     logging.info(payload)
     if not payload:
         raise http.HttpResponseBadRequest
     
     try:
         data = json.loads(payload)
     except:
         logging.exception("Unable to serialize POST")
         raise http.HttpResponseBadRequest
     
     commit_data = data.get('commits', [])
     
     repo = self._parse_repo(data)
     project, _ = Project.create(**repo)
     
     commit_dict = self.parse_commits(commit_data, project)
     total_commits = []
     for email, commits in commit_dict.iteritems():
         # TODO: run this in a task queue?
         cmts = Commit.create_by_email(email, commits, project=project)
         total_commits += cmts
     
     status = 201 if len(total_commits) else 200
     
     self._publish_commits(total_commits)
     
     return self.respond_json({'commits': [c.hash for c in total_commits]}, status=status)
Пример #2
0
 def test_disabled_project(self):
     kwargs = {
         'name': 'foo',
         'url': 'http://example.com/user/repo',
         'repo_id': 1,
         'service': 'github',
     }
     Project.objects.create(active=False, **kwargs)
     project = Project.create(**kwargs)
     self.assertEqual(project, None)
Пример #3
0
 def test_disabled_project(self):
     kwargs = {
         'name': 'foo',
         'url': 'http://example.com/user/repo',
         'repo_id': 1,
         'service': 'github',
     }
     Project.objects.create(active=False, **kwargs)
     project = Project.create(**kwargs)
     self.assertEqual(project, None)
Пример #4
0
 def handle(self, *args, **options):
     if len(args) != 1:
         raise CommandError('Must supply a JSON file of commits.')
     
     commit_path = args[0]
     
     if os.path.isdir(commit_path):
         files = [os.path.join(commit_path, f) for f in os.listdir(commit_path) if f.startswith('commits')]
     else:
         files = [commit_path]
     
     for commits_json in files:
         logging.info("Parsing File: %s", commits_json)
         with open(commits_json, 'r') as commit_file:
             commits = json.loads(commit_file.read())
             for commit in commits['models']:
                 try:
                     project, _ = Project.create(url=commit['project'])
                     c = to_commit(commit)
                     Commit.create_by_email(c['email'], c, project)
                 except Exception:
                     logging.exception("Error: %s" % commit)
Пример #5
0
    def post(self, request):
        payload = self.parse_payload(request)
        if not payload:
            return http.HttpResponseBadRequest()
        elif isinstance(payload, http.HttpResponse):
            return payload
        try:
            data = json.loads(payload)
        except:
            logging.exception("Unable to serialize POST")
            return http.HttpResponseBadRequest()

        commit_data = data.get('commits', [])

        repo = self._parse_repo(data)
        logging.info(repo)
        project = Project.create(**repo)

        if project is None:
            logging.error("Project Disabled")
            # TODO: discover what response codes are helpful to github
            # and bitbucket
            return self.respond_json({'error': 'abuse'}, status=202)

        commit_dict = self.parse_commits(commit_data, project)
        total_commits = []
        for email, commits in commit_dict.iteritems():
            # TODO: run this in a task queue?
            cmts = Commit.create_by_email(email, commits, project=project)
            total_commits += cmts

        status = 201 if len(total_commits) else 200

        self._publish_commits(total_commits)

        return self.respond_json(
            {'commits': [c.hash for c in total_commits]},
            status=status)
Пример #6
0
    def post(self, request):
        payload = self.parse_payload(request)
        if not payload:
            return http.HttpResponseBadRequest()
        elif isinstance(payload, http.HttpResponse):
            return payload
        try:
            data = json.loads(payload)
        except:
            logging.exception("Unable to serialize POST")
            return http.HttpResponseBadRequest()

        commit_data = data.get('commits', [])

        repo = self._parse_repo(data)
        logging.info(repo)
        project = Project.create(**repo)

        if project is None:
            logging.error("Project Disabled")
            # TODO: discover what response codes are helpful to github
            # and bitbucket
            return self.respond_json({'error': 'abuse'}, status=202)

        commit_dict = self.parse_commits(commit_data, project)
        total_commits = []
        for email, commits in commit_dict.iteritems():
            # TODO: run this in a task queue?
            cmts = Commit.create_by_email(email, commits, project=project)
            total_commits += cmts

        status = 201 if len(total_commits) else 200

        self._publish_commits(total_commits)

        return self.respond_json(
            {'commits': [c.hash for c in total_commits]},
            status=status)
Пример #7
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError('Must supply a JSON file of commits.')

        commit_path = args[0]

        if os.path.isdir(commit_path):
            files = [os.path.join(commit_path, f) for f in
                     os.listdir(commit_path) if f.startswith('commits')]
        else:
            files = [commit_path]

        for commits_json in files:
            logging.info("Parsing File: %s", commits_json)
            with open(commits_json, 'r') as commit_file:
                commits = json.loads(commit_file.read())
                for commit in commits['models']:
                    try:
                        project, _ = Project.create(url=commit['project'])
                        c = to_commit(commit)
                        Commit.create_by_email(c['email'], c, project)
                    except Exception:
                        logging.exception("Error: %s" % commit)
Пример #8
0
 def make_project(self, url='http://github.com/project', name='test'):
     return Project.create(url=url, name=name)
Пример #9
0
 def make_project(self, url='http://github.com/project', name='test'):
     return Project.create(url=url, name=name)
Пример #10
0
 def make_project(self, url="http://github.com/project", name="test"):
     return Project.create(url=url, name=name)