def fix_commit(key): """Fix an individual commit if possible.""" commit_key = ndb.Key(urlsafe=key) commit = commit_key.get() if commit is None: return commit_data = commit.to_dict() # Check the timestamp to see if we should reject/delete if commit.timestamp is None: logging.warning("Skipping early orphan") return if commit.timestamp < settings.START_DATETIME: logging.warning("Skipping early orphan") return if 'project_slug' in commit_data: del commit_data['project_slug'] new_commit = Commit.create_by_email(commit.email, [commit_data], project=commit.project) if new_commit and new_commit[0].parent(): logging.info('Deleting orphan') commit.key.delete()
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)
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)
def post(self): payload = self.parse_payload() logging.info(payload) if not payload: abort(400) try: data = json.loads(payload) except: logging.exception("Unable to serialize POST") abort(400) repository = data.get('repository', {}) commit_data = data.get('commits', []) repo = self._parse_repo(repository) commit_dict = self.parse_commits(commit_data) total_commits = [] for email, commits in commit_dict.iteritems(): # TODO: run this in a task queue? cmts = Commit.create_by_email(email, commits, project=repo.get('url', '')) total_commits += cmts status = 200 # If we found commits try to save the project too. if len(total_commits): status = 201 _, project = Project.get_or_create(**repo) project_key = project.key @ndb.transactional def txn(): # TODO: run this in a task queue? total = len(total_commits) project = project_key.get() logging.info("adding %s points to %s", total, project) project.total += total project.put() txn() return self.respond_json( {'commits': [c.urlsafe() for c in total_commits]}, status_code=status)
def post(self): payload = self.parse_payload() logging.info(payload) if not payload: abort(400) try: data = json.loads(payload) except: logging.exception("Unable to serialize POST") abort(400) repository = data.get('repository', {}) commit_data = data.get('commits', []) repo = self._parse_repo(repository) commit_dict = self.parse_commits(commit_data) total_commits = [] for email, commits in commit_dict.iteritems(): # TODO: run this in a task queue? cmts = Commit.create_by_email(email, commits, project=repo.get('url', '')) total_commits += cmts status = 200 # If we found commits try to save the project too. if len(total_commits): status = 201 _, project = Project.get_or_create(**repo) project_key = project.key @ndb.transactional def txn(): # TODO: run this in a task queue? total = len(total_commits) project = project_key.get() logging.info("adding %s points to %s", total, project) project.total += total project.put() txn() return self.respond_json({'commits': [c.urlsafe() for c in total_commits]}, status_code=status)
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)