Skip to content

Commit

Permalink
Merge pull request #102 from danhellem/mdToHtml
Browse files Browse the repository at this point in the history
markdown to HTML conversion so that work item descriptions are formatted nicely
  • Loading branch information
danhellem authored Jan 21, 2022
2 parents 291f27c + f20d3a1 commit b82f037
Show file tree
Hide file tree
Showing 974 changed files with 39,996 additions and 195 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ typings/

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
Expand All @@ -100,8 +99,4 @@ dist
.dynamodb/

# TernJS port file
.tern-port

node_modules/
**/node_modules
node_modules/**
.tern-port
70 changes: 28 additions & 42 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const core = require(`@actions/core`);
const github = require(`@actions/github`);
const azdev = require(`azure-devops-node-api`);
const azdev = require('azure-devops-node-api');
const showdown = require('showdown');

const debug = false; // debug mode for testing...always set to false before doing a commit
const testPayload = []; // used for debugging, cut and paste payload
Expand Down Expand Up @@ -142,22 +143,27 @@ async function main() {
// create Work Item via https://docs.microsoft.com/en-us/rest/api/azure/devops/
async function create(vm) {
if (vm.env.logLevel >= 200) console.log(`Starting 'create' method...`);

var converter = new showdown.Converter();
var html = converter.makeHtml(vm.body);

converter = null;

let patchDocument = [
{
op: "add",
path: "/fields/System.Title",
value: vm.title + " (GitHub Issue #" + vm.number + ")"
value: vm.title + ` (GitHub Issue #${vm.number})`
},
{
op: "add",
path: "/fields/System.Description",
value: vm.body
value: html
},
{
op: "add",
path: "/fields/Microsoft.VSTS.TCM.ReproSteps",
value: vm.body
value: html
},
{
op: "add",
Expand All @@ -175,17 +181,7 @@ async function create(vm) {
{
op: "add",
path: "/fields/System.History",
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
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}`
},
{
op: "add",
Expand Down Expand Up @@ -273,6 +269,10 @@ async function create(vm) {
async function update(vm, workItem) {
if (vm.env.logLevel >= 200) console.log(`Starting 'update' method...`);

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

if (
Expand All @@ -286,20 +286,17 @@ async function update(vm, workItem) {
});
}

if (
workItem.fields["System.Description"] != vm.body ||
workItem.fields["Microsoft.VSTS.TCM.ReproSteps"] != vm.body
) {
if (workItem.fields["System.Description"] != html || workItem.fields["Microsoft.VSTS.TCM.ReproSteps"] != html ) {
patchDocument.push(
{
op: "add",
path: "/fields/System.Description",
value: vm.body,
value: html,
},
{
op: "add",
path: "/fields/Microsoft.VSTS.TCM.ReproSteps",
value: vm.body,
value: html,
}
);
}
Expand Down Expand Up @@ -327,19 +324,18 @@ async function update(vm, workItem) {
async function comment(vm, workItem) {
if (vm.env.logLevel >= 200) console.log(`Starting 'comment' method...`);

var converter = new showdown.Converter();
var html = converter.makeHtml(vm.comment_text);

converter = null;

let patchDocument = [];

if (vm.comment_text != "") {
patchDocument.push({
op: "add",
path: "/fields/System.History",
value:
'<a href="' +
vm.comment_url +
'" target="_new">GitHub issue comment added</a> by ' +
vm.user +
"</br></br>" +
vm.comment_text,
value: `<a href="${vm.comment_url}" target="_new">GitHub issue comment added</a> by ${vm.user}</br></br>${html}`,
});
}

Expand Down Expand Up @@ -372,15 +368,7 @@ async function close(vm, workItem) {
patchDocument.push({
op: "add",
path: "/fields/System.History",
value:
'GitHub <a href="' +
vm.url +
'" target="_new">issue #' +
vm.number +
"</a> was closed on " +
vm.closed_at +
" by " +
vm.user,
value: `GitHub <a href="${vm.url}" target="_new">issue #${vm.number}</a> closed by ${vm.user}`,
});
}

Expand Down Expand Up @@ -412,7 +400,7 @@ async function reopened(vm, workItem) {
patchDocument.push({
op: "add",
path: "/fields/System.History",
value: "GitHub issue reopened by " + vm.user,
value: `GitHub issue reopened by ${vm.user}`,
});

// verbose logging
Expand Down Expand Up @@ -497,9 +485,7 @@ async function find(vm) {
try {
client = await connection.getWorkItemTrackingApi();
} catch (error) {
console.log(
"Error: Connecting to organization. Check the spelling of the organization name and ensure your token is scoped correctly."
);
console.log("Error: Connecting to organization. Check the spelling of the organization name and ensure your token is scoped correctly.");
core.setFailed(error);
return -1;
}
Expand Down Expand Up @@ -694,4 +680,4 @@ function getValuesFromPayload(payload, env) {
}

return vm;
}
}
15 changes: 15 additions & 0 deletions node_modules/.bin/showdown

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/showdown.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions node_modules/.bin/showdown.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node_modules/@actions/core/lib/command.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions node_modules/@actions/core/lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/@actions/core/lib/command.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions node_modules/@actions/core/lib/core.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b82f037

Please sign in to comment.