Created
August 12, 2024 07:29
-
-
Save NiceRath/18a12f3aa3d8d62534c46d228e5801df to your computer and use it in GitHub Desktop.
JetBrains YouTrack - Workflow to auto-close old tickets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| NOTE: | |
| You need to at least modify the 'tagIdle', 'ticketQuery' and 'closeAction' variables | |
| */ | |
| const entities = require('@jetbrains/youtrack-scripting-api/entities'); | |
| const week = 7 * 24 * 60 * 60 * 1000; | |
| const notifyTime1 = 2 * week; | |
| const notifyTime2 = 4 * week; | |
| const closeTime = 5 * week; | |
| const notifyComment1 = 'Is the ticket still relevant?'; | |
| const notifyComment2 = 'Is the ticket still relevant? It will be closed soon.'; | |
| const closeComment = 'Closing the ticket as it is outdated!'; | |
| const closeAction = 'Outdated'; // action as it can be used in the 'Execute command' context | |
| const tagIdle = 'Idle'; | |
| const ticketQuery = 'Project:TEST #Unsolved' // use a default ticket query to filter on which tickets you want to process | |
| const runCron = '0 0 8 ? * MON'; // monday 0800; '0 */1 * * * ?' = run the rule every minute for testing | |
| // add first comment as notification | |
| // before closing the ticket - we notify again | |
| // after that it is closed | |
| exports.rule = entities.Issue.onSchedule({ | |
| title: 'Notify about and close old tickets', | |
| search: ticketQuery, | |
| cron: runCron, | |
| action: function(ctx) { | |
| var issue = ctx.issue; | |
| var updateDate = new Date(issue.updated); | |
| var ticketIdleTime = Date.now() - updateDate.getTime(); | |
| if (!issue.hasTag(tagIdle)) { | |
| if (ticketIdleTime >= notifyTime1) { | |
| console.log('Comment Issue ID (1): ' + issue.id); | |
| issue.addComment(notifyComment1, ctx.currentUser); | |
| issue.addTag(tagIdle); | |
| } | |
| } else { | |
| if (ticketIdleTime >= closeTime) { | |
| console.log('Closing Issue ID: ' + issue.id); | |
| issue.addComment(closeComment, ctx.currentUser); | |
| issue.applyCommand(closeAction); | |
| } else if (ticketIdleTime >= notifyTime2) { | |
| console.log('Comment Issue ID (2): ' + issue.id); | |
| issue.addComment(notifyComment2, ctx.currentUser); | |
| } else if (ticketIdleTime < notifyTime1) { | |
| console.log('Removing idle tag: ' + issue.id); | |
| issue.removeTag(tagIdle); | |
| } | |
| } | |
| }, | |
| requirements: {} | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment