2019-10-19 16:38:07 +02:00
|
|
|
import { apiClient } from '@scm-manager/ui-components';
|
|
|
|
|
import * as types from '../../modules/types';
|
|
|
|
|
import {
|
2018-09-05 14:32:49 +02:00
|
|
|
Action,
|
|
|
|
|
Repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
RepositoryCollection,
|
|
|
|
|
} from '@scm-manager/ui-types';
|
|
|
|
|
import { isPending } from '../../modules/pending';
|
|
|
|
|
import { getFailure } from '../../modules/failure';
|
2018-07-31 16:32:16 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export const FETCH_REPOS = 'scm/repos/FETCH_REPOS';
|
2018-07-31 16:32:16 +02:00
|
|
|
export const FETCH_REPOS_PENDING = `${FETCH_REPOS}_${types.PENDING_SUFFIX}`;
|
|
|
|
|
export const FETCH_REPOS_SUCCESS = `${FETCH_REPOS}_${types.SUCCESS_SUFFIX}`;
|
|
|
|
|
export const FETCH_REPOS_FAILURE = `${FETCH_REPOS}_${types.FAILURE_SUFFIX}`;
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export const FETCH_REPO = 'scm/repos/FETCH_REPO';
|
2018-08-01 18:23:16 +02:00
|
|
|
export const FETCH_REPO_PENDING = `${FETCH_REPO}_${types.PENDING_SUFFIX}`;
|
|
|
|
|
export const FETCH_REPO_SUCCESS = `${FETCH_REPO}_${types.SUCCESS_SUFFIX}`;
|
|
|
|
|
export const FETCH_REPO_FAILURE = `${FETCH_REPO}_${types.FAILURE_SUFFIX}`;
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export const CREATE_REPO = 'scm/repos/CREATE_REPO';
|
2018-08-03 08:52:02 +02:00
|
|
|
export const CREATE_REPO_PENDING = `${CREATE_REPO}_${types.PENDING_SUFFIX}`;
|
|
|
|
|
export const CREATE_REPO_SUCCESS = `${CREATE_REPO}_${types.SUCCESS_SUFFIX}`;
|
|
|
|
|
export const CREATE_REPO_FAILURE = `${CREATE_REPO}_${types.FAILURE_SUFFIX}`;
|
|
|
|
|
export const CREATE_REPO_RESET = `${CREATE_REPO}_${types.RESET_SUFFIX}`;
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export const MODIFY_REPO = 'scm/repos/MODIFY_REPO';
|
2018-08-06 15:41:20 +02:00
|
|
|
export const MODIFY_REPO_PENDING = `${MODIFY_REPO}_${types.PENDING_SUFFIX}`;
|
|
|
|
|
export const MODIFY_REPO_SUCCESS = `${MODIFY_REPO}_${types.SUCCESS_SUFFIX}`;
|
|
|
|
|
export const MODIFY_REPO_FAILURE = `${MODIFY_REPO}_${types.FAILURE_SUFFIX}`;
|
2018-11-06 11:24:01 +01:00
|
|
|
export const MODIFY_REPO_RESET = `${MODIFY_REPO}_${types.RESET_SUFFIX}`;
|
2018-08-06 15:41:20 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export const DELETE_REPO = 'scm/repos/DELETE_REPO';
|
2018-08-03 09:54:04 +02:00
|
|
|
export const DELETE_REPO_PENDING = `${DELETE_REPO}_${types.PENDING_SUFFIX}`;
|
|
|
|
|
export const DELETE_REPO_SUCCESS = `${DELETE_REPO}_${types.SUCCESS_SUFFIX}`;
|
|
|
|
|
export const DELETE_REPO_FAILURE = `${DELETE_REPO}_${types.FAILURE_SUFFIX}`;
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
const CONTENT_TYPE = 'application/vnd.scmm-repository+json;v=2';
|
2018-08-03 08:52:02 +02:00
|
|
|
|
2018-08-01 18:23:16 +02:00
|
|
|
// fetch repos
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
const SORT_BY = 'sortBy=namespaceAndName';
|
2018-07-31 16:32:16 +02:00
|
|
|
|
2018-10-09 16:46:39 +02:00
|
|
|
export function fetchRepos(link: string) {
|
|
|
|
|
return fetchReposByLink(link);
|
2018-08-01 14:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 16:42:27 +02:00
|
|
|
export function fetchReposByPage(link: string, page: number, filter?: string) {
|
2019-04-10 17:25:36 +02:00
|
|
|
if (filter) {
|
|
|
|
|
return fetchReposByLink(
|
2019-10-19 16:38:07 +02:00
|
|
|
`${link}?page=${page - 1}&q=${decodeURIComponent(filter)}`,
|
2019-04-10 17:25:36 +02:00
|
|
|
);
|
|
|
|
|
}
|
2018-10-09 16:46:39 +02:00
|
|
|
return fetchReposByLink(`${link}?page=${page - 1}`);
|
2018-08-01 14:56:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function appendSortByLink(url: string) {
|
|
|
|
|
if (url.includes(SORT_BY)) {
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
let urlWithSortBy = url;
|
2019-10-19 16:38:07 +02:00
|
|
|
if (url.includes('?')) {
|
|
|
|
|
urlWithSortBy += '&';
|
2018-08-01 14:56:24 +02:00
|
|
|
} else {
|
2019-10-19 16:38:07 +02:00
|
|
|
urlWithSortBy += '?';
|
2018-08-01 14:56:24 +02:00
|
|
|
}
|
|
|
|
|
return urlWithSortBy + SORT_BY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchReposByLink(link: string) {
|
|
|
|
|
const url = appendSortByLink(link);
|
2018-07-31 16:32:16 +02:00
|
|
|
return function(dispatch: any) {
|
|
|
|
|
dispatch(fetchReposPending());
|
|
|
|
|
return apiClient
|
2018-08-01 14:56:24 +02:00
|
|
|
.get(url)
|
2018-07-31 16:32:16 +02:00
|
|
|
.then(response => response.json())
|
|
|
|
|
.then(repositories => {
|
|
|
|
|
dispatch(fetchReposSuccess(repositories));
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
dispatch(fetchReposFailure(err));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchReposPending(): Action {
|
|
|
|
|
return {
|
2019-10-19 16:38:07 +02:00
|
|
|
type: FETCH_REPOS_PENDING,
|
2018-07-31 16:32:16 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchReposSuccess(repositories: RepositoryCollection): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: FETCH_REPOS_SUCCESS,
|
2019-10-19 16:38:07 +02:00
|
|
|
payload: repositories,
|
2018-07-31 16:32:16 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchReposFailure(err: Error): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: FETCH_REPOS_FAILURE,
|
2019-10-19 16:38:07 +02:00
|
|
|
payload: err,
|
2018-07-31 16:32:16 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-01 18:23:16 +02:00
|
|
|
// fetch repo
|
2018-11-05 13:52:46 +01:00
|
|
|
export function fetchRepoByLink(repo: Repository) {
|
|
|
|
|
return fetchRepo(repo._links.self.href, repo.namespace, repo.name);
|
|
|
|
|
}
|
2018-08-01 18:23:16 +02:00
|
|
|
|
2018-11-05 13:52:46 +01:00
|
|
|
export function fetchRepoByName(link: string, namespace: string, name: string) {
|
2019-10-19 16:38:07 +02:00
|
|
|
const repoUrl = link.endsWith('/') ? link : link + '/';
|
2018-11-05 13:52:46 +01:00
|
|
|
return fetchRepo(`${repoUrl}${namespace}/${name}`, namespace, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fetchRepo(link: string, namespace: string, name: string) {
|
2018-08-01 18:23:16 +02:00
|
|
|
return function(dispatch: any) {
|
|
|
|
|
dispatch(fetchRepoPending(namespace, name));
|
2018-08-03 08:52:02 +02:00
|
|
|
return apiClient
|
2018-11-05 13:52:46 +01:00
|
|
|
.get(link)
|
2018-08-01 18:23:16 +02:00
|
|
|
.then(response => response.json())
|
2018-08-03 08:52:02 +02:00
|
|
|
.then(repository => {
|
|
|
|
|
dispatch(fetchRepoSuccess(repository));
|
|
|
|
|
})
|
2018-08-01 18:23:16 +02:00
|
|
|
.catch(err => {
|
2018-08-03 08:52:02 +02:00
|
|
|
dispatch(fetchRepoFailure(namespace, name, err));
|
2018-08-01 18:23:16 +02:00
|
|
|
});
|
2018-08-03 08:52:02 +02:00
|
|
|
};
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchRepoPending(namespace: string, name: string): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: FETCH_REPO_PENDING,
|
|
|
|
|
payload: {
|
|
|
|
|
namespace,
|
2019-10-19 16:38:07 +02:00
|
|
|
name,
|
2018-08-01 18:23:16 +02:00
|
|
|
},
|
2019-10-19 16:38:07 +02:00
|
|
|
itemId: namespace + '/' + name,
|
2018-08-01 18:23:16 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchRepoSuccess(repository: Repository): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: FETCH_REPO_SUCCESS,
|
|
|
|
|
payload: repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
itemId: createIdentifier(repository),
|
2018-08-01 18:23:16 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 08:52:02 +02:00
|
|
|
export function fetchRepoFailure(
|
|
|
|
|
namespace: string,
|
|
|
|
|
name: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
error: Error,
|
2018-08-03 08:52:02 +02:00
|
|
|
): Action {
|
2018-08-01 18:23:16 +02:00
|
|
|
return {
|
|
|
|
|
type: FETCH_REPO_FAILURE,
|
|
|
|
|
payload: {
|
|
|
|
|
namespace,
|
|
|
|
|
name,
|
2019-10-19 16:38:07 +02:00
|
|
|
error,
|
2018-08-01 18:23:16 +02:00
|
|
|
},
|
2019-10-19 16:38:07 +02:00
|
|
|
itemId: namespace + '/' + name,
|
2018-08-01 18:23:16 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 08:52:02 +02:00
|
|
|
// create repo
|
|
|
|
|
|
2018-10-11 10:42:49 +02:00
|
|
|
export function createRepo(
|
|
|
|
|
link: string,
|
|
|
|
|
repository: Repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
callback?: (repo: Repository) => void,
|
2018-10-11 10:42:49 +02:00
|
|
|
) {
|
2018-08-03 08:52:02 +02:00
|
|
|
return function(dispatch: any) {
|
|
|
|
|
dispatch(createRepoPending());
|
|
|
|
|
return apiClient
|
2018-10-11 08:19:50 +02:00
|
|
|
.post(link, repository, CONTENT_TYPE)
|
2019-01-22 11:58:31 +01:00
|
|
|
.then(response => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const location = response.headers.get('Location');
|
2018-08-03 08:52:02 +02:00
|
|
|
dispatch(createRepoSuccess());
|
2019-01-22 11:58:31 +01:00
|
|
|
return apiClient.get(location);
|
|
|
|
|
})
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
.then(response => {
|
2018-08-03 08:52:02 +02:00
|
|
|
if (callback) {
|
2019-01-22 11:58:31 +01:00
|
|
|
callback(response);
|
2018-08-03 08:52:02 +02:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
dispatch(createRepoFailure(err));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createRepoPending(): Action {
|
|
|
|
|
return {
|
2019-10-19 16:38:07 +02:00
|
|
|
type: CREATE_REPO_PENDING,
|
2018-08-03 08:52:02 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createRepoSuccess(): Action {
|
|
|
|
|
return {
|
2019-10-19 16:38:07 +02:00
|
|
|
type: CREATE_REPO_SUCCESS,
|
2018-08-03 08:52:02 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createRepoFailure(err: Error): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: CREATE_REPO_FAILURE,
|
2019-10-19 16:38:07 +02:00
|
|
|
payload: err,
|
2018-08-03 08:52:02 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createRepoReset(): Action {
|
|
|
|
|
return {
|
2019-10-19 16:38:07 +02:00
|
|
|
type: CREATE_REPO_RESET,
|
2018-08-03 08:52:02 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 15:41:20 +02:00
|
|
|
// modify
|
|
|
|
|
|
|
|
|
|
export function modifyRepo(repository: Repository, callback?: () => void) {
|
|
|
|
|
return function(dispatch: any) {
|
|
|
|
|
dispatch(modifyRepoPending(repository));
|
|
|
|
|
|
|
|
|
|
return apiClient
|
|
|
|
|
.put(repository._links.update.href, repository, CONTENT_TYPE)
|
|
|
|
|
.then(() => {
|
|
|
|
|
dispatch(modifyRepoSuccess(repository));
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
})
|
2018-11-05 13:52:46 +01:00
|
|
|
.then(() => {
|
|
|
|
|
dispatch(fetchRepoByLink(repository));
|
|
|
|
|
})
|
2018-11-15 21:39:08 +01:00
|
|
|
.catch(error => {
|
2018-08-06 15:41:20 +02:00
|
|
|
dispatch(modifyRepoFailure(repository, error));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function modifyRepoPending(repository: Repository): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: MODIFY_REPO_PENDING,
|
|
|
|
|
payload: repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
itemId: createIdentifier(repository),
|
2018-08-06 15:41:20 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function modifyRepoSuccess(repository: Repository): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: MODIFY_REPO_SUCCESS,
|
|
|
|
|
payload: repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
itemId: createIdentifier(repository),
|
2018-08-06 15:41:20 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function modifyRepoFailure(
|
|
|
|
|
repository: Repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
error: Error,
|
2018-08-06 15:41:20 +02:00
|
|
|
): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: MODIFY_REPO_FAILURE,
|
2019-10-19 16:38:07 +02:00
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
repository,
|
|
|
|
|
},
|
|
|
|
|
itemId: createIdentifier(repository),
|
2018-08-06 15:41:20 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 11:24:01 +01:00
|
|
|
export function modifyRepoReset(repository: Repository): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: MODIFY_REPO_RESET,
|
2019-10-19 16:38:07 +02:00
|
|
|
payload: {
|
|
|
|
|
repository,
|
|
|
|
|
},
|
|
|
|
|
itemId: createIdentifier(repository),
|
2018-11-06 11:24:01 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 09:54:04 +02:00
|
|
|
// delete
|
|
|
|
|
|
|
|
|
|
export function deleteRepo(repository: Repository, callback?: () => void) {
|
|
|
|
|
return function(dispatch: any) {
|
|
|
|
|
dispatch(deleteRepoPending(repository));
|
|
|
|
|
return apiClient
|
|
|
|
|
.delete(repository._links.delete.href)
|
|
|
|
|
.then(() => {
|
|
|
|
|
dispatch(deleteRepoSuccess(repository));
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
dispatch(deleteRepoFailure(repository, err));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function deleteRepoPending(repository: Repository): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: DELETE_REPO_PENDING,
|
|
|
|
|
payload: repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
itemId: createIdentifier(repository),
|
2018-08-03 09:54:04 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function deleteRepoSuccess(repository: Repository): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: DELETE_REPO_SUCCESS,
|
|
|
|
|
payload: repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
itemId: createIdentifier(repository),
|
2018-08-03 09:54:04 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function deleteRepoFailure(
|
|
|
|
|
repository: Repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
error: Error,
|
2018-08-03 09:54:04 +02:00
|
|
|
): Action {
|
|
|
|
|
return {
|
|
|
|
|
type: DELETE_REPO_FAILURE,
|
|
|
|
|
payload: {
|
|
|
|
|
error,
|
2019-10-19 16:38:07 +02:00
|
|
|
repository,
|
2018-08-03 09:54:04 +02:00
|
|
|
},
|
2019-10-19 16:38:07 +02:00
|
|
|
itemId: createIdentifier(repository),
|
2018-08-03 09:54:04 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 16:32:16 +02:00
|
|
|
// reducer
|
|
|
|
|
|
2018-08-01 18:23:16 +02:00
|
|
|
function createIdentifier(repository: Repository) {
|
2019-10-19 16:38:07 +02:00
|
|
|
return repository.namespace + '/' + repository.name;
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-31 16:32:16 +02:00
|
|
|
function normalizeByNamespaceAndName(
|
2019-10-19 16:38:07 +02:00
|
|
|
repositoryCollection: RepositoryCollection,
|
2018-07-31 16:32:16 +02:00
|
|
|
) {
|
|
|
|
|
const names = [];
|
|
|
|
|
const byNames = {};
|
|
|
|
|
for (const repository of repositoryCollection._embedded.repositories) {
|
2018-08-01 18:23:16 +02:00
|
|
|
const identifier = createIdentifier(repository);
|
2018-07-31 16:32:16 +02:00
|
|
|
names.push(identifier);
|
|
|
|
|
byNames[identifier] = repository;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
list: {
|
|
|
|
|
...repositoryCollection,
|
|
|
|
|
_embedded: {
|
2019-10-19 16:38:07 +02:00
|
|
|
repositories: names,
|
|
|
|
|
},
|
2018-07-31 16:32:16 +02:00
|
|
|
},
|
2019-10-19 16:38:07 +02:00
|
|
|
byNames: byNames,
|
2018-07-31 16:32:16 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
const reducerByNames = (state: object, repository: Repository) => {
|
2018-08-01 18:23:16 +02:00
|
|
|
const identifier = createIdentifier(repository);
|
2019-05-15 14:35:05 +02:00
|
|
|
return {
|
2018-08-01 18:23:16 +02:00
|
|
|
...state,
|
|
|
|
|
byNames: {
|
|
|
|
|
...state.byNames,
|
2019-10-19 16:38:07 +02:00
|
|
|
[identifier]: repository,
|
|
|
|
|
},
|
2018-08-01 18:23:16 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-31 16:32:16 +02:00
|
|
|
export default function reducer(
|
2019-10-19 16:38:07 +02:00
|
|
|
state: object = {},
|
|
|
|
|
action: Action = {
|
|
|
|
|
type: 'UNKNOWN',
|
|
|
|
|
},
|
|
|
|
|
): object {
|
2018-08-01 18:23:16 +02:00
|
|
|
if (!action.payload) {
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
|
case FETCH_REPOS_SUCCESS:
|
2018-08-01 14:56:24 +02:00
|
|
|
return normalizeByNamespaceAndName(action.payload);
|
2018-08-01 18:23:16 +02:00
|
|
|
case FETCH_REPO_SUCCESS:
|
|
|
|
|
return reducerByNames(state, action.payload);
|
|
|
|
|
default:
|
2018-08-03 08:52:02 +02:00
|
|
|
return state;
|
2018-07-31 16:32:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// selectors
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export function getRepositoryCollection(state: object) {
|
2018-07-31 16:32:16 +02:00
|
|
|
if (state.repos && state.repos.list && state.repos.byNames) {
|
|
|
|
|
const repositories = [];
|
|
|
|
|
for (let repositoryName of state.repos.list._embedded.repositories) {
|
|
|
|
|
repositories.push(state.repos.byNames[repositoryName]);
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
...state.repos.list,
|
|
|
|
|
_embedded: {
|
2019-10-19 16:38:07 +02:00
|
|
|
repositories,
|
|
|
|
|
},
|
2018-07-31 16:32:16 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-01 10:00:53 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export function isFetchReposPending(state: object) {
|
2018-08-01 10:00:53 +02:00
|
|
|
return isPending(state, FETCH_REPOS);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export function getFetchReposFailure(state: object) {
|
2018-08-01 10:00:53 +02:00
|
|
|
return getFailure(state, FETCH_REPOS);
|
|
|
|
|
}
|
2018-08-01 18:23:16 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export function getRepository(state: object, namespace: string, name: string) {
|
2018-08-01 18:23:16 +02:00
|
|
|
if (state.repos && state.repos.byNames) {
|
2019-10-19 16:38:07 +02:00
|
|
|
return state.repos.byNames[namespace + '/' + name];
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 08:52:02 +02:00
|
|
|
export function isFetchRepoPending(
|
2019-10-19 16:38:07 +02:00
|
|
|
state: object,
|
2018-08-03 08:52:02 +02:00
|
|
|
namespace: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
name: string,
|
2018-08-03 08:52:02 +02:00
|
|
|
) {
|
2019-10-19 16:38:07 +02:00
|
|
|
return isPending(state, FETCH_REPO, namespace + '/' + name);
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-03 08:52:02 +02:00
|
|
|
export function getFetchRepoFailure(
|
2019-10-19 16:38:07 +02:00
|
|
|
state: object,
|
2018-08-03 08:52:02 +02:00
|
|
|
namespace: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
name: string,
|
2018-08-03 08:52:02 +02:00
|
|
|
) {
|
2019-10-19 16:38:07 +02:00
|
|
|
return getFailure(state, FETCH_REPO, namespace + '/' + name);
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
2018-08-03 08:52:02 +02:00
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export function isAbleToCreateRepos(state: object) {
|
2018-08-03 09:54:04 +02:00
|
|
|
return !!(
|
2018-08-03 08:52:02 +02:00
|
|
|
state.repos &&
|
|
|
|
|
state.repos.list &&
|
|
|
|
|
state.repos.list._links &&
|
|
|
|
|
state.repos.list._links.create
|
2018-08-03 09:54:04 +02:00
|
|
|
);
|
2018-08-03 08:52:02 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export function isCreateRepoPending(state: object) {
|
2018-08-03 08:52:02 +02:00
|
|
|
return isPending(state, CREATE_REPO);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export function getCreateRepoFailure(state: object) {
|
2018-08-03 08:52:02 +02:00
|
|
|
return getFailure(state, CREATE_REPO);
|
|
|
|
|
}
|
2018-08-03 09:54:04 +02:00
|
|
|
|
2018-08-06 15:41:20 +02:00
|
|
|
export function isModifyRepoPending(
|
2019-10-19 16:38:07 +02:00
|
|
|
state: object,
|
2018-08-06 15:41:20 +02:00
|
|
|
namespace: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
name: string,
|
2018-08-06 15:41:20 +02:00
|
|
|
) {
|
2019-10-19 16:38:07 +02:00
|
|
|
return isPending(state, MODIFY_REPO, namespace + '/' + name);
|
2018-08-06 15:41:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getModifyRepoFailure(
|
2019-10-19 16:38:07 +02:00
|
|
|
state: object,
|
2018-08-06 15:41:20 +02:00
|
|
|
namespace: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
name: string,
|
2018-08-06 15:41:20 +02:00
|
|
|
) {
|
2019-10-19 16:38:07 +02:00
|
|
|
return getFailure(state, MODIFY_REPO, namespace + '/' + name);
|
2018-08-06 15:41:20 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-03 09:54:04 +02:00
|
|
|
export function isDeleteRepoPending(
|
2019-10-19 16:38:07 +02:00
|
|
|
state: object,
|
2018-08-03 09:54:04 +02:00
|
|
|
namespace: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
name: string,
|
2018-08-03 09:54:04 +02:00
|
|
|
) {
|
2019-10-19 16:38:07 +02:00
|
|
|
return isPending(state, DELETE_REPO, namespace + '/' + name);
|
2018-08-03 09:54:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getDeleteRepoFailure(
|
2019-10-19 16:38:07 +02:00
|
|
|
state: object,
|
2018-08-03 09:54:04 +02:00
|
|
|
namespace: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
name: string,
|
2018-08-03 09:54:04 +02:00
|
|
|
) {
|
2019-10-19 16:38:07 +02:00
|
|
|
return getFailure(state, DELETE_REPO, namespace + '/' + name);
|
2018-08-03 09:54:04 +02:00
|
|
|
}
|
2018-10-11 10:42:49 +02:00
|
|
|
|
|
|
|
|
export function getPermissionsLink(
|
2019-10-19 16:38:07 +02:00
|
|
|
state: object,
|
2018-10-11 10:42:49 +02:00
|
|
|
namespace: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
name: string,
|
2018-10-11 10:42:49 +02:00
|
|
|
) {
|
|
|
|
|
const repo = getRepository(state, namespace, name);
|
|
|
|
|
return repo && repo._links ? repo._links.permissions.href : undefined;
|
|
|
|
|
}
|