Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Commit

Permalink
Added simple check of repository existence through GH API
Browse files Browse the repository at this point in the history
  • Loading branch information
bartaz committed Nov 24, 2016
1 parent 3416616 commit 1bf8c53
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/common/components/repository-input/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'isomorphic-fetch';

import React, { Component } from 'react';

import parseGitHubUrl from 'parse-github-url';
Expand Down Expand Up @@ -39,7 +41,32 @@ export class RepositoryInput extends Component {

if (repo) {
let repoUrl = `https://github.com/${repo}.git`;
let apiUrl = `https://api.github.com/repos/${repo}`;

message = <span>Repository: {repo}, URL: <a href={repoUrl}>{repoUrl}</a></span>;

let self = this;
fetch(apiUrl)
.then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
const error = new Error(response.statusText);
error.response = response;
throw error;
}
})
.then(() => {
self.setState({
message: <span>{this.state.message} [exists on GitHub]</span>
});
})
.catch((errors) => {
self.setState({
message: `Repository ${repo} doesn't exist (${errors})`
});
});

} else {
message = 'Invalid repository URL';
}
Expand Down

0 comments on commit 1bf8c53

Please sign in to comment.