Implement Git repo config

This commit is contained in:
Philipp Czora
2018-12-14 16:01:57 +01:00
parent c2d872bd59
commit 8a6a235e77
10 changed files with 203 additions and 78 deletions

View File

@@ -0,0 +1,120 @@
// @flow
import React from "react";
import {apiClient, BranchSelector, ErrorPage, Loading, SubmitButton} from "@scm-manager/ui-components";
import type {Branch, Repository} from "@scm-manager/ui-types";
import {translate} from "react-i18next";
type Props = {
repository: Repository,
t: string => string
};
type State = {
loadingBranches: boolean,
loadingDefaultBranch: boolean,
submitPending: boolean,
error: Error,
branches: Branch[],
selectedBranchName: string
};
const GIT_CONFIG_CONTENT_TYPE = "application/vnd.scmm-gitConfig+json";
class RepositoryConfig extends React.Component<Props, State> {
state = {
branches: []
};
componentDidMount() {
const { repository } = this.props;
this.setState({ ...this.state, loadingBranches: true });
apiClient
.get(repository._links.branches.href)
.then(response => response.json())
.then(payload => payload._embedded.branches)
.then(branches =>
this.setState({ ...this.state, branches, loadingBranches: false })
)
.catch(error => this.setState({ ...this.state, error }));
this.setState({ ...this.state, loadingDefaultBranch: true });
apiClient
.get(repository._links.configuration.href)
.then(response => response.json())
.then(payload => payload.defaultBranch)
.then(selectedBranchName =>
this.setState({
...this.state,
selectedBranchName,
loadingDefaultBranch: false
})
)
.catch(error => this.setState({ ...this.state, error }));
}
branchSelected = (branch: Branch) => {
if (!branch) {
this.setState({ ...this.state, selectedBranchName: null });
}
this.setState({ ...this.state, selectedBranchName: branch.name });
};
submit = (event: Event) => {
event.preventDefault();
const { repository } = this.props;
const newConfig = {
defaultBranch: this.state.selectedBranchName
};
this.setState({ ...this.state, submitPending: true });
apiClient
.put(
repository._links.configuration.href,
newConfig,
GIT_CONFIG_CONTENT_TYPE
)
.then(() => this.setState({ ...this.state, submitPending: false }))
.catch(error => this.setState({ ...this.state, error }));
};
render() {
const { t, error } = this.props;
const { loadingBranches, loadingDefaultBranch, submitPending } = this.state;
if (error) {
return (
<ErrorPage
title={t("scm-git-plugin.repo-config.error.title")}
subtitle={t("scm-git-plugin.repo-config.error.subtitle")}
error={error}
/>
);
}
if (!(loadingBranches || loadingDefaultBranch)) {
return (
<form onSubmit={this.submit}>
<BranchSelector
label={t("scm-git-plugin.repo-config.default-branch")}
branches={this.state.branches}
selected={this.branchSelected}
selectedBranch={this.state.selectedBranchName}
/>
<SubmitButton
label={t("scm-git-plugin.repo-config.submit")}
loading={submitPending}
disabled={
!this.state.selectedBranchName
}
/>
</form>
);
} else {
return <Loading />;
}
}
}
export default translate("plugins")(RepositoryConfig);

View File

@@ -1,11 +1,13 @@
//@flow
import { binder } from "@scm-manager/ui-extensions";
import React from "react";
import {binder} from "@scm-manager/ui-extensions";
import ProtocolInformation from "./ProtocolInformation";
import GitAvatar from "./GitAvatar";
import { ConfigurationBinder as cfgBinder } from "@scm-manager/ui-components";
import {ConfigurationBinder as cfgBinder} from "@scm-manager/ui-components";
import GitGlobalConfiguration from "./GitGlobalConfiguration";
import GitMergeInformation from "./GitMergeInformation";
import RepositoryConfig from "./RepositoryConfig";
// repository
@@ -13,10 +15,29 @@ const gitPredicate = (props: Object) => {
return props.repository && props.repository.type === "git";
};
binder.bind("repos.repository-details.information", ProtocolInformation, gitPredicate);
binder.bind("repos.repository-merge.information", GitMergeInformation, gitPredicate);
binder.bind(
"repos.repository-details.information",
ProtocolInformation,
gitPredicate
);
binder.bind(
"repos.repository-merge.information",
GitMergeInformation,
gitPredicate
);
binder.bind("repos.repository-avatar", GitAvatar, gitPredicate);
cfgBinder.bindRepository(
"/configuration",
"scm-git-plugin.repo-config.link",
"configuration",
RepositoryConfig
);
// global config
cfgBinder.bindGlobal("/git", "scm-git-plugin.config.link", "gitConfig", GitGlobalConfiguration);
cfgBinder.bindGlobal(
"/git",
"scm-git-plugin.config.link",
"gitConfig",
GitGlobalConfiguration
);

View File

@@ -1,9 +1,9 @@
{
"scm-git-plugin": {
"information": {
"clone" : "Clone the repository",
"create" : "Create a new repository",
"replace" : "Push an existing repository",
"clone": "Clone the repository",
"create": "Create a new repository",
"replace": "Push an existing repository",
"merge": {
"heading": "How to merge source branch into target branch",
"checkout": "1. Make sure your workspace is clean and checkout target branch",
@@ -22,6 +22,15 @@
"disabled": "Disabled",
"disabledHelpText": "Enable or disable the Git plugin",
"submit": "Submit"
},
"repo-config": {
"link": "Configuration",
"default-branch": "Default branch",
"submit": "Submit",
"error": {
"title": "Error",
"subtitle": "Something went wrong"
}
}
}
}