def add_reviewer(cohort, content_item, reviewer, add_as_project_reviewer): api = Api(PERSONAL_GITHUB_NAME) projects = get_projects(cohort, content_item) # for o in projects: print(f"{o.id} {o}\n\t{o.content_item}\n\t{o.repository.full_name}\n") # cohort_users = cohort.get_member_users() # assert len(projects) == len(cohort_users), f"{projects}\n{cohort_users}" # if add_as_project_reviewer: if "@" in reviewer: user = User.objects.get(email=reviewer) else: user = User.objects.get(social_profile__github_name=reviewer) github_name = user.social_profile.github_name # else: # github_name = reviewer for project in projects: print(project) if project.repository: add_collaborator(api, project.repository.full_name, github_name) project.save() if add_as_project_reviewer: project.reviewer_users.add(user) project.save()
def assign_random_reviewers(projects, users): api = Api(PERSONAL_GITHUB_NAME) shuffled_reviewers = list( shuffle_project_reviewers(projects, [o for o in users if o.active]) ) broken = [ project for project, _ in shuffled_reviewers if not project.repository.full_name.startswith(ORGANISATION) ] # assert broken == [], "\n".join([f"{project.id} {project}" for project in broken]) for project, user in shuffled_reviewers: print(user) if project.repository and project.repository.full_name.startswith(ORGANISATION): add_collaborator( api, project.repository.full_name, user.social_profile.github_name ) project.reviewer_users.add(user) project.save() try: card = project.agile_card except AgileCard.DoesNotExist: pass else: assert card is not None card.reviewers.set(project.reviewer_users.all()) card.save()
def invite_github_collaborators_to_repo(self): from social_auth.github_api import Api from git_real.helpers import add_collaborator users = list(self.recruit_users.all()) + list( self.reviewer_users.all()) assert len(users) >= 1, "This repo has no collaborators to add" api = Api(GITHUB_BOT_USERNAME) for user in users: add_collaborator(api, self.repository.full_name, user.social_profile.github_name)
def handle(self, *args, **options): api = Api(PERSONAL_GITHUB_NAME) for proj in RecruitProject.objects.filter(repository__owner=ORGANISATION): repo = proj.repository print(repo) protect_master(api, repo.full_name) for user in proj.reviewer_users.all(): print(user.social_profile.github_name) add_collaborator(api, repo.full_name, user.social_profile.github_name) for user in proj.recruit_users.all(): print(user.social_profile.github_name) add_collaborator(api, repo.full_name, user.social_profile.github_name) print()
def assign_random_reviewers(cards, users): api = Api(PERSONAL_GITHUB_NAME) shuffled_reviewers = list( shuffle_project_reviewers(cards, [o for o in users if o.active])) for card, user in shuffled_reviewers: print(user) if card.recruit_project: project = card.recruit_project if project.repository and project.repository.full_name.startswith( ORGANISATION): add_collaborator(api, project.repository.full_name, user.social_profile.github_name) project.reviewer_users.add(user) project.save() if user not in card.reviewers.all(): card.reviewers.add(user) card.save()
def add_reviewer(team, content_item, reviewer, add_as_project_reviewer): api = Api(PERSONAL_GITHUB_NAME) cards = get_team_cards(team, content_item) if "@" in reviewer: user = User.objects.get(email=reviewer) else: user = User.objects.get(social_profile__github_name=reviewer) github_name = user.social_profile.github_name for card in cards: if card.recruit_project and card.repository: add_collaborator(api, card.repository.full_name, github_name) card.save() if add_as_project_reviewer: card.reviewers.add(user) if card.recruit_project: card.recruit_project.reviewer_users.add(user) card.save()
api = Api(PERSONAL_GITHUB_NAME) cohort_ds = Cohort.objects.get(pk=50) cohort_web = Cohort.objects.get(pk=51) cohorts = [cohort_ds, cohort_web] cohort_users = [] for cohort in cohorts: cohort_users.extend( [o.user for o in RecruitCohort.objects.filter(cohort=cohort)]) projects = [] for user in cohort_users: projects.extend(RecruitProject.objects.filter(recruit_users__in=[user])) repos = [project.repository for project in projects if project.repository] repo_names = [ repo.full_name for repo in repos if repo.full_name.startswith(ORGANISATION) ] staff_count = len(staff_github_names) repo_count = len(repo_names) for repo_number, repo_full_name in enumerate(repo_names): print(f"Repo [{repo_number}/{repo_count}]: {repo_full_name}") for staff_number, github_user_name in enumerate(staff_github_names): print( f"\t adding user [{staff_number}/{staff_count}]: {github_user_name}" ) add_collaborator(api, repo_full_name, github_user_name)