mirror of
https://github.com/portainer/portainer.git
synced 2025-07-30 02:39:41 +02:00
feat(registry): gitlab support (#3107)
* feat(api): gitlab registry type * feat(registries): early support for gitlab registries * feat(app): registry service selector * feat(registry): gitlab support : list repositories and tags - remove features missing * feat(registry): gitlab registry remove features * feat(registry): gitlab switch to registry V2 API for repositories and tags * feat(api): use development extension binary * fix(registry): avoid 401 on gitlab retrieve to disconnect the user * feat(registry): gitlab browse projects without extension * style(app): code cleaning * refactor(app): PR review changes + refactor on types * fix(gitlab): remove gitlab info from registrymanagementconfig and force gitlab type * style(api): go fmt * feat(api): update APIVersion and ExtensionDefinitionsURL * fix(api): fix invalid RM extension URL * feat(registry): PAT scope help * feat(registry): defaults on registry creation * style(registry-creation): update layout and text for Gitlab registry * feat(registry-creation): update gitlab notice
This commit is contained in:
parent
03d9d6afbb
commit
198e92c734
38 changed files with 1022 additions and 160 deletions
|
@ -0,0 +1,86 @@
|
|||
import _ from 'lodash-es';
|
||||
import { RegistryGitlabProject } from '../models/gitlabRegistry';
|
||||
import { RegistryRepositoryGitlabViewModel } from '../models/registryRepository';
|
||||
|
||||
angular.module('portainer.extensions.registrymanagement')
|
||||
.factory('RegistryGitlabService', ['$async', 'Gitlab',
|
||||
function RegistryGitlabServiceFactory($async, Gitlab) {
|
||||
'use strict';
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* PROJECTS
|
||||
*/
|
||||
|
||||
async function _getProjectsPage(env, params, projects) {
|
||||
const response = await Gitlab(env).projects(params).$promise;
|
||||
projects = _.concat(projects, response.data);
|
||||
if (response.next) {
|
||||
params.page = response.next;
|
||||
projects = await _getProjectsPage(env, params, projects);
|
||||
}
|
||||
return projects;
|
||||
}
|
||||
|
||||
async function projectsAsync(url, token) {
|
||||
try {
|
||||
const data = await _getProjectsPage({url: url, token: token}, {page: 1}, []);
|
||||
return _.map(data, (project) => new RegistryGitlabProject(project));
|
||||
} catch (error) {
|
||||
throw {msg: 'Unable to retrieve projects', err: error};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* END PROJECTS
|
||||
*/
|
||||
|
||||
/**
|
||||
* REPOSITORIES
|
||||
*/
|
||||
|
||||
async function _getRepositoriesPage(params, repositories) {
|
||||
const response = await Gitlab().repositories(params).$promise;
|
||||
repositories = _.concat(repositories, response.data);
|
||||
if (response.next) {
|
||||
params.page = response.next;
|
||||
repositories = await _getRepositoriesPage(params, repositories);
|
||||
}
|
||||
return repositories;
|
||||
}
|
||||
|
||||
async function repositoriesAsync(registry) {
|
||||
try {
|
||||
const params = {
|
||||
id: registry.Id,
|
||||
projectId: registry.Gitlab.ProjectId,
|
||||
page: 1
|
||||
};
|
||||
const data = await _getRepositoriesPage(params, []);
|
||||
return _.map(data, (r) => new RegistryRepositoryGitlabViewModel(r));
|
||||
} catch (error) {
|
||||
throw {msg: 'Unable to retrieve repositories', err: error};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* END REPOSITORIES
|
||||
*/
|
||||
|
||||
/**
|
||||
* SERVICE FUNCTIONS DECLARATION
|
||||
*/
|
||||
|
||||
function projects(url, token) {
|
||||
return $async(projectsAsync, url, token);
|
||||
}
|
||||
|
||||
function repositories(registry) {
|
||||
return $async(repositoriesAsync, registry);
|
||||
}
|
||||
|
||||
service.projects = projects;
|
||||
service.repositories = repositories;
|
||||
return service;
|
||||
}
|
||||
]);
|
Loading…
Add table
Add a link
Reference in a new issue