Developer Portal for YouTrack and Hub Help

Notify Reporter to Approve Fix

This workflow sends notification to the user who reported an issue when the issue is resolved.

Name

@jetbrains/youtrack-workflow-notify-reporter-to-approve-fix

Auto-attached

no

Modules

Notify reporter to approve fix (on-change rule)

Define transitions for "State" field for fixes that are approved by reporters (state-machine rule)

Use Case

This workflow was originally taken from a submitted request (JT-7821).

The user who submitted this issue wanted to make sure that the resolution of an issue could be approved by the user who reported the issue.

Here's how it works:

  1. The reporter creates an issue.

  2. The issue is fixed, its status is set to fixed, and the change is built and deployed by TeamCity.

  3. When the fix is deployed (in a test/stage or production environment), the issue status is set to Pending verification in Test/production (either manually by the developer or automatically based on some status information from TeamCity).

  4. A notification is sent to the reporter.

  5. The reporter tests the issue in a suitable environment and determines one of the possible outcomes:

    • The issue is fixed. The reporter then approves the fix and closes the issue (or moves it to another state that corresponds to the team workflow).

    • The issue is still not fixed. The reporter returns it to the developer as "not approved".

Modules

This workflow includes two modules. The first contains an on-change rule that sends notifications, and the second contains a state-machine rule that manages the lifecycle of an issue.

Notify reporter to approve fix

The first rule notifies the user who reported the issue and sets the reporter as the assignee.

When an issue is updated, this rule checks whether the state was changed to Pending verification. If true, then:

  • The reporter is notified.

  • The reporter is set as the Assignee of the issue.

const entities = require('@jetbrains/youtrack-scripting-api/entities'); const workflow = require('@jetbrains/youtrack-scripting-api/workflow'); exports.rule = entities.Issue.onChange({ title: 'Notify reporter to approve fix', guard: (ctx) => { return ctx.issue.fields.becomes(ctx.State, ctx.State.Pending); }, action: (ctx) => { const issue = ctx.issue; issue.fields.Assignee = issue.reporter; issue.reporter.notify(workflow.i18n('Please approve fix for the issue {0}', issue.id), workflow.i18n('You have reported issue {0}. Please verify the applied fix for the issue and set the appropriate state.', issue.id), true); }, requirements: { State: { type: entities.EnumField.fieldType, Pending: { name: 'Pending verification' } }, Assignee: { type: entities.User.fieldType } } });

Define transitions for "State" field for fixes that are approved by reporters

The next rule defines the lifecycle for issues to support this use case.

This rule defines the following transitions for issue states:

  1. An issue starts with the state Submitted.

  2. From the initial state, an issue can only transition to the following state:

    • On event (action) Open, the state is set to Open.

  3. From the Open state, an issue can only transition to the following state:

    • On event (action) Fix, the state is set to Fixed.

  4. When the state is set to Fixed, the user is forced to set the Fixed in build field.

  5. From the Fixed state, an issue can only transition to the following state:

    • On event (action) Send for verification, the state is set to Pending for verification.

  6. When the state is set to Pending for Verification, the reporter is set as the Assignee. The reporter is notified and asked to approve the fix.

  7. From the Pending for Verification state, an issue can only transition to the following states:

    • On event (action) Approve, the state is set to Verified.

    • On event (action) Re-open, the state is set to Open.

  8. From the Open state, the issue can only transition to Fixed.

  9. From the Verified state, no further state transitions are allowed.

const entities = require('@jetbrains/youtrack-scripting-api/entities'); const workflow = require('@jetbrains/youtrack-scripting-api/workflow'); exports.rule = entities.Issue.stateMachine({ title: 'Define transitions for "State" field for fixes that are approved by reporters', fieldName: 'State', states: { Submitted: { initial: true, transitions: { open: { targetState: 'Open' } } }, Open: { transitions: { fix: { targetState: 'Fixed' } } }, Fixed: { onEnter: (ctx) => { ctx.issue.fields.required(ctx.FixedInBuild, workflow.i18n('Please set \'Fixed in build\' value.')); }, transitions: { 'Send for verification': { targetState: 'Pending verification' } } }, 'Pending verification': { onEnter: (ctx) => { const issue = ctx.issue; issue.fields.Assignee = issue.reporter; issue.reporter.notify(workflow.i18n('Please approve fix for the issue {0}', issue.id), workflow.i18n('You have reported issue {0}. Please verify the applied fix for the issue and set the appropriate state.', issue.id), true); }, transitions: { Approve: { targetState: 'Verified' }, Reopen: { targetState: 'Open' } } }, Verified: { transitions: { Reopen: { targetState: 'Open' } } } }, requirements: { FixedInBuild: { type: entities.Build.fieldType, name: 'Fixed in build' }, Assignee: { type: entities.User.fieldType } } });
Last modified: 15 March 2024