Skip to content

Commit

Permalink
Fix merge conflict for #17 by @kennethvandenberghe ❤️
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb committed Nov 15, 2018
2 parents e0801fb + 03d4bec commit 1e7aff9
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 78 deletions.
52 changes: 31 additions & 21 deletions bin/good-first-issue.js
Expand Up @@ -20,6 +20,7 @@ cli
.option('-f, --first', 'Return first/top issue')
.action(async (project, cmd) => {
let input = project

if (!project) {
input = await prompt()
}
Expand All @@ -28,30 +29,39 @@ cli
if (!(input in projects)) {
console.log(chalk.red(`"${input}" was not found in good-first-issue.`))
console.log('--------------------------------')
console.log('If you\'d like to add a new project to good-first-issue,')
console.log('please see the module\'s Github repository: ' + chalk.cyan('https://github.com/bnb/good-first-issue#adding-new-projects'))
console.log("If you'd like to add a new project to good-first-issue,")
console.log(
"please see the module's Github repository: " +
chalk.cyan(
'https://github.com/bnb/good-first-issue#adding-new-projects'
)
)
process.exit(0)
}

const issues = await search(projects[input].q)

if (issues.length === 0) {
console.log(chalk.yellow(`No Good First Issues were found in ${input}`))
process.exit(0)
}
search(projects[input].q, (error, issues) => {

// Call the log functionality, output the result to the console.
log(issues, projects[input].name, function(error, output) {
if(error) throw error
// Configure the randomizer for the pool of good-first-issues. This cannot exceed how many entries are actually available from the API.
var key = Math.floor(Math.random() * Math.floor(output.length - 1));

if (cmd.first) {
key = 0
}

// Call the log functionality, output the result to the console.
log(issues, projects[input].name, function(error, output) {
if(error) throw error
// Configure the randomizer for the pool of good-first-issues. This cannot exceed how many entries are actually available from the API.
var key = Math.floor(Math.random() * Math.floor(output.length - 1));

if (cmd.first) {
key = 0
}

if (cmd.open) {
opn(issues[key].url)
}

// Log the issue!
console.log(output[key].toString())
})
})
if (cmd.open) {
opn(issues[key].url)
}

// Log the issue!
console.log(output[key].toString())
})
})
.parse(process.argv)
48 changes: 20 additions & 28 deletions lib/search.js
@@ -1,44 +1,36 @@
// This helper goes and fetches Good First Issues
// This module expects a search query which is just a standard GitHub search query. These queries should not include sort or order, since those are defined in the function.
const chalk = require('chalk')

const octokit = require('@octokit/rest')({
timeout: 0, // 0 means no request timeout
headers: {
accept: 'application/vnd.github.v3+json',
'user-agent': 'octokit/rest.js v1.2.3' // v1.2.3 will be current version
},
}
})

// GitHub search parameters for the Node.js org
var sort = 'updated'
var order = 'desc'

function search (q, cb) {
octokit.search.issues({q, sort, order}, (error, result) => {
if(error) throw error
if(result.data.items.length === 0) {
console.log(chalk.yellow('No issues were found'))
process.exit(0)
}
var data = result.data.items.map(issue => {
return data = {
title: issue.title,
pr: issue.number,
labels: issue.labels,
state: issue.state,
repo: issue.repository_url,
url: issue.html_url,
assignee: issue.assignee,
assignees: issue.assignees,
locked: issue.locked
function search(q) {
return octokit.search.issues({ q, sort, order }).then(({ data }) => {
return data.items.reduce((acc, item) => {
if (item.assignee === null && item.locked !== true) {
return acc.concat({
title: item.title,
pr: item.number,
labels: item.labels,
state: item.state,
repo: item.repository_url,
url: item.html_url,
assignee: item.assignee,
assignees: item.assignees,
locked: item.locked
})
}
})

var issues = data.filter(issue => issue.assignee === null && issue.locked !== true)

cb(null, issues)
return acc
}, [])
})
}
}

module.exports = search
module.exports = search
55 changes: 26 additions & 29 deletions lib/search.spec.js
@@ -1,22 +1,22 @@
let issues;
let search;
let issues
let search

beforeEach(() => {
jest.resetModules();
jest.restoreAllMocks();
jest.resetAllMocks();
issues = jest.fn();
jest.resetModules()
jest.restoreAllMocks()
jest.resetAllMocks()
issues = jest.fn()
jest.doMock('@octokit/rest', () => () => {
return {
search: {
issues
}
};
});
search = require('./search');
});
}
})
search = require('./search')
})

test('should return filtered issues', done => {
test('should return filtered issues', () => {
const items = [
{
title: 'fooTitle',
Expand Down Expand Up @@ -51,17 +51,15 @@ test('should return filtered issues', done => {
assignees: 'bazAssignees',
locked: true
}
];
]

issues.mockImplementation((obj, callback) =>
callback(null, {
data: {
items
}
})
);
issues.mockResolvedValue({
data: {
items
}
})

function callback(error, result) {
return search({}).then(result =>
expect(result).toEqual([
{
title: 'fooTitle',
Expand All @@ -74,13 +72,12 @@ test('should return filtered issues', done => {
assignees: 'fooAssignees',
locked: false
}
]);
done();
}
search({}, callback);
});
])
)
})

test('should throw', () => {
issues.mockImplementation((obj, callback) => callback(new Error()));
expect(() => search()).toThrow();
});
test('should throw', async () => {
const error = new Error('myError')
issues.mockRejectedValue(error)
await expect(search()).rejects.toEqual(error)
})

0 comments on commit 1e7aff9

Please sign in to comment.