def process_row(row): repo_url = row[REPO] found = re.search("https://github.com/(.*)\.git", repo_url) if not found: print(f"bad url: {repo_url}") return repo_full_name = found.groups()[0] try: repo_dict = git_helpers.get_repo( github_auth_login=GIT_REAL_BOT_USERNAME, repo_full_name=repo_full_name ) except AssertionError: print(f"bad url: {repo_url}") return repo = git_helpers.save_repo( repo_dict ) # note thet the repo itself doesn't "belong" to anyone try: card = AgileCard.objects.get(pk=int(row[CARD_ID])) except AgileCard.DoesNotExist: print(f"bad card if: {row[CARD_ID]}") return card.recruit_project.repo = repo card.recruit_project.save()
def create_repo_and_assign_collaborators(self, card_flavour_names): from git_real.constants import GITHUB_BOT_USERNAME, ORGANISATION github_auth_login = GITHUB_BOT_USERNAME assert ( self.recruit_users.count() == 1 ), f"There should be 1 assignee. No more and no less: {self.assignees.all()}" recruit_user = self.recruit_users.first() try: social = social_models.SocialProfile.objects.get(user=recruit_user) except social_models.SocialProfile.DoesNotExist: logger.error( f"{recruit_user.id} {recruit_user} has no github name") raise github_name = social.github_name assert github_name, f"{recruit_user.id} {recruit_user} has no github name" repo_name = self._generate_repo_name_for_project( user=recruit_user, flavour_names=card_flavour_names, content_item=self.content_item, ) repo_full_name = f"{ORGANISATION}/{repo_name}" readme_text = "\n".join([ f"{self.content_item.title} ({self.content_item.id})", f"For raw project instructions see: {self.content_item.url}", ]) git_helpers.create_repo_and_assign_contributer( github_auth_login, repo_full_name, github_user_name=github_name, readme_text=readme_text, ) repo_dict = git_helpers.get_repo(github_auth_login=github_auth_login, repo_full_name=repo_full_name) repo = git_helpers.save_repo( repo_dict) # note thet the repo itself doesn't "belong" to anyone self.repository = repo self.invite_github_collaborators_to_repo() self.save()
def scrape_and_save_user_repos(api, username, user): print(f"\nfetching repos for: {user}") repo_dicts = api.request_pages(f"users/{username}/repos", response404=[]) for repo in repo_dicts: helpers.save_repo(repo, user)
def scrape_and_save_organisation_repos(api, organisation_name): repo_dicts = api.request_pages(f"orgs/{organisation_name}/repos") for repo in repo_dicts: helpers.save_repo(repo) # (#161)