Targetprocess

The Targetprocess Developer Hub

Welcome to the Targetprocess developer hub. Here you'll find comprehensive guides and documentation to help you start working with Targetprocess as quickly as possible and support you if you get stuck. Let's jump right in!

Docs

Example: Change state in Targetprocess, when merge/pull request updates

📘

How to apply Raw JSON from examples

This rule reacts on a set of updates of merge/pull requests and triggers a state change of a Targetprocess item, related to updated branch or merge/pull request

  • WIP is removed from the merge request name;
  • Merge/pull request gets all required approvals;
  • Merge/pull request is merged;
  • Branch closes without code changes;
const utils = require('utils')
const devOps = require('devOps')

var stateTo = ''
var cmds = []

if (args.ResourceType != 'MergeRequest') return []


var isWIPRemoved = devOps.mergeRequestDraftRemoved(args)
var ifApproved = devOps.mergeRequestApproved(args)
var ifMerged = devOps.mergeRequestMerged(args)
var ifClosed = devOps.mergeRequestClosed(args)

console.log(`isWIPRemoved: ${isWIPRemoved}`)
console.log(`ifApproved: ${ifApproved}`)
console.log(`ifMerged: ${ifMerged}`)
console.log(`ifClosed: ${ifClosed}`)

if (isWIPRemoved) {
  stateTo = 'Code Review'
}

if (ifApproved) {
  stateTo = 'To Test'
}

if (ifMerged) {
  stateTo = 'Integrated'
}

if (ifClosed) {
  stateTo = 'Open'
}

// Change state if needed
if (stateTo != '') {
  var entityIds = args.TargetprocessEntityIds;
  for (let i = 0; i < entityIds.length; i++) {
    var id = entityIds[i];
    cmds.push(
      utils.moveToStateByName('UserStory', id, stateTo)
    );
  }
}

console.log(`State To: ${stateTo}`)


return cmds;

States of entities in Targetprocess are specified by name. Just put the right names in THEN clause of the rule instead of the ones in bold:

🚧

Put your state names in THEN of the rule for each event:

if (isWIPRemoved) {
stateTo = 'Code Review'
}

if (ifApproved) {
stateTo = 'To Test'
}

if (ifMerged) {
stateTo = 'Integrated'
}

if (ifClosed) {
stateTo = 'Open'
}

{
    "type": "source:devOps:EntityChanged",
    "entityTypes": [
      "MergeRequest"
    ],
    "modifications": {
      "created": false,
      "deleted": false,
      "updated": [
        "repository",
        "id",
        "sourceId",
        "title",
        "isDraft",
        "url",
        "state",
        "mergeStatus",
        "reviewStatus",
        "branch"
      ]
    }
  }

Updated about a year ago

Example: Change state in Targetprocess, when merge/pull request updates


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.