Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance lib/log.js and test-case #81

Merged
merged 2 commits into from
Feb 26, 2019
Merged
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
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"
}
}