Skip to content

Commit

Permalink
feat: add ability to create org repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmacdonald committed Jul 12, 2019
1 parent 0171db6 commit 174b7c4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 35 additions & 8 deletions src/VerifyRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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 <ErrorModal
error = {error}
cancel = {this.cancel.bind(this)}/>
} else if (checkingOwner) {
return <CheckingModal body="Checking the repository owner..." />
} else if (checkingRepo) {
return <CheckingModal body="Checking your respository..." />
return <CheckingModal body="Checking the respository..." />
} else if (checkingPermission) {
return <CheckingModal body="Checking your permissions..." />
} else {
Expand All @@ -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 <ErrorModal
error = "You cannot create a repository for another user's account."
cancel = {this.cancel.bind(this)}/>
Expand Down

0 comments on commit 174b7c4

Please sign in to comment.