Skip to content

Commit

Permalink
Use github as markdown renderer, add a release type section
Browse files Browse the repository at this point in the history
  • Loading branch information
klandell committed Jan 24, 2018
1 parent a60b201 commit bf7da4f
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1,019 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Asana Release notes generator
Generates release notes for Asana tasks with a given version number.
# Asana Release Notes Generator
Generates release notes for Asana tasks with a given version number.

Version numbers should be added to Asana tasks via tags in the form `v{version#}` (ex. `v1.5.0`). To start a release, run the command `yarn release` or `yarn release {version#}`. The release notes will be copied to the releases directory. Be sure to create a .env file with the `ASANA_ACCESS_TOKEN`, `ASANA_API_VERSION`, and `ASANA_PROJECT_ID` properties.
Version numbers should be added to Asana tasks via tags in the form `v{version#}` (ex. `v1.5.0`). To start a release, run the command `yarn release` or `yarn release -v {version#} -t {type}`. If no command line arguments are provided, you will be prompted for them. The release notes will be copied to the releases directory. Be sure to create a .env file with the `ASANA_ACCESS_TOKEN`, `ASANA_API_VERSION`, and `ASANA_PROJECT_ID` properties.
87 changes: 63 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// yup, tons of dependencies. It's a command line tool, I don't care.
const chalk = require('chalk');
const csv = require('csvtojson');
const fetch = require('node-fetch');
const fs = require('fs');
const marked = require('marked');
const minimist = require('minimist');
const mkdirp = require('mkdirp');
const moment = require('moment');
const pdf = require('html-pdf');
Expand All @@ -13,7 +12,6 @@ const { wrapBody } = require('./template');

// use some async stuff where possible
const mkdir = promisify(mkdirp);
const toHTML = promisify(marked);
const writeFile = promisify(fs.writeFile);

// load in environment variables
Expand Down Expand Up @@ -75,12 +73,17 @@ const getTasks = async (tagId) => {
};

// generates the release notes and calls the functions to write out the files
const genNotes = async (version, tasks = []) => {
const genNotes = async (version, type, tasks = []) => {
const now = moment();
const text =
`# Version ${version} Release Notes
`# ATLAS ${version} Release Notes
_Tasks may be viewed directly on Asana by clicking their taskId_
 
##### Release Type:
- [${type === 'major' ? 'x' : ' '}] Major
- [${type === 'minor' ? 'x' : ' '}] Minor
- [${type === 'patch' ? 'x' : ' '}] Patch
##### Items completed:
${tasks.sort(({ id: a }, { id: b }) => a > b ? 1 : (a < b ? -1 : 0))
.map(({ id, name }) => (
Expand All @@ -90,11 +93,12 @@ const genNotes = async (version, tasks = []) => {
&nbsp;
_Generated ${now.format('MM/DD/YYYY')} at ${now.format('hh:mm A')}_
`.replace(/ {2,}/g, ''); // replace groups of 2 or more spaces with an empty string for proper formatting
const htmlBody = await render(text); // generate an html body from the text

const htmlBody = await toHTML(text.replace(/&nbsp;/g, '<br><br>')); // generate an html body from the text
const dir = `./releases/v${version}`;
const filePath = `${dir}/v${version}`;

// make a subdirectory for this release
try {
await mkdir(dir);
} catch (err) {
Expand All @@ -104,12 +108,39 @@ const genNotes = async (version, tasks = []) => {

// write the text directory into the markdown file
writeMD(filePath, text);
// write the html file
writeHTML(filePath, htmlBody);
// write the pdf file
writePDF(filePath, htmlBody);

// only write the html and pdf files if rendering was successful.
if (htmlBody) {
// write the html file
writeHTML(filePath, htmlBody);
// write the pdf file
writePDF(filePath, htmlBody);
}
}

const render = async (text) => {
let data;
console.log(chalk.yellow('Rendering markdown...'));

try {
const response = await fetch('https://api.github.com/markdown', {
method: 'POST',
body: JSON.stringify({
text: text,
mode: 'gfm',
}),
});
if (response.ok) {
data = await response.text();
} else {
logError('An error occurred while rendering the markdown');
}
} catch (err) {
logError('An error occurred while rendering the markdown');
}
return data;
};

// write the markdown file out to the releases directory
const writeMD = async (filePath, text) => {
try {
Expand Down Expand Up @@ -151,29 +182,37 @@ const writePDF = (filePath, body) => {
};

// prompt the user for a version string
const argVersion = process.argv[2];
if (argVersion) {
prompt.override = { version: argVersion };
}
const argv = minimist(process.argv.slice(2));
prompt.override = { version: argv.v, type: argv.t };

prompt.message = '';
prompt.delimiter = '';

prompt.start();
prompt.get([{
name: 'version',
type: 'string',
description: chalk.green('Enter the version number (ex. 1.0.0):'),
pattern: /^\d+\.\d+\.\d+$/,
message: 'The version must be in the format x.x.x',
required: true,
}], async (err, result) => {
prompt.get([
{
name: 'version',
type: 'string',
description: chalk.green('Enter the version number (ex. 1.0.0):'),
pattern: /^\d+\.\d+\.\d+$/,
message: 'The version must be in the format x.x.x',
required: true,
},
{
name: 'type',
type: 'string',
description: chalk.green('Enter the release type (major|minor|patch):'),
pattern: /^major$|^minor$|^patch$/i,
message: 'You must enter a valid release type',
required: true,
}
], async (err, result) => {
if (result) {
const { version } = result;
const { version, type } = result;
const tagId = await getTagId(`v${version}`);
if (tagId) {
const tasks = await getTasks(tagId);
genNotes(version, tasks);
genNotes(version, type.toLowerCase(), tasks);
}
}
});
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "asana-release-notes",
"version": "0.0.1",
"description": "Generate release notes from an Asana export",
"description": "Generate release notes from Asana tasks with a version tag",
"main": "index.js",
"author": "Kyle Landell <kyle.landell@gmail.com>",
"license": "MIT",
Expand All @@ -13,8 +13,7 @@
"csvtojson": "^1.1.9",
"dotenv": "^4.0.0",
"html-pdf": "^2.2.0",
"latest": "^0.2.0",
"marked": "^0.3.12",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"moment": "^2.20.1",
"node-fetch": "^1.7.3",
Expand Down
Loading

0 comments on commit bf7da4f

Please sign in to comment.