Merged changes

This commit is contained in:
Philipp Czora
2018-09-19 17:19:48 +02:00
12 changed files with 164 additions and 56 deletions

View File

@@ -4,7 +4,7 @@
"description": "Description",
"contact": "Contact",
"date": "Date",
"summary": "Changeset {{id}} committed at {{time}}"
"summary": "Changeset {{id}} committed {{time}}"
},
"author": {
"name": "Author",

View File

@@ -0,0 +1,27 @@
//@flow
import React from "react";
import type { Changeset } from "@scm-manager/ui-types";
type Props = {
changeset: Changeset
};
export default class ChangesetAuthor extends React.Component<Props> {
render() {
const { changeset } = this.props;
return (
<>
{changeset.author.name}{" "}
<a
className="is-hidden-mobile"
href={"mailto:" + changeset.author.mail}
>
&lt;
{changeset.author.mail}
&gt;
</a>
</>
);
}
}

View File

@@ -0,0 +1,25 @@
//@flow
import { Link } from "react-router-dom";
import React from "react";
import type { Repository, Changeset } from "@scm-manager/ui-types";
type Props = {
repository: Repository,
changeset: Changeset
};
export default class ChangesetId extends React.Component<Props> {
render() {
const { repository, changeset } = this.props;
return (
<Link
to={`/repo/${repository.namespace}/${repository.name}/changeset/${
changeset.id
}`}
>
{changeset.id.substr(0, 7)}
</Link>
);
}
}

View File

@@ -0,0 +1,22 @@
// @flow
import ChangesetRow from "./ChangesetRow";
import React from "react";
import type { Changeset, Repository } from "@scm-manager/ui-types";
import classNames from "classnames";
type Props = {
repository: Repository,
changesets: Changeset[]
};
class ChangesetList extends React.Component<Props> {
render() {
const { repository, changesets } = this.props;
const content = changesets.map((changeset, index) => {
return <ChangesetRow key={index} repository={repository} changeset={changeset} />;
});
return <div className={classNames("box")}>{content}</div>;
}
}
export default ChangesetList;

View File

@@ -1,11 +1,13 @@
//@flow
import React from "react";
import type { Changeset } from "@scm-manager/ui-types";
import type { Changeset, Repository } from "@scm-manager/ui-types";
import classNames from "classnames";
import { translate, Interpolate } from "react-i18next";
import ChangesetAvatar from "./ChangesetAvatar";
import ChangesetId from "./ChangesetId";
import injectSheet from "react-jss";
import { DateFromNow } from "@scm-manager/ui-components";
import ChangesetAuthor from "./ChangesetAuthor";
const styles = {
pointer: {
@@ -13,10 +15,14 @@ const styles = {
},
changesetGroup: {
marginBottom: "1em"
},
withOverflow: {
overflow: "auto"
}
};
type Props = {
repository: Repository,
changeset: Changeset,
t: any,
classes: any
@@ -24,32 +30,21 @@ type Props = {
class ChangesetRow extends React.Component<Props> {
createLink = (changeset: Changeset) => {
return <a href={`/repo/changeset/${changeset.id}`}>{changeset.id}</a>;
const { repository } = this.props;
return <ChangesetId changeset={changeset} repository={repository} />;
};
render() {
const { changeset, t, classes } = this.props;
const { changeset, classes } = this.props;
const changesetLink = this.createLink(changeset);
const dateFromNow = <DateFromNow date={changeset.date} />;
const authorLine = (
<>
{changeset.author.name}{" "}
<a
className="is-hidden-mobile"
href={"mailto:" + changeset.author.mail}
>
&lt;
{changeset.author.mail}
&gt;
</a>
</>
);
const authorLine = <ChangesetAuthor changeset={changeset}/>;
return (
<article className={classNames("media", classes.inner)}>
<figure className="media-left">
<ChangesetAvatar changeset={changeset} />
</figure>
<div className="media-content">
<div className={classNames("media-content", classes.withOverflow)}>
<div className="content">
<p className="is-ellipsis-overflow">
{changeset.description}

View File

@@ -1,21 +0,0 @@
// @flow
import ChangesetRow from "./ChangesetRow";
import React from "react";
import type { Changeset } from "@scm-manager/ui-types";
import classNames from "classnames";
type Props = {
changesets: Changeset[]
};
class ChangesetTable extends React.Component<Props> {
render() {
const { changesets } = this.props;
const content = changesets.map((changeset, index) => {
return <ChangesetRow key={index} changeset={changeset} />;
});
return <div className={classNames("box")}>{content}</div>;
}
}
export default ChangesetTable;

View File

@@ -22,7 +22,7 @@ import {
getBranchNames
} from "../../repos/modules/branches";
import type { PagedCollection, Repository } from "@scm-manager/ui-types";
import ChangesetTable from "../components/ChangesetTable";
import ChangesetList from "../components/ChangesetList";
import DropDown from "../components/DropDown";
import { withRouter } from "react-router-dom";
@@ -84,7 +84,7 @@ class Changesets extends React.Component<State, Props> {
renderTable = () => {
const branch = this.props.match.params.branch;
const { changesets, branchNames } = this.props;
const { repository, changesets, branchNames } = this.props;
if (branchNames && branchNames.length > 0) {
return (
@@ -95,12 +95,12 @@ class Changesets extends React.Component<State, Props> {
preselectedOption={branch}
optionSelected={branch => this.branchChanged(branch)}
/>
<ChangesetTable changesets={changesets} />
<ChangesetList repository={repository} changesets={changesets} />
</div>
);
}
return <ChangesetTable changesets={changesets} />;
return <ChangesetList changesets={changesets} />;
};
renderPaginator() {

View File

@@ -100,9 +100,10 @@ public class BranchRootResource {
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
Repository repository = repositoryService.getRepository();
RepositoryPermissions.read(repository).check();
ChangesetPagingResult changesets = repositoryService.getLogCommand()
.setPagingStart(page)
.setPagingLimit(pageSize)
ChangesetPagingResult changesets = new PagedLogCommandBuilder(repositoryService)
.page(page)
.pageSize(pageSize)
.create()
.setBranch(branchName)
.getChangesets();
if (changesets != null && changesets.getChangesets() != null) {

View File

@@ -12,6 +12,7 @@ import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryNotFoundException;
import sonia.scm.repository.RepositoryPermissions;
import sonia.scm.repository.RevisionNotFoundException;
import sonia.scm.repository.api.LogCommandBuilder;
import sonia.scm.repository.api.RepositoryService;
import sonia.scm.repository.api.RepositoryServiceFactory;
import sonia.scm.web.VndMediaType;
@@ -59,9 +60,10 @@ public class ChangesetRootResource {
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
Repository repository = repositoryService.getRepository();
RepositoryPermissions.read(repository).check();
ChangesetPagingResult changesets = repositoryService.getLogCommand()
.setPagingStart(page)
.setPagingLimit(pageSize)
ChangesetPagingResult changesets = new PagedLogCommandBuilder(repositoryService)
.page(page)
.pageSize(pageSize)
.create()
.getChangesets();
if (changesets != null && changesets.getChangesets() != null) {
PageResult<Changeset> pageResult = new PageResult<>(changesets.getChangesets(), changesets.getTotal());

View File

@@ -73,9 +73,10 @@ public class FileHistoryRootResource {
try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) {
log.info("Get changesets of the file {} and revision {}", path, revision);
Repository repository = repositoryService.getRepository();
ChangesetPagingResult changesets = repositoryService.getLogCommand()
.setPagingStart(page)
.setPagingLimit(pageSize)
ChangesetPagingResult changesets = new PagedLogCommandBuilder(repositoryService)
.page(page)
.pageSize(pageSize)
.create()
.setPath(path)
.setStartChangeset(revision)
.getChangesets();

View File

@@ -0,0 +1,30 @@
package sonia.scm.api.v2.resources;
import sonia.scm.repository.api.LogCommandBuilder;
import sonia.scm.repository.api.RepositoryService;
class PagedLogCommandBuilder {
private final RepositoryService repositoryService;
private int page;
private int pageSize ;
PagedLogCommandBuilder(RepositoryService repositoryService) {
this.repositoryService = repositoryService;
}
PagedLogCommandBuilder page(int page) {
this.page = page;
return this;
}
PagedLogCommandBuilder pageSize(int pageSize) {
this.pageSize = pageSize;
return this;
}
LogCommandBuilder create() {
return repositoryService.getLogCommand()
.setPagingStart(page * pageSize)
.setPagingLimit(pageSize);
}
}

View File

@@ -109,8 +109,8 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
List<Changeset> changesetList = Lists.newArrayList(new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit));
when(changesetPagingResult.getChangesets()).thenReturn(changesetList);
when(changesetPagingResult.getTotal()).thenReturn(1);
when(logCommandBuilder.setPagingStart(anyInt())).thenReturn(logCommandBuilder);
when(logCommandBuilder.setPagingLimit(anyInt())).thenReturn(logCommandBuilder);
when(logCommandBuilder.setPagingStart(0)).thenReturn(logCommandBuilder);
when(logCommandBuilder.setPagingLimit(10)).thenReturn(logCommandBuilder);
when(logCommandBuilder.setBranch(anyString())).thenReturn(logCommandBuilder);
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
MockHttpRequest request = MockHttpRequest
@@ -126,6 +126,34 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
assertTrue(response.getContentAsString().contains(String.format("\"description\":\"%s\"", commit)));
}
@Test
public void shouldGetSinglePageOfChangeSets() throws Exception {
String id = "revision_123";
Instant creationDate = Instant.now();
String authorName = "name";
String authorEmail = "em@i.l";
String commit = "my branch commit";
ChangesetPagingResult changesetPagingResult = mock(ChangesetPagingResult.class);
List<Changeset> changesetList = Lists.newArrayList(new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit));
when(changesetPagingResult.getChangesets()).thenReturn(changesetList);
when(changesetPagingResult.getTotal()).thenReturn(1);
when(logCommandBuilder.setPagingStart(20)).thenReturn(logCommandBuilder);
when(logCommandBuilder.setPagingLimit(10)).thenReturn(logCommandBuilder);
when(logCommandBuilder.setBranch(anyString())).thenReturn(logCommandBuilder);
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
MockHttpRequest request = MockHttpRequest
.get(CHANGESET_URL + "?page=2")
.accept(VndMediaType.CHANGESET_COLLECTION);
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(200, response.getStatus());
log.info("Response :{}", response.getContentAsString());
assertTrue(response.getContentAsString().contains(String.format("\"id\":\"%s\"", id)));
assertTrue(response.getContentAsString().contains(String.format("\"name\":\"%s\"", authorName)));
assertTrue(response.getContentAsString().contains(String.format("\"mail\":\"%s\"", authorEmail)));
assertTrue(response.getContentAsString().contains(String.format("\"description\":\"%s\"", commit)));
}
@Test
public void shouldGetChangeSet() throws Exception {
String id = "revision_123";
@@ -137,8 +165,6 @@ public class ChangesetRootResourceTest extends RepositoryTestBase {
List<Changeset> changesetList = Lists.newArrayList(new Changeset(id, Date.from(creationDate).getTime(), new Person(authorName, authorEmail), commit));
when(changesetPagingResult.getChangesets()).thenReturn(changesetList);
when(changesetPagingResult.getTotal()).thenReturn(1);
when(logCommandBuilder.setPagingStart(anyInt())).thenReturn(logCommandBuilder);
when(logCommandBuilder.setPagingLimit(anyInt())).thenReturn(logCommandBuilder);
when(logCommandBuilder.setEndChangeset(anyString())).thenReturn(logCommandBuilder);
when(logCommandBuilder.setStartChangeset(anyString())).thenReturn(logCommandBuilder);
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);