changelog_output
Advanced tools
Comparing version 1.0.4 to 1.0.5
100
cli.js
@@ -23,2 +23,4 @@ #!/usr/bin/env node | ||
let releaseDate = '' | ||
const slackCharSafeLimit = 2000 | ||
let currentCharCount = 0 | ||
@@ -105,2 +107,3 @@ function checkForConfig() { | ||
const commitRegex = /\*\*([\s\S]*?)\n/g | ||
let issueCount = 0 | ||
const issues = [] | ||
@@ -113,3 +116,15 @@ | ||
for (let m = 0; m < match.length; m++) { | ||
issues.push(match[m]) | ||
const issue = match[m] | ||
currentCharCount = currentCharCount + issue.length | ||
if (currentCharCount > slackCharSafeLimit) { | ||
++issueCount | ||
currentCharCount = 0 | ||
} | ||
if (issues[issueCount]) { | ||
issues[issueCount].push(issue) | ||
} else { | ||
issues.push([]) | ||
issues[issueCount].push(issue) | ||
} | ||
} | ||
@@ -123,16 +138,19 @@ } | ||
function createLinks(issues) { | ||
const output = [] | ||
const output = [...Array(issues.length)].map(() => []) | ||
const WDFRegex = /([a-zA-Z]+(-[0-9]+)+)/g | ||
for (let i = 0; i < issues.length; i++) { | ||
const issue = { | ||
title: `N/A • ${issues[i]}` | ||
for (let o = 0; o < issues.length; o++) { | ||
for (let i = 0; i < issues[o].length; i++) { | ||
const currentIssue = issues[o][i] | ||
const issue = { | ||
title: `N/A • ${currentIssue}` | ||
} | ||
if (WDFRegex.test(currentIssue)) { | ||
const match = currentIssue.match(WDFRegex) | ||
issue['title'] = `<${baseLink}${match[0]}|${match[0]}> • ${currentIssue}` | ||
} | ||
output[o].push(issue) | ||
} | ||
if (WDFRegex.test(issues[i])) { | ||
const match = issues[i].match(WDFRegex) | ||
issue['title'] = `<${baseLink}${match[0]}|${match[0]}> • ${issues[i]}` | ||
} | ||
output.push(issue) | ||
} | ||
@@ -144,14 +162,37 @@ | ||
function createOutputFile(data) { | ||
let outputFile = `${title}${releaseDate}\n${version}\n\n${data.map(d => { | ||
// if (d.link) { | ||
// return d.title + d.link + '\n\n' | ||
// } | ||
return d.title + '\n' | ||
})}`; | ||
outputFile = outputFile.replace(/,/g, '') | ||
outputFile = outputFile.replace(/\*\*/g, '') | ||
console.warn(outputFile) | ||
const blocks = [ | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: `${title}${releaseDate}` | ||
} | ||
}, | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: `*${version}*` | ||
} | ||
} | ||
]; | ||
for (let d = 0; d < data.length; d++) { | ||
let outputText = `${data[d].map(d => { | ||
return d.title + '\n' | ||
})}` | ||
outputText = outputText.replace(/,/g, '') | ||
outputText = outputText.replace(/\*\*/g, '') | ||
const block = { | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: outputText | ||
} | ||
} | ||
blocks.push(block) | ||
} | ||
const slackData = { | ||
blocks | ||
}; | ||
console.warn('slackPath', slackPath) | ||
if (slackPath) { | ||
@@ -161,14 +202,3 @@ axios({ | ||
url: `https://hooks.slack.com/services/${slackPath}`, | ||
data: { | ||
text: 'Changelog', | ||
blocks: [ | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: outputFile | ||
} | ||
} | ||
] | ||
}, | ||
data: slackData, | ||
headers: { | ||
@@ -175,0 +205,0 @@ 'Content-type': 'application/json' |
{ | ||
"writeOutput": false, | ||
"fileName": "CHANGELOG_TEST.md", | ||
"fileName": "CHANGELOG_LARGE.md", | ||
"link": "https://worked.atlassian.net/browse/" | ||
} |
{ | ||
"name": "changelog_output", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"local:check": "node cli.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -8,0 +9,0 @@ }, |
8766
200