YouTrack InCloud 2017.3 Help

Referred Issues

This workflow automatically adds a refers to link when another issue is mentioned by its Id in a comment or description.

Name@jetbrains/youtrack-workflow-referred-issues
Auto-attachedno
Modules Add "refers to" link to an issue when the issue ID is added to a description or comment (on-change rule)

Use Case

This workflow helps you automate the creation of links between related issues.

This workflow references an issue link type with the name refers to. This is a custom issue link type that is not available in YouTrack by default. To use this workflow, you need to add this issue link type to your system. When you create this issue link type, enter the following values:

FieldDescription
NameReference (or any other name, this does not affect the workflow)
Outward Namerefers to
Link DirectionUndirected

For general instructions, see Create an Issue Link Type.

Modules

This on-change rule in this module checks the description and comment for an issue for references to other issues. When one or more references are found, the issues are added as refers to links.

Add "refers to" link to an issue when the issue ID is added to a description or comment

var entities = require('@jetbrains/youtrack-scripting-api/entities'); var workflow = require('@jetbrains/youtrack-scripting-api/workflow'); exports.rule = entities.Issue.onChange({ title: workflow.i18n('Add "refers to" link to an issue when the issue ID is added to a description or comment'), guard: function(ctx) { return !ctx.issue.comments.added.isEmpty() || ctx.issue.isChanged('description'); }, action: function(ctx) { var issue = ctx.issue; var startGroup = /(^|[',;.:"\\()?!<>#+|/\[\]\t\n\r ])/; var endGroup = /([',;.:"\\()?!<>#+|/\[\]\t\n\r ]|$)/; var issueIdGroup = '(' + issue.project.key.toLowerCase() + '-\\d+)'; var regexp = new RegExp(startGroup.source + issueIdGroup + endGroup.source, 'i'); var text = issue.comments.added.isEmpty() ? issue.description : issue.comments.added.first().text; var match = regexp.exec(text); var allMentionedIssues = {}; while (match) { var matchedIssueId = match[2].trim(); var referringIssue = entities.Issue.findById(matchedIssueId); if (referringIssue !== null) { issue.links[ctx.RefersTo.outward].add(referringIssue); allMentionedIssues[matchedIssueId] = true; } text = text.substring(match.index + match[0].length); match = regexp.exec(text); } var allAddedIssues = Object.keys(allMentionedIssues); if (allAddedIssues.length) { workflow.message(workflow.i18n('Automatically added \'refers to\' {0} links.', allAddedIssues.join())); } }, requirements: { RefersTo: { type: entities.IssueLinkPrototype, name: 'Refers', outward: 'refers to' } } });
Last modified: 6 September 2017