Workflow JS: track issue tags changed

Answered

Is it able to track issue tags changing?

issue.hasTag() not actually solves my purpose: I want to track adding/removing tags on issue. Ideally i want to track add/remove specific tag.

Thanks 

6 comments
Comment actions Permalink
Official comment

You need `issue.tags.added` and `issue.tags.removed` properties. These properties contain sets of tags, added/removed during current issue modification.

To find a specific tag inside these sets, you may use https://www.jetbrains.com/help/youtrack/incloud/v1-Set.html#has method, where `element` should be added as a requirement (see https://www.jetbrains.com/help/youtrack/incloud/requirements.html#requirements-example). Another way is to iterate over these Sets with `forEach` method and look for a tag by name and/or by owner.

 

Comment actions Permalink

Спасибо, то что нужно!
не нашёл про added и removed в документации

0
Comment actions Permalink

@mariya, 

I am not able to get this Tag added notification to Slack workflow working. I can't seem to figure out how to watch for a tag to be added. I've tried issue.tags.added and issue.tags.removed in the action but still nothing. 

============================================

// IMPORTANT: Use a valid Incoming Webhook from Slack. To get one, go to https://my.slack.com/services/new/incoming-webhook/
// youtrack_tickets T0253QBLAHSLAHLSHSLHJFmQ
/// PRIVATE T0253GALAHSHSHSHSHSgMm0Eexu43DW

var SLACK_WEBHOOK_URL = 'T0253GALAHSHSHSHSHSgMm0Eexu43DW';

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var http = require('@jetbrains/youtrack-scripting-api/http');

exports.rule = entities.Issue.onChange({
title: 'Send notifications to Slack whenever an issue tag is added',
guard: function(ctx) {
///return ctx.issue.becomesReported || ctx.issue.becomesResolved || ctx.issue.becomesUnresolved;
return ctx.issue.tags.added;
},
action: function(ctx) {
var issue = ctx.issue;

var issueLink = '<' + issue.url + "|" + issue.id + '>';
var message, isNew;

if (issue.becomesReported) {
message = "Issue Created: ";
isNew = true;
} else if (issue.becomesResolved) {
message = "Issue Resolved: ";
isNew = false;
} else if (issue.becomesUnresolved) {
message = "Issue Reopened: ";
isNew = false;
}
message += issue.summary;
var paletteString = "#FFFFFF,#8d5100,#ce6700,#409600,#0070e4,#900052,#0050a1,#2f9890,#8e1600," +
"#dc0083,#7dbd36,#ff7123,#ff7bc3,#fed74a,#b7e281,#d8f7f3,#e6e6e6,#e6f6cf,#ffee9c,#ffc8ea,#e30000," +
"#e0f1fb,#fce5f1,#f7e9c1,#92e1d5,#a6e0fc,#e0c378,#bababa,#25beb2,#42a3df,#878787,#4d4d4d,#246512,#00665e,#553000,#1a1a1a";
var palette = paletteString.split(",");
var color = palette[issue.Priority.colorIndex];

if (!color) {
color = "#edb431";
}

var changedByTitle = '',
changedByName = '',
priority = '',
status = '',
assignee = '',
tag = issue.tags.added.name;

if (issue.Priority) priority = issue.Priority.name;
if (issue.Status) status = issue.Status.name;
if (issue.Assignee) assignee = issue.Assignee.fullName;

if (isNew) {
changedByTitle = "Created By";
changedByName = issue.reporter.fullName;
} else {
changedByTitle = "Updated By";
changedByName = issue.updatedBy.fullName;
}

var payload = {
"attachments": [{
"fallback": issueLink,
"pretext": message + issueLink,
"color": color,
"fields": [
{
//"title": '',
"value": "*"+'<' + issue.url + "|" + issue.summary + '>'+"*",
"short": true
},
{
//"fields": "Status",
//"value": "*Type:* "+issue.Type.name,
//"short": true
//"fields": "Status",
"value": "*Tag:* "+tag,
"short": true
}, {
//"fields": "Status",
"value": "*"+"Status:* "+status,
"short": true
},
{
//"fields": changedByTitle,
"value": "*"+changedByTitle+":"+"* "+changedByName,
"short": true
}
]
}]
};

var connection = new http.Connection(SLACK_WEBHOOK_URL, null, 2000);
var response = connection.postSync('', null, JSON.stringify(payload));
if (!response.isSuccess) {
console.warn('Failed to post notification to Slack. Details: ' + response.toString());
}
},
}
);

==========================================================

0
Comment actions Permalink

@Bjorgensen

tag = issue.tags.added.name

tags.added is a Set, not a single tag. You can use 

issue.tags.added.first()

to get first tag from Set, or iterate whole tags.added Set to get all added tags

https://www.jetbrains.com/help/youtrack/standalone/v1-Set.html

0
Comment actions Permalink

Thanks @Dmitriy, I've made that change, but my other problem is that the workflow is not being triggered when adding a tag to an issue. 

Any ideas?

 

0
Comment actions Permalink

It looks like IssueTag.isNew was added in 2018.2. I'm currently waiting on my platform team to updated from 2018.1. - 2018.3. 

0

Please sign in to leave a comment.