diff --git a/package-lock.json b/package-lock.json index 4769f9c..caa1173 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4904,9 +4904,9 @@ } }, "cwrc-git-server-client": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/cwrc-git-server-client/-/cwrc-git-server-client-1.8.0.tgz", - "integrity": "sha512-BTmu0JUfF7bM+WaiAD/uiNLfWimBzdOj1lyT1zPvGwYSWrU0iESiPcMU1kbj4RoZzwYnBUyNvCMf9xgb4nNKhA==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/cwrc-git-server-client/-/cwrc-git-server-client-1.9.0.tgz", + "integrity": "sha512-/0XmgaatdJhRUjl4IEQ/YSKu8mgcLkn0zjJhYA2rlptFSH57e6Kh9hWs84pJN0Y4UH3QLqWLNjYZNiXy2OlK6w==", "requires": { "js-cookie": "2.2.0" }, diff --git a/package.json b/package.json index c31add8..592861d 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "bootstrap": "^3.4.1", - "cwrc-git-server-client": "^1.8.0", + "cwrc-git-server-client": "^1.9.0", "jquery": "^3.4.1", "js-cookie": "2.1.4", "parse-link-header": "^1.0.1", diff --git a/src/VerifyRepo.js b/src/VerifyRepo.js index a8475ac..67a752f 100644 --- a/src/VerifyRepo.js +++ b/src/VerifyRepo.js @@ -86,6 +86,8 @@ class VerifyRepo extends Component { resetComponent = () => this.setState({ checkingRepo: null, doesRepoExist: null, + checkingOwner: null, + isOwnerUser: null, checkingPermission: null, doesUserHavePermission: null, error: null, @@ -94,7 +96,23 @@ class VerifyRepo extends Component { }) componentDidMount() { - this.checkRepoExistence(); + this.isOwnerUserOrOrg(); + } + + isOwnerUserOrOrg() { + this.setState({checkingOwner: true}); + cwrcGit.getDetailsForGithubUser(this.props.owner).then((result)=>{ + const isOwnerUser = result.data.type === 'User'; + this.setState({checkingOwner: false, isOwnerUser}); + this.checkRepoExistence(); + }, + (error)=>{ + if (error.status === 404) { + this.displayError(`The repository owner "${this.props.owner}" does not exist.`); + } else { + this.displayError(error); + } + }) } checkRepoExistence() { @@ -169,10 +187,17 @@ class VerifyRepo extends Component { } createRepo = () => { - cwrcGit.createRepo(this.props.repo, this.state.repoDesc, this.state.isPrivate).then( - (result) => this.complete(), - (error) => this.displayError(error) - ) + if (this.state.isOwnerUser) { + cwrcGit.createRepo(this.props.repo, this.state.repoDesc, this.state.isPrivate).then( + (result) => this.complete(), + (error) => this.displayError(error) + ) + } else { + cwrcGit.createOrgRepo(this.props.owner, this.props.repo, this.state.repoDesc, this.state.isPrivate).then( + (result) => this.complete(), + (error) => this.displayError(error) + ) + } } // handles changes passed up from children @@ -185,14 +210,16 @@ class VerifyRepo extends Component { } render() { - const {checkingRepo, doesRepoExist, checkingPermission, doesUserHavePermission, error} = this.state + const {checkingRepo, checkingOwner, isOwnerUser, doesRepoExist, checkingPermission, doesUserHavePermission, error} = this.state if (error) { return + } else if (checkingOwner) { + return } else if (checkingRepo) { - return + return } else if (checkingPermission) { return } else { @@ -201,7 +228,7 @@ class VerifyRepo extends Component { error = "You do not have permission to use this repository. Try saving as a pull request or save to another repository you have writing privileges for." cancel = {this.cancel.bind(this)}/> } else { - if (this.props.owner !== this.props.user) { + if (isOwnerUser && this.props.owner !== this.props.user) { return