Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 84 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ async function main() {
workItem != null ? await reopened(vm, workItem) : "";
break;
case "assigned":
console.log("assigned action is not yet implemented");
workItem != null ? await assigned(vm, workItem) : "";
break;
case "unassigned":
workItem != null ? await assigned(vm, workItem) : "";
break;
case "labeled":
workItem != null ? await label(vm, workItem) : "";
Expand Down Expand Up @@ -165,6 +168,11 @@ async function create(vm) {
path: "/fields/Microsoft.VSTS.TCM.ReproSteps",
value: html
},
{
op: "add",
path: "/fields/Microsoft.VSTS.Scheduling.StoryPoints",
value: vm.defaultStoryPoints
},
{
op: "add",
path: "/fields/System.Tags",
Expand Down Expand Up @@ -213,6 +221,15 @@ async function create(vm) {
});
}

// if assignee is not empty, set it
if (vm.env.assignedTo != "") {
patchDocument.push({
op: "add",
path: "/fields/System.AssignedTo",
value: vm.env.assignedTo
});
}

// if the bypassrules are on, then use the issue.sender.user.name value for the person
// who created the issue
if (vm.env.bypassRules) {
Expand Down Expand Up @@ -286,6 +303,26 @@ async function update(vm, workItem) {
});
}

if (
workItem.fields["System.AssignedTo"] != vm.env.assignedTo
) {

if (vm.env.assignedTo == "") {
console.log("Removing assigned to field");

patchDocument.push({
op: "remove",
path: "/fields/System.AssignedTo",
});
} else {
console.log("Reassigning work item to new user");
patchDocument.push({
op: "add",
path: "/fields/System.AssignedTo",
value: vm.env.assignedTo,
});
}}

if (workItem.fields["System.Description"] != html || workItem.fields["Microsoft.VSTS.TCM.ReproSteps"] != html ) {
patchDocument.push(
{
Expand Down Expand Up @@ -402,6 +439,47 @@ async function close(vm, workItem) {
}
}

async function assigned(vm, workItem) {
if (vm.env.logLevel >= 200) console.log(`Starting 'assigned' method...`);

let patchDocument = [];


if (
workItem.fields["System.AssignedTo"] != vm.env.assignedTo
) {
if (vm.env.assignedTo == "") {
console.log("Removing assigned to field");

patchDocument.push({
op: "remove",
path: "/fields/System.AssignedTo",
});
}
else
{
console.log("Reassigning work item to new user");
patchDocument.push({
op: "add",
path: "/fields/System.AssignedTo",
value: vm.env.assignedTo,
});
}}

// verbose logging
if (vm.env.logLevel >= 300) {
console.log("Print full patch object:");
console.log(patchDocument);
}

if (patchDocument.length > 0) {
return await updateWorkItem(patchDocument, workItem.id, vm.env);
} else {
return null;
}
}


// reopen existing work item
async function reopened(vm, workItem) {
if (vm.env.logLevel >= 200) console.log(`Starting 'reopened' method...`);
Expand Down Expand Up @@ -617,7 +695,8 @@ async function updateIssueBody(vm, workItem) {
owner: vm.owner,
repo: vm.repository,
issue_number: vm.number,
body: vm.body,
body: vm.body//,
// assignees: vm.env.AssignedTo
});

// verbose logging
Expand Down Expand Up @@ -649,6 +728,7 @@ function getValuesFromPayload(payload, env) {
closed_at: payload.issue.closed_at != undefined ? payload.issue.closed_at : null,
owner: payload.repository.owner != undefined ? payload.repository.owner.login : "",
sender_login: payload.sender.login != undefined ? payload.sender.login : '',
defaultStoryPoints: env.defaultStoryPoints != undefined ? env.defaultStoryPoints : 0.5,
label: "",
comment_text: "",
comment_url: "",
Expand All @@ -667,7 +747,8 @@ function getValuesFromPayload(payload, env) {
newState: env.ado_new_state != undefined ? env.ado_new_state : "New",
activeState: env.ado_active_state != undefined ? env.ado_active_state : "Active",
bypassRules: env.ado_bypassrules != undefined ? env.ado_bypassrules : false,
logLevel: env.log_level != undefined ? env.log_level : 100
logLevel: env.log_level != undefined ? env.log_level : 100,
assignedTo: env.ado_assigned_to != undefined ? env.ado_assigned_to : "none"
}
};

Expand Down