def update(self, myGitlab: GitLab) -> None: self.__syncing_progress = 0 self.__is_syncing = True myGitlab.set_project(projectID=self.__project.project_id) # construct a thread list that each thread responsible to update a different manager myThreadList: list = [ threading.Thread(target=self.__update_merge_request_manager, args=(myGitlab, )), threading.Thread(target=self.__update_member_manager, args=(myGitlab, )), threading.Thread(target=self.__update_commits_manager, args=(myGitlab, )), threading.Thread(target=self.__update_issues_manager, args=(myGitlab, )), ] self.__syncing_state = "Syncing data from remote..." self.__start_and_join_all_thread(myThreadList) self.__update_code_diff_manager(myGitlab) myThreadList: list = [ threading.Thread(target=self.__analyze_master_commits_code_diff, args=()), threading.Thread(target=self.__analyze_merge_requests_code_diff, args=()), ] self.__syncing_state = "Analyzing..." self.__start_and_join_all_thread(myThreadList) self.__syncing_state = "Synced" self.__last_synced = datetime.datetime.now() self.__is_syncing = False
def __update_issues_manager(self, myGitlab: GitLab) -> None: issueList: list = myGitlab.get_issue_list() self.__issuesManager.populate_issue_list(issueList) # Get comments for issue in issueList: issue_notes = myGitlab.get_comments_of_issue(issue.iid) for item in issue_notes: if item.system is False: self.__commentsManager.add_comment(item, issue.author["name"]) self.__syncing_progress = self.__syncing_progress + 1
def __update_merge_request_manager(self, myGitlab: GitLab) -> None: mergeRequests, commitsForMR = myGitlab.get_merge_requests_and_commits( state="all") for i in range(0, len(mergeRequests)): newMR = self.__mergeRequestManager.add_merge_request( mergeRequests[i], commitsForMR[i]) # Get comments mr_notes = myGitlab.get_comments_of_mr(mergeRequests[i].iid) for item in mr_notes: if item.system is False: newComment = self.__commentsManager.add_comment( item, mergeRequests[i].author["name"]) newMR.add_comment(newComment.noteable_iid) self.__syncing_progress = self.__syncing_progress + 1
def __update_commits_manager(self, myGitlab: GitLab) -> None: commitList: list = myGitlab.get_commit_list_for_project() tempUserSet: set = set() for commit in commitList: # Get all git users, set will only store unique values tempUserSet.add(commit.author_name) self.__commitsManager.add_commit(commit) # Get comments commit_notes = myGitlab.get_comments_of_commit(commit.short_id) for item in commit_notes: self.__commentsManager.add_comment(item, commit.author_name, commit.short_id) self.__user_list = list(tempUserSet) self.__syncing_progress = self.__syncing_progress + 1
def __update_code_diff_for_commit_list(self, commitList: List[Commit], myGitLab: GitLab) -> None: for commit in commitList: codeDiff: List[dict] = myGitLab.get_commits_code_diff( commit.short_id) self.__update_code_diff(codeDiff) codeDiffID = self.__codeDiffManager.append_code_diff(codeDiff) commit.code_diff_id = codeDiffID
def __update_code_diff_for_merge_request_and_commits( self, myGitlab: GitLab) -> None: mr: MergeRequest for mr in self.__mergeRequestManager.merge_request_list: codeDiff = myGitlab.get_merge_request_code_diff_latest_version( mr.iid) self.__update_code_diff(codeDiff) codeDiffID = self.__codeDiffManager.append_code_diff(codeDiff) mr.code_diff_id = codeDiffID self.__update_code_diff_for_commit_list(mr.related_commits_list, myGitlab)
def __init__(self, user_token: str, user_token_hashed=None, url=None): self.__project_list: List[GitLabProject] = [] self.__configs: dict = {} self.__gitlab: GitLab = GitLab(user_token, url) self.__user_token_hashed: str = user_token_hashed # hashed self.__last_time_access: datetime = datetime.datetime.now() if self.__gitlab.authenticate(): self.__username: str = self.__gitlab.get_username() # related to user_token self.__update_project_list() else: raise gitlab.exceptions.GitlabAuthenticationError
import os import sys sys.path.append(os.path.abspath("./server")) from interface.gitlab_project_interface import GitLabProject from interface.gitlab_interface import GitLab from model.project import Project from model.code_diff import CodeDiff from manager.code_diff_Analyzer import CodeDiffAnalyzer """ Below are only for testing purpose """ if __name__ == "__main__": myGitLab = GitLab(token="EJf7qdRqxdKWu1ydozLe", url="https://cmpt373-1211-12.cmpt.sfu.ca/") if myGitLab.authenticate(): print("authenticated") project = myGitLab.find_project(2) gitLabProject = GitLabProject(project=project) gitLabProject.update(myGitLab) print("Done!") temp = CodeDiffAnalyzer() diffs = project.commits.get("d95a38e6").diff() for diff in diffs: print(diff) print(temp.get_code_diff_statistic(CodeDiff(diff)), '\n')
def __update_member_manager(self, myGitlab: GitLab) -> None: members: list = myGitlab.get_all_members() for member in members: self.__membersManager.add_member(member) self.__syncing_progress = self.__syncing_progress + 1