Developer Portal for YouTrack and Hub 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-attached

no

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:

Field

Description

Name

Reference (or any other name, this does not affect the workflow)

Outward Name

refers to

Link Direction

Undirected

For general instructions, see Create 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.

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