mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
fix missing checkout/clone description on repository information page
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
|
||||
import * as validation from "./validation.js";
|
||||
import * as urls from "./urls";
|
||||
import * as repositories from "./repositories.js";
|
||||
|
||||
export { validation, urls };
|
||||
export { validation, urls, repositories };
|
||||
|
||||
export { default as DateFromNow } from "./DateFromNow.js";
|
||||
export { default as ErrorNotification } from "./ErrorNotification.js";
|
||||
@@ -18,6 +19,8 @@ export { default as ProtectedRoute } from "./ProtectedRoute.js";
|
||||
|
||||
export { apiClient, NOT_FOUND_ERROR, UNAUTHORIZED_ERROR } from "./apiclient.js";
|
||||
|
||||
|
||||
|
||||
export * from "./buttons";
|
||||
export * from "./forms";
|
||||
export * from "./layout";
|
||||
|
||||
19
scm-ui-components/packages/ui-components/src/repositories.js
Normal file
19
scm-ui-components/packages/ui-components/src/repositories.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// @flow
|
||||
import type { Repository } from "@scm-manager/ui-types";
|
||||
|
||||
// util methods for repositories
|
||||
|
||||
export function getProtocolLinkByType(repository: Repository, type: string) {
|
||||
let protocols = repository._links.protocol;
|
||||
if (protocols) {
|
||||
if (!Array.isArray(protocols)) {
|
||||
protocols = [protocols];
|
||||
}
|
||||
for (let proto of protocols) {
|
||||
if (proto.name === type) {
|
||||
return proto.href;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// @flow
|
||||
|
||||
import type { Repository } from "@scm-manager/ui-types";
|
||||
import { getProtocolLinkByType, getTypePredicate } from "./repositories";
|
||||
|
||||
describe("getProtocolLinkByType tests", () => {
|
||||
|
||||
it("should return the http protocol link", () => {
|
||||
|
||||
const repository: Repository = {
|
||||
namespace: "scm",
|
||||
name: "core",
|
||||
type: "git",
|
||||
_links: {
|
||||
protocol: [{
|
||||
name: "http",
|
||||
href: "http://scm.scm-manager.org/repo/scm/core"
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
const link = getProtocolLinkByType(repository, "http");
|
||||
expect(link).toBe("http://scm.scm-manager.org/repo/scm/core");
|
||||
});
|
||||
|
||||
it("should return the http protocol link from multiple protocols", () => {
|
||||
|
||||
const repository: Repository = {
|
||||
namespace: "scm",
|
||||
name: "core",
|
||||
type: "git",
|
||||
_links: {
|
||||
protocol: [{
|
||||
name: "http",
|
||||
href: "http://scm.scm-manager.org/repo/scm/core"
|
||||
},{
|
||||
name: "ssh",
|
||||
href: "git@scm.scm-manager.org:scm/core"
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
const link = getProtocolLinkByType(repository, "http");
|
||||
expect(link).toBe("http://scm.scm-manager.org/repo/scm/core");
|
||||
});
|
||||
|
||||
it("should return the http protocol, even if the protocol is a single link", () => {
|
||||
|
||||
const repository: Repository = {
|
||||
namespace: "scm",
|
||||
name: "core",
|
||||
type: "git",
|
||||
_links: {
|
||||
protocol: {
|
||||
name: "http",
|
||||
href: "http://scm.scm-manager.org/repo/scm/core"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const link = getProtocolLinkByType(repository, "http");
|
||||
expect(link).toBe("http://scm.scm-manager.org/repo/scm/core");
|
||||
});
|
||||
|
||||
it("should return null, if such a protocol does not exists", () => {
|
||||
|
||||
const repository: Repository = {
|
||||
namespace: "scm",
|
||||
name: "core",
|
||||
type: "git",
|
||||
_links: {
|
||||
protocol: [{
|
||||
name: "http",
|
||||
href: "http://scm.scm-manager.org/repo/scm/core"
|
||||
},{
|
||||
name: "ssh",
|
||||
href: "git@scm.scm-manager.org:scm/core"
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
const link = getProtocolLinkByType(repository, "awesome");
|
||||
expect(link).toBeNull();
|
||||
});
|
||||
|
||||
it("should return null, if no protocols are available", () => {
|
||||
|
||||
const repository: Repository = {
|
||||
namespace: "scm",
|
||||
name: "core",
|
||||
type: "git",
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const link = getProtocolLinkByType(repository, "http");
|
||||
expect(link).toBeNull();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,9 +1,10 @@
|
||||
// @flow
|
||||
export type Link = {
|
||||
href: string
|
||||
href: string,
|
||||
name?: string
|
||||
};
|
||||
|
||||
export type Links = { [string]: Link };
|
||||
export type Links = { [string]: Link | Link[] };
|
||||
|
||||
export type Collection = {
|
||||
_embedded: Object,
|
||||
|
||||
Reference in New Issue
Block a user