Beispiel #1
0
 def clean_organizations(self):
     """Check if valid names have been provided."""
     organizations = self.cleaned_data.get('organizations')
     for name in organizations.split():
         try:
             get_org_data(name)
         except HTTPError:
             raise forms.ValidationError(
                 _("Invalid name: ") + name,
                 code='invalid',
                 params={'name': name},
             )
     return organizations
Beispiel #2
0
def show_repos(request):
    """Get repositories for organizations."""
    context = set_up_context(request)
    if request.method == 'POST':
        form_orgs = OrgNamesForm(request.POST)
        if form_orgs.is_valid():
            session = requests.Session()
            repos_choices = []
            for org_name in form_orgs.cleaned_data['organizations'].split():
                org_data = github.get_org_data(org_name, session)
                org, _ = misc.get_or_create_record(Organization, org_data)
                repos_data = [
                    repo for repo in github.get_org_repos(org_name, session)
                ]
                for repo_data in repos_data:
                    misc.get_or_create_record(
                        org,
                        repo_data,
                        {
                            'is_tracked': False,
                            'is_visible': False
                        },
                    )
                    repos_choices.append(
                        (repo_data['id'], repo_data['name']), )
            session.close()
            form_repos = RepoNamesForm(choices=repos_choices)
            context['form_repos'] = form_repos
    else:
        form_orgs = OrgNamesForm()

    context['form_orgs'] = form_orgs

    return TemplateResponse(request, 'admin/configuration.html', context)