Skip to content

Commit

Permalink
Merge pull request #81 from hemal7735/enhance/log
Browse files Browse the repository at this point in the history
enhance lib/log.js and test-case
  • Loading branch information
bnb authored Feb 26, 2019
2 parents c17b200 + 58fd6df commit a239281
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 24 deletions.
8 changes: 4 additions & 4 deletions bin/good-first-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ cli
process.exit(0)
}

// Call the log functionality, output the result to the console.
let output = await log(issues, projects[input].name)
let key = cmd.first ? 0 : Math.floor(Math.random() * Math.floor(issues.length - 1))

let key = cmd.first ? 0 : Math.floor(Math.random() * Math.floor(output.length - 1))
// Call the log functionality, output the result to the console.
let output = await log(issues[key], projects[input].name)

// Log the issue!
console.log(output[key].toString())
console.log(output.toString())

if (cmd.open) {
opn(issues[key].url)
Expand Down
34 changes: 15 additions & 19 deletions lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@ var boxenOptions = {
borderColor: 'green',
borderStyle: 'round'
}
async function log (issues, project) {
var set = []
for (var issue in issues) {
var data = {
leftpad: ' ',
doublepad: ' ',
header: 'Good First Issue in ' + chalk.yellow(project) + ': ',
title: chalk.green(issues[issue].title),
issue: chalk.cyan('#' + issues[issue].pr),
state: chalk.green(issues[issue].state),
unassigned: chalk.green('unassigned!'), // All assigned issues are being filtered out at the search level, so all issues will always be unassigned
link: chalk.cyan(issues[issue].url),
repo: chalk.green(issues[issue].url.toString().slice(19, issues[issue].url.toString().indexOf('/issue'))),
labels: issues[issue].labels
}
async function log (issue, project) {
const data = {
leftpad: ' ',
doublepad: ' ',
header: 'Good First Issue in ' + chalk.yellow(project) + ': ',
title: chalk.green(issue.title),
issue: chalk.cyan('#' + issue.pr),
state: chalk.green(issue.state),
unassigned: chalk.green('unassigned!'), // All assigned issues are being filtered out at the search level, so all issues will always be unassigned
link: chalk.cyan(issue.url),
repo: chalk.green(issue.url.toString().slice(19, issue.url.toString().indexOf('/issue'))),
labels: issue.labels
}

var output = '\n' + boxen(data.header + '\n\n' + ' - Title: ' + data.title + '\n' + ' - Repository: ' + data.repo + '\n' + ' - Issue: ' + data.issue + '\n' + ' - Status: ' + data.state + '\n' + ' - Assigned to: ' + data.unassigned + '\n\n' + 'Start now: ' + data.link, boxenOptions) + '\n'
const output = '\n' + boxen(data.header + '\n\n' + ' - Title: ' + data.title + '\n' + ' - Repository: ' + data.repo + '\n' + ' - Issue: ' + data.issue + '\n' + ' - Status: ' + data.state + '\n' + ' - Assigned to: ' + data.unassigned + '\n\n' + 'Start now: ' + data.link, boxenOptions) + '\n'

set.push(output)
}
return set
return output
}

module.exports = log
39 changes: 39 additions & 0 deletions lib/log.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const log = require('./log')
const chalk = require('chalk')
const stripAnsi = require('strip-ansi');

test('should return formatted log', async () => {
const org = 'foojs'
const repo = 'barjs'
const issue = {
title: 'Add BAZ support',
pr: 123,
labels: [[Object], [Object], [Object]],
state: 'open',
repo: `https://api.github.com/${org}/${repo}`,
url: `https://github.com/${org}/${repo}/issues/123`,
assignee: null,
assignees: [],
locked: false
}

const expectedOutput = `
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โ”‚
โ”‚ Good First Issue in foojs: โ”‚
โ”‚ โ”‚
โ”‚ - Title: Add BAZ support โ”‚
โ”‚ - Repository: foojs/barjs โ”‚
โ”‚ - Issue: #123 โ”‚
โ”‚ - Status: open โ”‚
โ”‚ - Assigned to: unassigned! โ”‚
โ”‚ โ”‚
โ”‚ Start now: https://github.com/foojs/barjs/issues/123 โ”‚
โ”‚ โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
`

const actualOutput = await log(issue, org)

expect(expectedOutput).toBe(stripAnsi(actualOutput))
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"devDependencies": {
"jest": "^23.6.0",
"markdown-magic": "^0.1.25",
"standard": "^12.0.1"
"standard": "^12.0.1",
"strip-ansi": "^5.0.0"
}
}

0 comments on commit a239281

Please sign in to comment.