fix missing checkout/clone description on repository information page

This commit is contained in:
Sebastian Sdorra
2018-09-27 12:17:36 +02:00
parent b645901704
commit 11fca51f5f
7 changed files with 142 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
//@flow //@flow
import React from "react"; import React from "react";
import { repositories } from "@scm-manager/ui-components";
import type { Repository } from "@scm-manager/ui-types"; import type { Repository } from "@scm-manager/ui-types";
type Props = { type Props = {
@@ -10,14 +11,16 @@ class ProtocolInformation extends React.Component<Props> {
render() { render() {
const { repository } = this.props; const { repository } = this.props;
if (!repository._links.httpProtocol) { const href = repositories.getProtocolLinkByType(repository, "http");
if (!href) {
return null; return null;
} }
return ( return (
<div> <div>
<h4>Clone the repository</h4> <h4>Clone the repository</h4>
<pre> <pre>
<code>git clone {repository._links.httpProtocol.href}</code> <code>git clone {href}</code>
</pre> </pre>
<h4>Create a new repository</h4> <h4>Create a new repository</h4>
<pre> <pre>
@@ -30,7 +33,7 @@ class ProtocolInformation extends React.Component<Props> {
<br /> <br />
git commit -m "added readme" git commit -m "added readme"
<br /> <br />
git remote add origin {repository._links.httpProtocol.href} git remote add origin {href}
<br /> <br />
git push -u origin master git push -u origin master
<br /> <br />
@@ -39,7 +42,7 @@ class ProtocolInformation extends React.Component<Props> {
<h4>Push an existing repository</h4> <h4>Push an existing repository</h4>
<pre> <pre>
<code> <code>
git remote add origin {repository._links.httpProtocol.href} git remote add origin {href}
<br /> <br />
git push -u origin master git push -u origin master
<br /> <br />

View File

@@ -1,5 +1,6 @@
//@flow //@flow
import React from "react"; import React from "react";
import { repositories } from "@scm-manager/ui-components";
import type { Repository } from "@scm-manager/ui-types"; import type { Repository } from "@scm-manager/ui-types";
type Props = { type Props = {
@@ -10,14 +11,15 @@ class ProtocolInformation extends React.Component<Props> {
render() { render() {
const { repository } = this.props; const { repository } = this.props;
if (!repository._links.httpProtocol) { const href = repositories.getProtocolLinkByType(repository, "http");
if (!href) {
return null; return null;
} }
return ( return (
<div> <div>
<h4>Clone the repository</h4> <h4>Clone the repository</h4>
<pre> <pre>
<code>hg clone {repository._links.httpProtocol.href}</code> <code>hg clone {href}</code>
</pre> </pre>
<h4>Create a new repository</h4> <h4>Create a new repository</h4>
<pre> <pre>
@@ -26,7 +28,7 @@ class ProtocolInformation extends React.Component<Props> {
<br /> <br />
echo "[paths]" > .hg/hgrc echo "[paths]" > .hg/hgrc
<br /> <br />
echo "default = {repository._links.httpProtocol.href}" > .hg/hgrc echo "default = {href}" > .hg/hgrc
<br /> <br />
echo "# {repository.name}" > README.md echo "# {repository.name}" > README.md
<br /> <br />
@@ -44,7 +46,7 @@ class ProtocolInformation extends React.Component<Props> {
<code> <code>
# add the repository url as default to your .hg/hgrc e.g: # add the repository url as default to your .hg/hgrc e.g:
<br /> <br />
default = {repository._links.httpProtocol.href} default = {href}
<br /> <br />
# push to remote repository # push to remote repository
<br /> <br />

View File

@@ -1,5 +1,6 @@
//@flow //@flow
import React from "react"; import React from "react";
import { repositories } from "@scm-manager/ui-components";
import type { Repository } from "@scm-manager/ui-types"; import type { Repository } from "@scm-manager/ui-types";
type Props = { type Props = {
@@ -10,14 +11,15 @@ class ProtocolInformation extends React.Component<Props> {
render() { render() {
const { repository } = this.props; const { repository } = this.props;
if (!repository._links.httpProtocol) { const href = repositories.getProtocolLinkByType(repository, "http");
if (!href) {
return null; return null;
} }
return ( return (
<div> <div>
<h4>Checkout the repository</h4> <h4>Checkout the repository</h4>
<pre> <pre>
<code>svn checkout {repository._links.httpProtocol.href}</code> <code>svn checkout {href}</code>
</pre> </pre>
</div> </div>
); );

View File

@@ -2,8 +2,9 @@
import * as validation from "./validation.js"; import * as validation from "./validation.js";
import * as urls from "./urls"; 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 DateFromNow } from "./DateFromNow.js";
export { default as ErrorNotification } from "./ErrorNotification.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 { apiClient, NOT_FOUND_ERROR, UNAUTHORIZED_ERROR } from "./apiclient.js";
export * from "./buttons"; export * from "./buttons";
export * from "./forms"; export * from "./forms";
export * from "./layout"; export * from "./layout";

View 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;
}

View File

@@ -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();
});
});

View File

@@ -1,9 +1,10 @@
// @flow // @flow
export type Link = { export type Link = {
href: string href: string,
name?: string
}; };
export type Links = { [string]: Link }; export type Links = { [string]: Link | Link[] };
export type Collection = { export type Collection = {
_embedded: Object, _embedded: Object,