def do_event(event): from_repo_id = event['from_repo_id'] to_repo_id = event['to_repo_id'] from_repo = RepoManager.get_repo_by_id(from_repo_id) to_repo = RepoManager.get_repo_by_id(to_repo_id) copy_from_bare = False if to_repo is None: return if from_repo is None: copy_from_bare = True from_repo_path = GIT_BARE_REPO_PATH if not copy_from_bare: from_repo_path = from_repo.get_abs_repopath() to_repo_path = to_repo.get_abs_repopath() if not os.path.exists(from_repo_path): logger.info('from_repo_path: %s is not exists, clone failed' % from_repo_path) return if chdir(from_repo_path) is False: logger.info('chdir to from_repo_path: %s is False, clone failed' % from_repo_path) return if os.path.exists(to_repo_path): logger.info('to_repo_path: %s already exists, clone failed' % to_repo_path) return args = ['/usr/bin/git', 'gc'] popen = Popen(args, stdout=PIPE, shell=False, close_fds=True) result = popen.communicate()[0].strip() to_repo_dirname = os.path.dirname(to_repo_path) if not os.path.exists(to_repo_dirname): os.makedirs(to_repo_dirname) shutil.copytree(from_repo_path, to_repo_path) update_repo_status(from_repo, to_repo)
def do_event(event): from_repo_id = event['from_repo_id'] to_repo_id = event['to_repo_id'] from_repo = RepoManager.get_repo_by_id(from_repo_id) to_repo = RepoManager.get_repo_by_id(to_repo_id) copy_from_bare = False if to_repo is None: return if from_repo is None: copy_from_bare = True from_repo_path = GIT_BARE_REPO_PATH if not copy_from_bare: from_repo_path = from_repo.get_abs_repopath() to_repo_path = to_repo.get_abs_repopath() if not os.path.exists(from_repo_path): logger.info('from_repo_path: %s is not exists, clone failed' % from_repo_path) return if chdir(from_repo_path) is False: logger.info('chdir to from_repo_path: %s is False, clone failed' % from_repo_path) return if os.path.exists(to_repo_path): logger.info('to_repo_path: %s already exists, clone failed' % to_repo_path) return args = ['/usr/bin/git', 'gc'] popen = Popen(args, stdout=PIPE, shell=False, close_fds=True) result = popen.communicate()[0].strip() to_repo_dirname = os.path.dirname(to_repo_path) if not os.path.exists(to_repo_dirname): os.makedirs(to_repo_dirname) shutil.copytree(from_repo_path, to_repo_path) update_repo_status(from_repo, to_repo)
def do_issue(request): action = request.POST.get('action', '') comment = request.POST.get('comment', '') repo_id = request.POST.get('repo_id', '') issue_id = request.POST.get('issue_id', '') if action == '' or repo_id == '' or issue_id == '': return _json_failed() repo = RepoManager.get_repo_by_id(int(repo_id)) issue = IssueManager.get_issue(int(repo_id), int(issue_id)) if repo is None or issue is None: return _json_failed() if issue.assigned != request.user.id and repo.user_id != request.user.id: return _json_failed() orgi_issue = copy.copy(issue) if action == 'fixed': issue.status = 4 elif action == 'close': issue.status = 5 elif action == 'reject': issue.status = 6 if comment != '': issueComment = IssueComment() issueComment.issue_id = issue.id issueComment.user_id = request.user.id issueComment.content = comment issueComment.save() issue.comment_count = issue.comment_count + 1 issue.save() FeedManager.feed_issue_change(request.user, repo, orgi_issue, issue.id) return _json_ok()
def do_issue(request): action = request.POST.get('action', '') comment = request.POST.get('comment', '') repo_id = request.POST.get('repo_id', '') issue_id = request.POST.get('issue_id', '') if action == '' or repo_id == '' or issue_id == '': return _json_failed() repo = RepoManager.get_repo_by_id(int(repo_id)) issue = IssueManager.get_issue(int(repo_id), int(issue_id)) if repo is None or issue is None: return _json_failed() if issue.assigned != request.user.id and repo.user_id != request.user.id: return _json_failed() orgi_issue = copy.copy(issue) if action == 'fixed': issue.status = 4 elif action == 'close': issue.status = 5 elif action == 'reject': issue.status = 6 if comment != '': issueComment = IssueComment() issueComment.issue_id = issue.id issueComment.user_id = request.user.id issueComment.content = comment issueComment.save() issue.comment_count = issue.comment_count + 1 issue.save() FeedManager.feed_issue_change(request.user, repo, orgi_issue, issue.id) return _json_ok()
def fillwith(self): self.repo = RepoManager.get_repo_by_id(self.repo_id) self.creator_userprofile = GsuserManager.get_userprofile_by_id(self.creator_user_id) self.assigned_userprofile = GsuserManager.get_userprofile_by_id(self.assigned) if self.tracker in ISSUE_ATTRS['REV_TRACKERS']: self.tracker_v = ISSUE_ATTRS['REV_TRACKERS'][self.tracker] if self.status in ISSUE_ATTRS['REV_STATUSES']: self.status_v = ISSUE_ATTRS['REV_STATUSES'][self.status] if self.priority in ISSUE_ATTRS['REV_PRIORITIES']: self.priority_v = ISSUE_ATTRS['REV_PRIORITIES'][self.priority]
def create(self, notif_cate, notif_type, from_user_id, to_user_id, relative_id): notifMessage = NotifMessage( notif_cate=notif_cate, notif_type=notif_type, from_user_id=from_user_id, to_user_id=to_user_id, relative_id=relative_id, ) if not relative_id: return notifMessage # without AT_MERGE_COMMENT if notifMessage.is_at_commit(): commitHistory = RepoManager.get_commit_by_id(relative_id) if commitHistory: repo = RepoManager.get_repo_by_id(commitHistory.repo_id) if repo: notifMessage.user_id = repo.user_id notifMessage.repo_id = repo.id elif notifMessage.is_at_issue() or notifMessage.is_issue_cate(): issue = IssueManager.get_issue_by_id(relative_id) if issue: notifMessage.user_id = issue.user_id notifMessage.repo_id = issue.repo_id elif notifMessage.is_at_merge() or notifMessage.is_pull_request_cate(): pullRequest = RepoManager.get_pullRequest_by_id(relative_id) if pullRequest: repo = RepoManager.get_repo_by_id(pullRequest.desc_repo_id) if repo: notifMessage.user_id = repo.user_id notifMessage.repo_id = repo.id elif notifMessage.is_at_issue_comment(): issue_comment = IssueManager.get_issue_comment(relative_id) if issue_comment: issue = IssueManager.get_issue_by_id(issue_comment.issue_id) if issue: notifMessage.user_id = issue.user_id notifMessage.repo_id = issue.repo_id return notifMessage
def create(self, notif_cate, notif_type, from_user_id, to_user_id, relative_id): notifMessage = NotifMessage( notif_cate = notif_cate, notif_type = notif_type, from_user_id = from_user_id, to_user_id = to_user_id, relative_id = relative_id, ) if not relative_id: return notifMessage # without AT_MERGE_COMMENT if notifMessage.is_at_commit(): commitHistory = RepoManager.get_commit_by_id(relative_id) if commitHistory: repo = RepoManager.get_repo_by_id(commitHistory.repo_id) if repo: notifMessage.user_id = repo.user_id notifMessage.repo_id = repo.id elif notifMessage.is_at_issue() or notifMessage.is_issue_cate(): issue = IssueManager.get_issue_by_id(relative_id) if issue: notifMessage.user_id = issue.user_id notifMessage.repo_id = issue.repo_id elif notifMessage.is_at_merge() or notifMessage.is_pull_request_cate(): pullRequest = RepoManager.get_pullRequest_by_id(relative_id) if pullRequest: repo = RepoManager.get_repo_by_id(pullRequest.desc_repo_id) if repo: notifMessage.user_id = repo.user_id notifMessage.repo_id = repo.id elif notifMessage.is_at_issue_comment(): issue_comment = IssueManager.get_issue_comment(relative_id) if issue_comment: issue = IssueManager.get_issue_by_id(issue_comment.issue_id) if issue: notifMessage.user_id = issue.user_id notifMessage.repo_id = issue.repo_id return notifMessage
def _fillwith_push_revref(request, feeds): revref_dict = {} for feed in feeds: if not feed.is_push_revref(): continue push_revref = RepoManager.get_pushrevref_by_id(feed.relative_id) if not push_revref: continue repo = RepoManager.get_repo_by_id(push_revref.repo_id) if repo and repo.auth_type == 2: if not request.user.is_authenticated( ) or not RepoManager.is_allowed_view_access_repo( repo, request.user): continue push_revref.commits = RepoManager.list_commit_by_repoId_pushrevrefId( push_revref.repo_id, push_revref.id, 0, 10) feed.relative_obj = push_revref