From e636d409ed2bf449d339daa7135fac66fc3d0a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maren=20S=C3=BCwer?= Date: Mon, 10 Dec 2018 15:36:52 +0100 Subject: [PATCH] correct error throwing in apiclient and add extension point --- .../src/main/js/GitMergeInformation.js | 55 +++++++++++++++++++ .../scm-git-plugin/src/main/js/index.js | 2 + .../main/resources/locales/en/plugins.json | 12 +++- .../packages/ui-components/src/apiclient.js | 19 ++----- 4 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 scm-plugins/scm-git-plugin/src/main/js/GitMergeInformation.js diff --git a/scm-plugins/scm-git-plugin/src/main/js/GitMergeInformation.js b/scm-plugins/scm-git-plugin/src/main/js/GitMergeInformation.js new file mode 100644 index 0000000000..12936bedaf --- /dev/null +++ b/scm-plugins/scm-git-plugin/src/main/js/GitMergeInformation.js @@ -0,0 +1,55 @@ +//@flow +import React from "react"; +import type { Repository } from "@scm-manager/ui-types"; +import { translate } from "react-i18next"; + +type Props = { + repository: Repository, + target: string, + source: string, + t: string => string +}; + +class GitMergeInformation extends React.Component { + render() { + const { source, target, t } = this.props; + + return ( +
+

{t("scm-git-plugin.information.merge.heading")}

+
{t("scm-git-plugin.information.merge.subheading")}
+ {t("scm-git-plugin.information.merge.clean")} + {t("scm-git-plugin.information.merge.checkout")} +
+          git checkout {target}
+        
+ {t("scm-git-plugin.information.merge.update")} +
+          
+            git pull
+          
+        
+ {t("scm-git-plugin.information.merge.merge")} +
+          
+            git merge {source}
+          
+        
+ {t("scm-git-plugin.information.merge.resolve")} +
+          
+            git add <conflict file>
+          
+        
+ {t("scm-git-plugin.information.merge.commit")} +
+          
+            git commit -m "Merge {source} into {target}"
+          
+        
+
+ ); + } +} + +export default translate("plugins")(GitMergeInformation); diff --git a/scm-plugins/scm-git-plugin/src/main/js/index.js b/scm-plugins/scm-git-plugin/src/main/js/index.js index 3f91405509..bdeda4cd0e 100644 --- a/scm-plugins/scm-git-plugin/src/main/js/index.js +++ b/scm-plugins/scm-git-plugin/src/main/js/index.js @@ -5,6 +5,7 @@ import GitAvatar from "./GitAvatar"; import { ConfigurationBinder as cfgBinder } from "@scm-manager/ui-components"; import GitGlobalConfiguration from "./GitGlobalConfiguration"; +import GitMergeInformation from "./GitMergeInformation"; // repository @@ -13,6 +14,7 @@ const gitPredicate = (props: Object) => { }; binder.bind("repos.repository-details.information", ProtocolInformation, gitPredicate); +binder.bind("repos.repository-merge.information", GitMergeInformation, gitPredicate); binder.bind("repos.repository-avatar", GitAvatar, gitPredicate); // global config diff --git a/scm-plugins/scm-git-plugin/src/main/resources/locales/en/plugins.json b/scm-plugins/scm-git-plugin/src/main/resources/locales/en/plugins.json index 483bff74c4..63ad8f2efd 100644 --- a/scm-plugins/scm-git-plugin/src/main/resources/locales/en/plugins.json +++ b/scm-plugins/scm-git-plugin/src/main/resources/locales/en/plugins.json @@ -3,7 +3,17 @@ "information": { "clone" : "Clone the repository", "create" : "Create a new repository", - "replace" : "Push an existing repository" + "replace" : "Push an existing repository", + "merge": { + "heading": "How to merge pull request", + "subheading": "Pull Request cannot be merged automatically - please follow these steps:", + "clean": "1. Make sure your workspace is clean", + "checkout": "2. Checkout target branch", + "update": "3. Update workspace", + "merge": "4. Merge source branch", + "resolve": "5. Resolve merge conflicts and add corrected files to index", + "commit": "6. Commit" + } }, "config": { "link": "Git", diff --git a/scm-ui-components/packages/ui-components/src/apiclient.js b/scm-ui-components/packages/ui-components/src/apiclient.js index 8c4bde6a72..25a108877a 100644 --- a/scm-ui-components/packages/ui-components/src/apiclient.js +++ b/scm-ui-components/packages/ui-components/src/apiclient.js @@ -16,30 +16,19 @@ function handleStatusCode(response: Response) { if (!response.ok) { switch (response.status) { case 401: - return throwError(response, UNAUTHORIZED_ERROR); + throw UNAUTHORIZED_ERROR; case 404: - return throwError(response, NOT_FOUND_ERROR); + throw NOT_FOUND_ERROR; case 409: - return throwError(response, CONFLICT_ERROR); + throw CONFLICT_ERROR; default: - return throwError(response, new Error("server returned status code " + response.status)); + throw new Error("server returned status code " + response.status); } } return response; } -function throwError(response: Response, err: Error) { - return response.json().then( - json => { - throw Error(json.message); - }, - () => { - throw err; - } - ); -} - export function createUrl(url: string) { if (url.includes("://")) { return url;