Пример #1
0
 def get_projects(gitlab_user):
     gitlab_projects_including_non_visualisation = gitlab_api_v4(
         'GET',
         f'projects',
         params=(
             ('archived', 'false'),
             ('min_access_level', DEVELOPER_ACCESS_LEVEL),
             ('sudo', gitlab_user['id']),
             ('per_page', '100'),
         ),
     )
     gitlab_projects = [
         gitlab_project
         for gitlab_project in gitlab_projects_including_non_visualisation
         if 'visualisation' in [tag.lower() for tag in gitlab_project['tag_list']]
     ]
     return sorted(
         [
             {
                 'gitlab_project': gitlab_project,
                 'manage_link': reverse(
                     'visualisations:branch',
                     kwargs={
                         'gitlab_project_id': gitlab_project['id'],
                         'branch_name': gitlab_project['default_branch'],
                     },
                 ),
             }
             for gitlab_project in gitlab_projects
         ],
         key=lambda d: d['gitlab_project']['name'].lower(),
     )
Пример #2
0
def _visualisation_branches(gitlab_project):
    # Sort default branch first, the remaining in last commit order
    def branch_sort_key(branch):
        return (
            branch['name'] == gitlab_project['default_branch'],
            branch['commit']['committed_date'],
            branch['name'],
        )

    return sorted(
        gitlab_api_v4('GET', f'/projects/{gitlab_project["id"]}/repository/branches'),
        key=branch_sort_key,
        reverse=True,
    )
Пример #3
0
def _gitlab_ecr_pipeline_get(pipeline_id):
    return gitlab_api_v4(
        'GET', f'/projects/{ECR_PROJECT_ID}/pipelines/{pipeline_id}')
Пример #4
0
def _gitlab_ecr_pipeline_cancel(pipeline_id):
    return gitlab_api_v4(
        'POST', f'/projects/{ECR_PROJECT_ID}/pipelines/{pipeline_id}/cancel')
Пример #5
0
def _gitlab_ecr_pipeline_get(pipeline_id):
    return gitlab_api_v4(
        "GET", f"/projects/{ECR_PROJECT_ID}/pipelines/{pipeline_id}")
Пример #6
0
def _gitlab_ecr_pipeline_cancel(pipeline_id):
    return gitlab_api_v4(
        "POST", f"/projects/{ECR_PROJECT_ID}/pipelines/{pipeline_id}/cancel")
Пример #7
0
def visualisations_html_GET(request):
    gitlab_users = gitlab_api_v4(
        'GET',
        f'/users',
        params=(
            ('extern_uid', request.user.profile.sso_id),
            ('provider', 'oauth2_generic'),
        ),
    )
    has_gitlab_user = bool(gitlab_users)

    # Something has really gone wrong if GitLab has multiple users with the
    # same SSO ID
    if len(gitlab_users) > 1:
        return HttpResponse(status=500)

    gitlab_url = (
        urlsplit(
            gitlab_api_v4('GET', f'groups/{settings.GITLAB_VISUALISATIONS_GROUP}')[
                'web_url'
            ]
        )
        ._replace(path='/', query='', fragment='')
        .geturl()
    )

    def get_projects(gitlab_user):
        gitlab_projects_including_non_visualisation = gitlab_api_v4(
            'GET',
            f'projects',
            params=(
                ('archived', 'false'),
                ('min_access_level', DEVELOPER_ACCESS_LEVEL),
                ('sudo', gitlab_user['id']),
                ('per_page', '100'),
            ),
        )
        gitlab_projects = [
            gitlab_project
            for gitlab_project in gitlab_projects_including_non_visualisation
            if 'visualisation' in [tag.lower() for tag in gitlab_project['tag_list']]
        ]
        return sorted(
            [
                {
                    'gitlab_project': gitlab_project,
                    'manage_link': reverse(
                        'visualisations:branch',
                        kwargs={
                            'gitlab_project_id': gitlab_project['id'],
                            'branch_name': gitlab_project['default_branch'],
                        },
                    ),
                }
                for gitlab_project in gitlab_projects
            ],
            key=lambda d: d['gitlab_project']['name'].lower(),
        )

    return render(
        request,
        'visualisations.html',
        {
            'has_gitlab_user': has_gitlab_user,
            'gitlab_url': gitlab_url,
            'projects': get_projects(gitlab_users[0]) if has_gitlab_user else [],
        },
        status=200,
    )