Skip to content

Commit 60d6cd4

Browse files
committed
Formatted code across project
1 parent 320c9c6 commit 60d6cd4

9 files changed

+45
-31
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Snitch 👉
22

3-
"A project isn't complete unless it has a CHANGELOG!" -- Jeff Schwartz, aka 4awpawz
4-
53
![Static Badge](https://img.shields.io/badge/Markdown-green)
64
![GitHub Release](https://img.shields.io/github/release/4awpawz/snitch/all.svg)
75
[![npm version](https://badge.fury.io/js/@4awpawz%2Fsnitch.svg)](https://badge.fury.io/js/@4awpawz%2Fsnitch)
86
[![License](https://img.shields.io/badge/license-MIT-%230172ad)](https://github.com/picocss/pico/blob/master/LICENSE.md)
97
[![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/4awpawz.svg?style=social&label=Follow%20%404awpawz)](https://twitter.com/4awpawz)
108

11-
## A Multi Purpose GitHub Issue Reporting Tool
9+
## Automated GitHub Issues Reporting
1210

13-
Snitch is a terminal utility that lets you easily create attractive, interactive, and informative reports from GitHub issues that can be used for tracking both open and closed issues by label, assignee and milestone and can provide a timely, accurate, and consolidated view of a project's status.
11+
Snitch is a terminal utility that automates the creation of interactive and informative reports from a GitHub repository's issues.
1412

1513
[![Snitch milestone report video](https://img.youtube.com/vi/u-7oJJUUdGs/0.jpg)](https://www.youtube.com/watch?v=u-7oJJUUdGs)
1614

core/index.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export async function snitch(args) {
1616
const issues = JSON.parse(result)
1717
let output = ""
1818
if (!config.noHeading && config.heading.length) output +=
19-
config.asText ? `${config.heading}\n\n` :
20-
renderInteractive(config, `<h1><a href="${config.repo}" target="_blank" title="link to repository ${config.repo}">${config.heading}</a></h1>\n\n`, `<h1>${config.heading}</h1>\n\n`)
19+
config.asText ? `${config.heading}` :
20+
renderInteractive(config,
21+
`<h1><a href="${config.repo}" target="_blank" title="link to repository ${config.repo}">${config.heading}</a></h1>`,
22+
`<h1>${config.heading}</h1>`)
2123
switch (config.reportName) {
2224
case "list":
2325
output += issuesReport(config, issues)
@@ -37,9 +39,12 @@ export async function snitch(args) {
3739
default:
3840
throw new TypeError(`invalid report type, you entered ${config.reportName}`)
3941
}
42+
const reportEndsWithThreeNewLines = output.endsWith("\n\n\n")
43+
console.error("report ends with three spaces: ", reportEndsWithThreeNewLines)
44+
if (!config.noAttribution && config.asText) output += "\n\n"
4045
if (!config.noAttribution) output +=
41-
config.asText ? `\n| ${attributionText} @ ${snitchUrl}` :
42-
`\n> [${attributionText}](${snitchUrl})`
46+
config.asText ? `| ${attributionText} @ ${snitchUrl}` :
47+
`<blockquote><a href="${snitchUrl}" target="_blank">${attributionText}</a></blockquote>`
4348
process.stdout.write(output)
4449
process.exit(0)
4550
}

core/lib/formatIssue.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export function formatIssue({ state, number, title, labels, assignees, milestone }) {
2-
const template = `${state} ${number} ${title} ${labels} ${assignees} ${milestone}\n`
2+
let template = `${state} ${number} ${title} ${labels} ${assignees} ${milestone}`
33
return template
44
}

core/services/configure.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export async function configure(args) {
2929
config.debug = args.includes("--debug")
3030
config.noAttribution = args.includes("--no-attribution")
3131
config.asText = args.includes("--as-text")
32+
config.blankLines = args.includes("--blank-lines")
3233
if (!config.debug && !reportTypes.includes(config.reportName)) {
3334
console.error("------------------")
3435
console.error("Pick A Report Type")

core/services/reports/issuesByAssigneeReport.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { renderInteractive } from "../../lib/renderInteractive.mjs"
66
import { assigneeUrl } from "../../lib/urls.mjs"
77

88
function assignee(config, _assignee) {
9-
return config.asText ? _assignee.name : renderInteractive(config,
9+
return config.asText ? `\n\n${_assignee.name}` : renderInteractive(config,
1010
`<h2><a href="${assigneeUrl(config, _assignee)}" target="_blank" title="link to assignee ${_assignee.name}">${_assignee.name}</a></h2>`,
1111
`<h2>${_assignee.name}</h2>`
1212
)
@@ -30,7 +30,7 @@ function mapReportableAssignee(config, assignee, issues) {
3030
asgn.id = assignee.id
3131
asgn.login = assignee.login
3232
asgn.name = assignee.name
33-
asgn.issues = getReportableIssues(config, asgn, issues) + "\n"
33+
asgn.issues = getReportableIssues(config, asgn, issues)
3434
return asgn
3535
}
3636

@@ -63,9 +63,8 @@ export function issuesByAssigneeReport(config, issues) {
6363
for (let i = 0; i < reportableAssignees.length; i++) {
6464
const reportableAssignee = reportableAssignees[i]
6565
let formattedOutput = ""
66-
formattedOutput += assignee(config, reportableAssignee) + "\n\n"
66+
formattedOutput += assignee(config, reportableAssignee)
6767
formattedOutput += reportableAssignee.issues
68-
if (i < reportableAssignees.length - 1) formattedOutput += "\n"
6968
output += formattedOutput
7069
}
7170
return output

core/services/reports/issuesByLabelReport.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { renderInteractive } from "../../lib/renderInteractive.mjs"
66
import { reportUnreportables } from "../../lib/reportUnreportables.mjs"
77

88
function label(config, label) {
9-
return config.asText ? `${label.name}` :
10-
renderInteractive(config, `<h2 style="color: #${label.color};"><a style="color: inherit;" href="${labelUrl(config, label)}" target="_blank" title="link to label ${label.name}">${label.name}</a></h2>`, `<h2 style="color: #${label.color};">${label.name}</h2>`)
9+
return config.asText ? `\n\n${label.name}` :
10+
renderInteractive(config,
11+
`<h2 style="color: #${label.color};"><a style="color: inherit;" href="${labelUrl(config, label)}" target="_blank" title="link to label ${label.name}">${label.name}</a></h2>`,
12+
`<h2 style="color: #${label.color};">${label.name}</h2>`)
1113
}
1214

1315
/*
@@ -58,9 +60,8 @@ export function issuesByLabelReport(config, issues) {
5860
for (let i = 0; i < reportableLabels.length; i++) {
5961
const reportableLabel = reportableLabels[i]
6062
let formattedOutput = ""
61-
formattedOutput += label(config, reportableLabel) + "\n\n"
63+
formattedOutput += label(config, reportableLabel)
6264
formattedOutput += reportableLabel.issues
63-
if (i < reportableLabels.length - 1) formattedOutput += "\n"
6465
output += formattedOutput
6566
}
6667
return output

core/services/reports/issuesByMilestoneAndLabelReport.mjs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ import { renderInteractive } from "../../lib/renderInteractive.mjs"
88
function milestone(config, _milestone) {
99
let title = _milestone.title
1010
title = _milestone.dueOn ? `${title} (${_milestone.dueOn.substring(0, 10)})` : title
11-
return config.asText ? `${title}\n\n` :
12-
renderInteractive(config, `<h2><a href="${milestoneUrl(config, _milestone)}" target="_blank" title="link to milestone ${_milestone.title}">${title}</a></h2>\n\n`, `<h2>${title}</h2>\n\n`)
11+
return config.asText ? `\n\n${title}` :
12+
renderInteractive(config,
13+
`<h2><a href="${milestoneUrl(config, _milestone)}" target="_blank" title="link to milestone ${_milestone.title}">${title}</a></h2>`,
14+
`<h2>${title}</h2>`)
1315
}
1416

1517
function label(config, label) {
16-
return config.asText ? ` ${label.name}\n\n` :
17-
renderInteractive(config, `<h3 style="color: #${label.color};"><a style="color: inherit;" href="${labelUrl(config, label)}" target="_blank" title="link to label ${label.name}">${label.name}</a></h3>\n\n`, `<h3 style="color: #${label.color};">${label.name}</h3>\n\n`)
18+
return config.asText ? `\n\n ${label.name}` :
19+
renderInteractive(config,
20+
`<h3 style="color: #${label.color}; margin-left: 2ch;"><a style="color: inherit;" href="${labelUrl(config, label)}" target="_blank" title="link to label ${label.name}">${label.name}</a></h3>`,
21+
`<h3 style="color: #${label.color}; margin-left: 2ch;">${label.name}</h3>`)
1822
}
1923

2024
/*
@@ -23,7 +27,8 @@ function label(config, label) {
2327
function getReportableIssues(config, milestone, label, issues) {
2428
const selector = { showState: true, showLabels: false, showAssignees: true, showMilestones: false }
2529
const milestoneLabelIssues = []
26-
issues.forEach(issue => issue.milestone && issue.milestone.number === milestone.number && issue.labels.some(issueLabel => issueLabel.id === label.id && milestoneLabelIssues.push(issue)))
30+
issues.forEach(issue =>
31+
issue.milestone && issue.milestone.number === milestone.number && issue.labels.some(issueLabel => issueLabel.id === label.id && milestoneLabelIssues.push(issue)))
2732
const lss = issuesReport(config, milestoneLabelIssues, selector)
2833
return lss
2934
}
@@ -84,9 +89,7 @@ export function issuesByMilestoneAndLabelReport(config, issues) {
8489
const reportableMilestoneLabel = reportableMilestone.labels[ii]
8590
formattedOutput += label(config, reportableMilestoneLabel)
8691
formattedOutput += reportableMilestoneLabel.issues
87-
if (ii < reportableMilestone.labels.length - 1) formattedOutput += "\n"
8892
}
89-
if (i < reportableMilestones.length - 1) formattedOutput += "\n"
9093
output += formattedOutput
9194
}
9295
return output

core/services/reports/issuesByMilestoneReport.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import { milestoneUrl } from "../../lib/urls.mjs"
88
function milestone(config, _milestone) {
99
let title = _milestone.title
1010
title = _milestone.dueOn ? `${title} (${_milestone.dueOn.substring(0, 10)})` : title
11-
return config.asText ? `${title}\n\n` :
12-
renderInteractive(config, `<h2><a href="${milestoneUrl(config, _milestone)}" target="_blank" title="link to milestone ${_milestone.title}">${title}</a></h2>\n\n`, `<h2>${title}</h2>\n\n`)
11+
return config.asText ? `\n\n${title}` :
12+
renderInteractive(config,
13+
`<h2><a href="${milestoneUrl(config, _milestone)}" target="_blank" title="link to milestone ${_milestone.title}">${title}</a></h2>`,
14+
`<h2>${title}</h2>`)
1315
}
1416

1517
/*
@@ -30,7 +32,7 @@ function mapReportableMilestone(config, _milestone, issues) {
3032
ms.title = milestone(config, _milestone)
3133
ms.number = _milestone.number
3234
ms.dueOn = Object.hasOwn(_milestone, "dueOn") && _milestone.dueOn || null
33-
ms.issues = getReportableIssues(config, ms, issues) + "\n"
35+
ms.issues = getReportableIssues(config, ms, issues)
3436
return ms
3537
}
3638

@@ -64,7 +66,7 @@ export function issuesByMilestoneReport(config, issues) {
6466
let formattedOutput = ""
6567
formattedOutput += reportableMilestone.title
6668
formattedOutput += reportableMilestone.issues
67-
if (i < reportableMilestones.length - 1) formattedOutput += "\n"
69+
// formattedOutput += !config.blankLines && config.asText && "\n" || ""
6870
output += formattedOutput
6971
}
7072
return output

core/services/reports/issuesReport.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function milestone(config, milestone) {
3333
msName += milestone.dueOn ?
3434
` (${milestone.dueOn.substring(0, 10)})` :
3535
""
36-
return config.asText ? msName : renderInteractive(config, `<a href="${milestoneUrl(config, milestone)}" target="_blank" title="link to milestone ${milestone.title}">${msName}</a>`, msName)
36+
return config.asText ? msName : renderInteractive(config,
37+
`<a href="${milestoneUrl(config, milestone)}" target="_blank" title="link to milestone ${milestone.title}">${msName}</a>`,
38+
msName)
3739
}
3840

3941
function number(number) {
@@ -83,7 +85,7 @@ export function issuesReport(config, issues, opts = { showState: true, showLabel
8385
if (issues.length === 0) reportAndExit(noIssuesToReport)
8486
const reportableIssues = getReportableIssues(config, issues)
8587
if (reportableIssues.length === 0) reportAndExit(noIssuesToReport)
86-
let output = ""
88+
let output = "\n\n"
8789
for (let i = 0; i < reportableIssues.length; i++) {
8890
const reportableIssue = reportableIssues[i]
8991
output += formatIssue({
@@ -94,7 +96,10 @@ export function issuesReport(config, issues, opts = { showState: true, showLabel
9496
assignees: opts.showAssignees ? reportableIssue.assignees : "",
9597
milestone: opts.showMilestones ? reportableIssue.milestone : ""
9698
})
97-
if (i < reportableIssues.length - 1) output += "\n"
99+
if (i < reportableIssues.length - 1 && config.blankLines && config.asText) output += "\n\n"
100+
if (i < reportableIssues.length - 1 && config.blankLines && !config.asText) output += "<br>\n<br>"
101+
if (i < reportableIssues.length - 1 && !config.blankLines && config.asText) output += "\n"
102+
if (i < reportableIssues.length - 1 && !config.blankLines && !config.asText) output += "<br>"
98103
}
99104
return output
100105
}

0 commit comments

Comments
 (0)