Skip to content

Commit b82f037

Browse files
authored
Merge pull request #102 from danhellem/mdToHtml
markdown to HTML conversion so that work item descriptions are formatted nicely
2 parents 291f27c + f20d3a1 commit b82f037

File tree

974 files changed

+39996
-195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

974 files changed

+39996
-195
lines changed

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ typings/
7979

8080
# Nuxt.js build / generate output
8181
.nuxt
82-
dist
8382

8483
# Gatsby files
8584
.cache/
@@ -100,8 +99,4 @@ dist
10099
.dynamodb/
101100

102101
# TernJS port file
103-
.tern-port
104-
105-
node_modules/
106-
**/node_modules
107-
node_modules/**
102+
.tern-port

index.js

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const core = require(`@actions/core`);
22
const github = require(`@actions/github`);
3-
const azdev = require(`azure-devops-node-api`);
3+
const azdev = require('azure-devops-node-api');
4+
const showdown = require('showdown');
45

56
const debug = false; // debug mode for testing...always set to false before doing a commit
67
const testPayload = []; // used for debugging, cut and paste payload
@@ -142,22 +143,27 @@ async function main() {
142143
// create Work Item via https://docs.microsoft.com/en-us/rest/api/azure/devops/
143144
async function create(vm) {
144145
if (vm.env.logLevel >= 200) console.log(`Starting 'create' method...`);
146+
147+
var converter = new showdown.Converter();
148+
var html = converter.makeHtml(vm.body);
149+
150+
converter = null;
145151

146152
let patchDocument = [
147153
{
148154
op: "add",
149155
path: "/fields/System.Title",
150-
value: vm.title + " (GitHub Issue #" + vm.number + ")"
156+
value: vm.title + ` (GitHub Issue #${vm.number})`
151157
},
152158
{
153159
op: "add",
154160
path: "/fields/System.Description",
155-
value: vm.body
161+
value: html
156162
},
157163
{
158164
op: "add",
159165
path: "/fields/Microsoft.VSTS.TCM.ReproSteps",
160-
value: vm.body
166+
value: html
161167
},
162168
{
163169
op: "add",
@@ -175,17 +181,7 @@ async function create(vm) {
175181
{
176182
op: "add",
177183
path: "/fields/System.History",
178-
value:
179-
'GitHub <a href="' +
180-
vm.url +
181-
'" target="_new">issue #' +
182-
vm.number +
183-
'</a> created in <a href="' +
184-
vm.repo_url +
185-
'" target="_new">' +
186-
vm.repo_fullname +
187-
"</a> by " +
188-
vm.user
184+
value: `GitHub <a href="${vm.url}" target="_new">issue #${vm.number}</a> created in <a href="${vm.repo_url}" target="_new">${vm.repo_fullname}</a> by ${vm.user}`
189185
},
190186
{
191187
op: "add",
@@ -273,6 +269,10 @@ async function create(vm) {
273269
async function update(vm, workItem) {
274270
if (vm.env.logLevel >= 200) console.log(`Starting 'update' method...`);
275271

272+
var body = vm.body.replace(`AB#${workItem.id}`, '').trim();
273+
var converter = new showdown.Converter();
274+
var html = converter.makeHtml(body);
275+
converter = null;
276276
let patchDocument = [];
277277

278278
if (
@@ -286,20 +286,17 @@ async function update(vm, workItem) {
286286
});
287287
}
288288

289-
if (
290-
workItem.fields["System.Description"] != vm.body ||
291-
workItem.fields["Microsoft.VSTS.TCM.ReproSteps"] != vm.body
292-
) {
289+
if (workItem.fields["System.Description"] != html || workItem.fields["Microsoft.VSTS.TCM.ReproSteps"] != html ) {
293290
patchDocument.push(
294291
{
295292
op: "add",
296293
path: "/fields/System.Description",
297-
value: vm.body,
294+
value: html,
298295
},
299296
{
300297
op: "add",
301298
path: "/fields/Microsoft.VSTS.TCM.ReproSteps",
302-
value: vm.body,
299+
value: html,
303300
}
304301
);
305302
}
@@ -327,19 +324,18 @@ async function update(vm, workItem) {
327324
async function comment(vm, workItem) {
328325
if (vm.env.logLevel >= 200) console.log(`Starting 'comment' method...`);
329326

327+
var converter = new showdown.Converter();
328+
var html = converter.makeHtml(vm.comment_text);
329+
330+
converter = null;
331+
330332
let patchDocument = [];
331333

332334
if (vm.comment_text != "") {
333335
patchDocument.push({
334336
op: "add",
335337
path: "/fields/System.History",
336-
value:
337-
'<a href="' +
338-
vm.comment_url +
339-
'" target="_new">GitHub issue comment added</a> by ' +
340-
vm.user +
341-
"</br></br>" +
342-
vm.comment_text,
338+
value: `<a href="${vm.comment_url}" target="_new">GitHub issue comment added</a> by ${vm.user}</br></br>${html}`,
343339
});
344340
}
345341

@@ -372,15 +368,7 @@ async function close(vm, workItem) {
372368
patchDocument.push({
373369
op: "add",
374370
path: "/fields/System.History",
375-
value:
376-
'GitHub <a href="' +
377-
vm.url +
378-
'" target="_new">issue #' +
379-
vm.number +
380-
"</a> was closed on " +
381-
vm.closed_at +
382-
" by " +
383-
vm.user,
371+
value: `GitHub <a href="${vm.url}" target="_new">issue #${vm.number}</a> closed by ${vm.user}`,
384372
});
385373
}
386374

@@ -412,7 +400,7 @@ async function reopened(vm, workItem) {
412400
patchDocument.push({
413401
op: "add",
414402
path: "/fields/System.History",
415-
value: "GitHub issue reopened by " + vm.user,
403+
value: `GitHub issue reopened by ${vm.user}`,
416404
});
417405

418406
// verbose logging
@@ -497,9 +485,7 @@ async function find(vm) {
497485
try {
498486
client = await connection.getWorkItemTrackingApi();
499487
} catch (error) {
500-
console.log(
501-
"Error: Connecting to organization. Check the spelling of the organization name and ensure your token is scoped correctly."
502-
);
488+
console.log("Error: Connecting to organization. Check the spelling of the organization name and ensure your token is scoped correctly.");
503489
core.setFailed(error);
504490
return -1;
505491
}
@@ -694,4 +680,4 @@ function getValuesFromPayload(payload, env) {
694680
}
695681

696682
return vm;
697-
}
683+
}

node_modules/.bin/showdown

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/showdown.cmd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/showdown.ps1

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/LICENSE.md

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/README.md

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.d.ts

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)