Skip to content

Commit

Permalink
Resolve #13: Filter pull requests to owned repositories (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
31z4 authored Mar 24, 2018
1 parent 538ee8e commit 3199eb6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/api/GitHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ export default class GitHub {
async _fetchPullRequests() {
const q = encodeURIComponent('type:pr author:' + this._author);
const pullRequests = await this._fetchPages('https://api.github.com/search/issues?per_page=100&q=' + q);
const filtered = pullRequests.items.filter((item) => item.author_association != 'OWNER');

const promises = pullRequests.items.map(async (item) => {
const promises = filtered.map(async (item) => {
if (item.state == 'closed' && await this._isMerged(item.pull_request.url)) {
item.state = 'merged';
}
Expand Down
57 changes: 57 additions & 0 deletions src/api/GitHub.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ describe('aggregatePullRequests', () => {
return mockResponse({items: [
{
repository_url: 'https://api.github.com/repos/user/repo1',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo1/pulls/1'},
state: 'open',
},
Expand All @@ -138,6 +139,7 @@ describe('aggregatePullRequests', () => {
return mockResponse({items: [
{
repository_url: 'https://api.github.com/repos/user/repo1',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo1/pulls/2'},
state: 'closed',
},
Expand Down Expand Up @@ -182,43 +184,98 @@ describe('aggregatePullRequests', () => {
await expect(github.aggregatePullRequests()).resolves.toEqual(result);
});

it('filters owned', async () => {
window.fetch.mockImplementation((url) => {
switch (url) {
case 'https://api.github.com/search/issues?per_page=100&q=type%3Apr%20author%3Atest':
return mockResponse({items: [
{
repository_url: 'https://api.github.com/repos/user/repo1',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo1/pulls/1'},
state: 'open',
},
{
repository_url: 'https://api.github.com/repos/user/repo2',
author_association: 'OWNER',
pull_request: {url: 'https://api.github.com/repos/user/repo2/pulls/1'},
state: 'open',
},
]});
case 'https://api.github.com/repos/user/repo1':
return mockResponse({
html_url: 'https://github.com/user/repo1',
full_name: 'Repo 1',
stargazers_count: 1,
language: 'JavaScript',
});
default:
return { ok: false };
}
});

const result = [
{
repository: {
html_url: 'https://github.com/user/repo1',
full_name: 'Repo 1',
stargazers_count: 1,
language: 'JavaScript',
},
open: 1,
closed: 0,
merged: 0,
html_url: 'https://github.com/search?utf8=✓&q=type%3Apr%20author%3Atest%20repo%3ARepo%201',
},
];

await expect(github.aggregatePullRequests()).resolves.toEqual(result);
});

it('aggregates', async () => {
window.fetch.mockImplementation((url) => {
switch (url) {
case 'https://api.github.com/search/issues?per_page=100&q=type%3Apr%20author%3Atest':
return mockResponse({items: [
{
repository_url: 'https://api.github.com/repos/user/repo1',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo1/pulls/1'},
state: 'open',
},
{
repository_url: 'https://api.github.com/repos/user/repo1',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo1/pulls/2'},
state: 'closed',
},
{
repository_url: 'https://api.github.com/repos/user/repo1',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo1/pulls/3'},
state: 'closed',
},
{
repository_url: 'https://api.github.com/repos/user/repo2',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo2/pulls/1'},
state: 'open',
},
{
repository_url: 'https://api.github.com/repos/user/repo2',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo2/pulls/2'},
state: 'open',
},
{
repository_url: 'https://api.github.com/repos/user/repo3',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo3/pulls/1'},
state: 'closed',
},
{
repository_url: 'https://api.github.com/repos/user/repo3',
author_association: 'CONTRIBUTOR',
pull_request: {url: 'https://api.github.com/repos/user/repo3/pulls/2'},
state: 'closed',
},
Expand Down

0 comments on commit 3199eb6

Please sign in to comment.