From c8fa40d5200dce82ebe91d848a90e7154b936363 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Wed, 3 Apr 2019 16:46:28 +0200 Subject: [PATCH 1/5] added specific check for errortype for create newbranch redirect --- scm-ui/src/repos/branches/containers/BranchRoot.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scm-ui/src/repos/branches/containers/BranchRoot.js b/scm-ui/src/repos/branches/containers/BranchRoot.js index f1570735e2..8d4774c23b 100644 --- a/scm-ui/src/repos/branches/containers/BranchRoot.js +++ b/scm-ui/src/repos/branches/containers/BranchRoot.js @@ -13,6 +13,7 @@ import { } from "../modules/branches"; import { ErrorPage, Loading } from "@scm-manager/ui-components"; import type { History } from "history"; +import { NotFoundError } from "./errors"; type Props = { repository: Repository, @@ -63,7 +64,7 @@ class BranchRoot extends React.Component { const url = this.matchedUrl(); if (error) { - if(location.search.indexOf("?create=true") > -1) { + if(error instanceof NotFoundError && location.search.indexOf("?create=true") > -1) { return ; } From 3122ec5fb0e530e2de42436e611fe47a0cfffd8d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 3 Apr 2019 17:09:31 +0200 Subject: [PATCH 2/5] fixes wrong import of NotFoundError --- scm-ui/src/repos/branches/containers/BranchRoot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scm-ui/src/repos/branches/containers/BranchRoot.js b/scm-ui/src/repos/branches/containers/BranchRoot.js index 8d4774c23b..2e8f910275 100644 --- a/scm-ui/src/repos/branches/containers/BranchRoot.js +++ b/scm-ui/src/repos/branches/containers/BranchRoot.js @@ -13,7 +13,7 @@ import { } from "../modules/branches"; import { ErrorPage, Loading } from "@scm-manager/ui-components"; import type { History } from "history"; -import { NotFoundError } from "./errors"; +import { NotFoundError } from "@scm-manager/ui-components"; type Props = { repository: Repository, From 7bbafee1ed325f0e579ee6970331792608c9543c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 3 Apr 2019 17:10:22 +0200 Subject: [PATCH 3/5] the branch endpoint should return a not found error with context, if the branch does not exists --- .../sonia/scm/api/v2/resources/BranchRootResource.java | 7 ++++--- .../sonia/scm/api/v2/resources/BranchRootResourceTest.java | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java index f0edbf79fb..9e7353b4b7 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/BranchRootResource.java @@ -79,15 +79,16 @@ public class BranchRootResource { @ResponseCode(code = 500, condition = "internal server error") }) public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("branch") String branchName) throws IOException { - try (RepositoryService repositoryService = serviceFactory.create(new NamespaceAndName(namespace, name))) { + NamespaceAndName namespaceAndName = new NamespaceAndName(namespace, name); + try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) { Branches branches = repositoryService.getBranchesCommand().getBranches(); return branches.getBranches() .stream() .filter(branch -> branchName.equals(branch.getName())) .findFirst() - .map(branch -> branchToDtoMapper.map(branch, new NamespaceAndName(namespace, name))) + .map(branch -> branchToDtoMapper.map(branch, namespaceAndName)) .map(Response::ok) - .orElse(Response.status(Response.Status.NOT_FOUND)) + .orElseThrow(() -> notFound(entity("branch", branchName).in(namespaceAndName))) .build(); } catch (CommandNotSupportedException ex) { return Response.status(Response.Status.BAD_REQUEST).build(); diff --git a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/BranchRootResourceTest.java b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/BranchRootResourceTest.java index 9fb20c0922..2c83d5e3e1 100644 --- a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/BranchRootResourceTest.java +++ b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/BranchRootResourceTest.java @@ -129,6 +129,7 @@ public class BranchRootResourceTest extends RepositoryTestBase { dispatcher.invoke(request, response); assertEquals(404, response.getStatus()); + assertEquals("application/vnd.scmm-error+json;v=2", response.getOutputHeaders().getFirst("Content-Type")); } @Test From ea986e3b093f32238001bf1e4e1b6d2c55faacda Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 3 Apr 2019 17:17:58 +0200 Subject: [PATCH 4/5] use ErrorNotification instead of ErrorPage, because we are already wrapped by a Page --- scm-ui/public/locales/de/repos.json | 2 -- scm-ui/public/locales/en/repos.json | 2 -- scm-ui/src/repos/branches/containers/BranchRoot.js | 13 +++---------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/scm-ui/public/locales/de/repos.json b/scm-ui/public/locales/de/repos.json index 6170c9021f..6f7846df72 100644 --- a/scm-ui/public/locales/de/repos.json +++ b/scm-ui/public/locales/de/repos.json @@ -44,8 +44,6 @@ "subtitle": "Erstellen eines neuen Repository" }, "branches": { - "errorTitle": "Fehler", - "errorSubtitle": "Unbekannter Branch Fehler", "overview": { "title": "Übersicht aller verfügbaren Branches", "createButton": "Branch erstellen" diff --git a/scm-ui/public/locales/en/repos.json b/scm-ui/public/locales/en/repos.json index 4eeddea8b2..89492f427d 100644 --- a/scm-ui/public/locales/en/repos.json +++ b/scm-ui/public/locales/en/repos.json @@ -44,8 +44,6 @@ "subtitle": "Create a new repository" }, "branches": { - "errorTitle": "Error", - "errorSubtitle": "Unknown branch error", "overview": { "title": "Overview of all branches", "createButton": "Create Branch" diff --git a/scm-ui/src/repos/branches/containers/BranchRoot.js b/scm-ui/src/repos/branches/containers/BranchRoot.js index 2e8f910275..2e9fb10f73 100644 --- a/scm-ui/src/repos/branches/containers/BranchRoot.js +++ b/scm-ui/src/repos/branches/containers/BranchRoot.js @@ -3,7 +3,6 @@ import React from "react"; import BranchView from "../components/BranchView"; import { connect } from "react-redux"; import { Redirect, Route, Switch, withRouter } from "react-router-dom"; -import { translate } from "react-i18next"; import type { Repository, Branch } from "@scm-manager/ui-types"; import { fetchBranch, @@ -11,7 +10,7 @@ import { getFetchBranchFailure, isFetchBranchPending } from "../modules/branches"; -import { ErrorPage, Loading } from "@scm-manager/ui-components"; +import { ErrorNotification, Loading } from "@scm-manager/ui-components"; import type { History } from "history"; import { NotFoundError } from "@scm-manager/ui-components"; @@ -23,7 +22,6 @@ type Props = { error?: Error, // context props - t: string => string, history: History, match: any, location: any, @@ -56,7 +54,6 @@ class BranchRoot extends React.Component { branch, loading, error, - t, match, location } = this.props; @@ -69,11 +66,7 @@ class BranchRoot extends React.Component { } return ( - + ); } @@ -122,5 +115,5 @@ export default withRouter( connect( mapStateToProps, mapDispatchToProps - )(translate("repos")(BranchRoot)) + )(BranchRoot) ); From a38f89d8f49ddcb423a4cec50c3600332c4ff31d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 3 Apr 2019 15:54:45 +0000 Subject: [PATCH 5/5] Close branch feature/branch-overview