Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Feature: Add all organization repositories when omitting repo name #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/githubService.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ exports.getRepo = function getRepo(owner, name) {
return apiCall(`${config.apiBaseUrl}/repos/${owner}/${name}`);
};

exports.listOrganizationRepos = function listRepos(owner) {
const config = configManager.getConfig();
return apiCall(`${config.apiBaseUrl}/orgs/${owner}/repos`).then(response => response.data);
};

exports.loadPullRequests = function loadPullRequests() {
const config = configManager.getConfig();
const repos = config.repos;
Expand Down
1 change: 1 addition & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ emoji.init();
app.get('/pulls', requestHandlers.getPullRequests);
app.get('/config', requestHandlers.getConfig);
app.get('/repoExists', requestHandlers.repoExists);
app.get('/scanOrgRepos', requestHandlers.scanOrgRepos);
app.put('/config', requestHandlers.updateConfig);
app.get('*', (req, res) => {
res.sendFile(path.resolve('dist', 'index.html'));
Expand Down
12 changes: 12 additions & 0 deletions server/requestHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ exports.repoExists = function getConfig(req, res) {
res.status(404).json(false);
});
};

exports.scanOrgRepos = function scanOrgRepos(req, res) {
githubService.listOrganizationRepos(req.query.owner).then(repos => {
res.status(200).json(repos.map(repo => ({ id: repo.id, name: repo.name })));
}).catch(error => {
console.error(`Error loading organization repos: ${error.message}`);
console.error(error);
res.status(500).json({
error: `Failed to load organization repos: ${error.message}`
});
});
};
44 changes: 34 additions & 10 deletions src/js/components/AddRepo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ export default class AddRepo extends React.Component {
error: 'That repository has already been added.'
});
} else {
axios.get(`/repoExists?owner=${this.state.owner}&repo=${this.state.repo}`)
.then(() => {
this.props.onAddRepo(this.state.owner, this.state.repo);
this.setState({
owner: '',
repo: '',
error: ''
if (!this.state.repo) {
axios.get(`/scanOrgRepos?owner=${this.state.owner}`)
.then(({ data: repos }) => {
repos.forEach(repo => {
if (!this.props.repos.indexOf(`${this.state.owner}/${repo.name}`) >= 0) {
this.props.onAddRepo(this.state.owner, repo.name);
}
});
document.getElementById('ownerInput').focus();
}).catch((error) => {
if (error.response && error.response.status === 404) {
if (error.response) {
this.setState({
error: 'That repository does not exist.'
error: error.response
});
} else {
/* eslint-disable no-console */
Expand All @@ -61,6 +61,30 @@ export default class AddRepo extends React.Component {
});
}
});
} else {
axios.get(`/repoExists?owner=${this.state.owner}&repo=${this.state.repo}`)
.then(() => {
this.props.onAddRepo(this.state.owner, this.state.repo);
this.setState({
owner: '',
repo: '',
error: ''
});
document.getElementById('ownerInput').focus();
}).catch((error) => {
if (error.response && error.response.status === 404) {
this.setState({
error: 'That repository does not exist.'
});
} else {
/* eslint-disable no-console */
console.error(error);
this.setState({
error: 'An unexpected error has occurred. Please try again.'
});
}
});
}
}
}

Expand Down Expand Up @@ -92,7 +116,7 @@ export default class AddRepo extends React.Component {
type="text" value={this.state.repo}
onChange={this.handleChangeRepo} placeholder="Repository" size="50"
/>
<button disabled={!(this.state.owner.length && this.state.repo.length)}>Add</button>
<button disabled={!(this.state.owner.length)}>Add</button>
</form>
</div>
);
Expand Down