def put(self, *args, **kwargs): if 'user' not in kwargs or not args: self.raise401() name = self.get_argument('name', None) description = self.get_argument('description', None) path = self.get_argument('path', None) scm = self.get_argument('scm', None) team = self.get_argument('team', None) tags = self.get_argument('tags', None) user = kwargs['user'] update = {} if name: update['set__name'] = name if description: update['set__description'] = description if path: update['set__path'] = path if scm: update['set__scm'] = scm if team: update['set__team'] = team if tags: tags_list = parse_listed_strs(tags) update['set__tags'] = tags_list try: path = parse_path(args[0]) Repo.objects(owner=user, name=path[0]).update_one(**update) repo = Repo.objects(owner=user, name=name or path[0]).first() repo_data = document_to_json(repo, filter_set=_FILTER) self.set_status(201) self.write(repo_data) except Exception as e: reason = e.message self.raise400(reason=reason)
def delete(self, *args, **kwargs): if 'user' not in kwargs or not args: self.raise401() try: user = kwargs['user'] path = parse_path(args[0]) Repo.objects(owner=user, name=path[0]).delete() self.set_status(204) self.finish() except Exception as e: reason = e.message self.raise400(reason=reason)
def parse(cls, response): repos = [] for i in range(len(response)): repo = response[i] repo = Repo(repo["id"], repo["name"], repo["stargazers_count"]) repos.append(repo) return repos
def post(self, *args, **kwargs): """Create a new project by providing the details about the project. If the validation and saving are successful, it response with the project data and 201 status. Otherwise, it gives 4XX status and error messages. """ name = self.get_argument('name', None) description = self.get_argument('description', None) url = self.get_argument('url', None) leader = self.get_argument('leader', None) members = self.get_argument('members', None) teams = self.get_argument('teams', None) repos = self.get_argument('repos', None) tags = self.get_argument('tags', None) if 'user' not in kwargs: self.raise401() try: # todo - better arguments handler url = url.strip() url = url if url else None members_list = [] repos_list = [] teams_list = [] project_leader = kwargs['user'] if leader: project_leader = User.objects(username=leader).first() if repos: for repo in parse_listed_strs(repos): r = Repo.objects(name=repo).first() if not r: continue repos_list.append(r) if members: for member in parse_listed_strs(members): u = User.objects(username=member).first() if not u or u == project_leader: continue members_list.append(u) if teams: for team in parse_listed_strs(teams): t = Team.objects(name=team).first() if not t: continue teams_list.append(t) members_list.append(project_leader) tags_list = parse_listed_strs(tags) project = Project( name=name, description=description, url=url, repos=repos_list, leader=project_leader, members=members_list, teams=teams_list, tags=tags_list) project.save() project_data = document_to_json(project, filter_set=_FILTER) self.set_status(201) self.write(project_data) except Exception as e: reason = e.message self.raise400(reason=reason)
async def get_repositories(self, search_term): repositories_response = requests.get( self.__base_url, { 'q' : search_term + ' in:name', 'page' : '1', 'per_page' : '5' }, auth=HTTPBasicAuth('sribalajig', 'Bala@1234')) repositories = json.loads(repositories_response.text)["items"] repos = [] for item in repositories: repos.append(Repo(item)) repos.sort(key=lambda x: x.created_at, reverse=True) tasks = [] for repo in repos: task = asyncio.ensure_future(self.get_latest_commit(repo)) tasks.append(task) latest_commits = await asyncio.gather(*tasks) for repo in repos: commit = next(commit for commit in latest_commits if commit.repo_name == repo.full_name) if commit != None: repo.set_latest_commit(commit) return repos
def parser(cls, response) -> list: repos = [] for i in range(len(response)): repo = response[i] repo = Repo(repo['id'], repo['name'], repo['stargazers_count']) repos.append(repo) return repos
def post(self, *args, **kwargs): name = self.get_argument('name', None) description = self.get_argument('description', None) path = self.get_argument('path', None) # verify scm = self.get_argument('scm', None) team = self.get_argument('team', None) # just for test tags = self.get_argument('tags', None) if 'user' not in kwargs: self.raise401() user = kwargs['user'] tags_list = parse_listed_strs(tags) try: name = name.strip() name = name if name else None repo = Repo(name=name, description=description, path=path, scm=scm, owner=user, team=team, tags=tags_list) repo.save() repo_data = document_to_json(repo, filter_set=_FILTER) self.set_status(201) self.write(repo_data) except Exception as e: reason = e.message self.raise400(reason=reason)
def parse(cls, response): repos = [] for i in range(len(response)): repo = response[i] repo = Repo(repo["id"], repo["name"], repo["stargazers_count"]) repos.append(repo) return repos ############################################################################# # # V3 # from models.repo import Repo # class RepoParser(): # @classmethod # def parse(cls, response): # for i in range(len(response)): # repo = response[i] # repo = Repo(repo["id"], repo["name"], repo["stargazers_count"]) # print(repo)
def parse(cls, response): for i in range(len(response)): repo = response[i] repo = Repo(repo['id'], repo['name'], repo['stargazers_count']) print(repo)
def get(self, *args, **kwargs): if 'user' not in kwargs: self.raise401() user = kwargs['user'] repo_type = None repo_query = None repo_contents = None repo_branches = None repo_tags = None repo_info = None limit = self.get_argument('limit', None) start = self.get_argument('start', None) try: limit = int(limit) except: limit = None if args: # author = self.get_argument('author', None) path = parse_path(args[0]) if not path: self.raise404() repo = Repo.objects(owner=user, name=path[0]).first() if repo: scm_repo = GitRepo(repo.path) repo_info = scm_repo.get_info() repo_branches, repo_tags = get_repo_branches_tags(scm_repo) repo_type, repo_query, repo_contents = get_repo_contents( scm_repo, path[1:], limit=limit, start=start) if not repo_contents: self.raise404() repo_data = document_to_json(repo, filter_set=_FILTER) else: team_name = self.get_argument('team_name', None) try: start = int(start) except: start = None try: team_name = parse_path(team_name)[0] except IndexError: team_name = None if team_name: team = Team.objects(name=team_name).first() if not team: self.raise404() if user not in team.member: self.raise403() repos = Repo.objects(team=team) else: repos = Repo.objects(owner=user) if limit and start: repos = repos[start: start+limit] elif limit: repos = repos[:limit] elif start: repos = repos[start:] repo_data = query_to_json(repos, filter_set=_FILTER) if repo_type and repo_contents: repo_data['repo_info'] = repo_info repo_data['repo_type'] = repo_type repo_data['repo_query'] = repo_query repo_data['repo_branches'] = repo_branches repo_data['repo_tags'] = repo_tags repo_data['repo_contents'] = repo_contents self.write(repo_data)
def put(self, *args, **kwargs): """Update a project by its name and other information. """ if 'user' not in kwargs or not args: self.raise401() name = self.get_argument('name', None) description = self.get_argument('description', None) url = self.get_argument('url', None) leader = self.get_argument('leader', None) members = self.get_argument('members', None) teams = self.get_argument('teams', None) repos = self.get_argument('repos', None) tags = self.get_argument('tags', None) user = kwargs['user'] path = parse_path(args[0]) project = Project.objects(name=path[0]).first() if not project or user not in project.members: self.raise401() project_leader = project.leader update = {} if name: update['set__name'] = name if description: update['set__description'] = description if url: update['set__url'] = url if leader: project_leader = User.objects(username=leader).first() update['set__leader'] = project_leader if members: members_list = [] for member in parse_listed_strs(members): u = User.objects(username=member).first() if not u or u == project_leader: continue members_list.append(u) members_list.append(project_leader) update['set__members'] = members_list if teams: teams_list = [] for team in parse_listed_strs(teams): t = Team.objects(name=team).first() if not t: continue teams_list.append(t) update['set__teams'] = teams_list if repos: repos_list = [] for repo in parse_listed_strs(repos): r = Repo.objects(name=repo).first() if not r: continue repos_list.append(r) update['set__repos'] = repos_list if tags: tags_list = parse_listed_strs(tags) update['set__tags'] = tags_list try: Project.objects(name=path[0]).update_one(**update) project = Repo.objects(name=name or path[0]).first() project_data = document_to_json(project, filter_set=_FILTER) self.set_status(201) self.write(project_data) except Exception as e: reason = e.message self.raise400(reason=reason)
def post(self, *args, **kwargs): """Create a new project by providing the details about the project. If the validation and saving are successful, it response with the project data and 201 status. Otherwise, it gives 4XX status and error messages. """ name = self.get_argument('name', None) description = self.get_argument('description', None) url = self.get_argument('url', None) leader = self.get_argument('leader', None) members = self.get_argument('members', None) teams = self.get_argument('teams', None) repos = self.get_argument('repos', None) tags = self.get_argument('tags', None) if 'user' not in kwargs: self.raise401() try: # todo - better arguments handler url = url.strip() url = url if url else None members_list = [] repos_list = [] teams_list = [] project_leader = kwargs['user'] if leader: project_leader = User.objects(username=leader).first() if repos: for repo in parse_listed_strs(repos): r = Repo.objects(name=repo).first() if not r: continue repos_list.append(r) if members: for member in parse_listed_strs(members): u = User.objects(username=member).first() if not u or u == project_leader: continue members_list.append(u) if teams: for team in parse_listed_strs(teams): t = Team.objects(name=team).first() if not t: continue teams_list.append(t) members_list.append(project_leader) tags_list = parse_listed_strs(tags) project = Project(name=name, description=description, url=url, repos=repos_list, leader=project_leader, members=members_list, teams=teams_list, tags=tags_list) project.save() project_data = document_to_json(project, filter_set=_FILTER) self.set_status(201) self.write(project_data) except Exception as e: reason = e.message self.raise400(reason=reason)
def parse(cls, response): for i in range(len(response)): repo = response[i] repo = Repo(repo["id"], repo["name"], repo["stargazers_count"]) print(repo)