Action when a tag is added

Hello,

We would like to create an action when a specific tag is added to an issue. What is the best way to do that ?

Ex : tag.Released.isAdded { //Do something }

Thanks in advance

Regards

0
8 comments
Official comment

Hello,

You can check the following:

if (ctx.issue.tags.added.isNotEmpty() && ctx.issue.tags.added.has(ctx.Released))

Besides that, describe Tag in requirements:

requirements: {
Released: {
type: entities.IssueTag,
name: "Released"
}
}

 

Avatar
Permanently deleted user

Hello,

Nevermind I found a way to do it.

exports.rule = entities.Issue.onChange({
title: 'Your title',
guard: function(ctx) {
var issue = ctx.issue;
return issue.isResolved && issue.tags.added.has(ctx.Released);
},
action: function(ctx) {
//your action rule
},
requirements: {
Released: {
type: entities.IssueTag
}
}
});


Hope it can helps others.

0

Hello,

ctx.issue.tags.added.isNotEmpty() only works with normal tags, and when a Star tag is added, this condition does not work.

How to track a Star tag?

Anastasia Bartasheva 

0

Hi Viacheslav Bachynskyi,

ctx.issue.tags.added.isNotEmpty() should work for the Star tag as well. In particular, the following condition determines whether any new watchers were added:

ctx.issue.tags.added.isNotEmpty() && ctx.issue.tags.added.find(t => t.name === "Star")

Can you please share the full workflow code from your side and describe the issue in more detail, how exactly ctx.issue.tags.added.isNotEmpty() doesn't work (whether it returns false or something else happens)?

0

Hi Julia Bernikova 

Here is the code:

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

const debug = true;

exports.rule = entities.Issue.onChange({
  title: 'Adding Watchers to "Visible to" list',
  guard: (ctx) => {
    return ctx.issue.tags.added.isNotEmpty();
  },
  action: (ctx) => {
    const issue = ctx.issue;

    issue.tags.forEach(function(tag) {
      if (tag.name === "Star") {
        if (!issue.isVisibleTo(tag.owner)) {
          issue.permittedUsers.add(tag.owner);

          if (debug) {
            console.log("Access granted to: " + tag.owner.login);
          }
        }
      }
    });
  },
  requirements: {}
});
0

When I add someone as an Assignee for the Issue, they are added to the Watchers list. At this moment, the Issue gets the ‘Star’ tag and the workflow should be triggered. But it doesn't work.

0

Hi Viacheslav Bachynskyi,

Thanks for explaining the scenario further. ctx.issue.tags.added.isNotEmpty() indeed only catches explicit tag addition, i.e. when a user manually clicks the “Star” icon within the issue. However, there's no way to detect it from a workflow if it's set implicitly as a result of changing the issue assignee. This ensures that the “Star” tag behavior configured by the user in their profile settings remains unaffected.

In your case, a more fitting solution would be catching the assignee change and making sure the issue is visible to them:

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

exports.rule = entities.Issue.onChange({
  title: 'Add-assignee-to-issue-visibility',
  guard: (ctx) => {
    return ctx.issue.Assignee && ctx.issue.isChanged("Assignee");
  },
  action: (ctx) => {
    const issue = ctx.issue;
    if (!issue.isVisibleTo(issue.Assignee)) {
      issue.permittedUsers.add(issue.Assignee);
      issue.addComment(issue.Assignee.fullName + " is added to the issue visibility since they are now the assignee");
    }
  }
});

 

0

Please sign in to leave a comment.