DevGenius1 / Scripts

1 stars 1 forks source link

round robbin #16

Open sani-d opened 5 months ago

sani-d commented 5 months ago

def result = get("/rest/api/2/project/ITSUPP/properties/round-robin").asString().body def parsedJson = new groovy.json.JsonSlurper().parseText(result) def lastIndex = parsedJson.value.value.lastIndex

// Piyush : 712020:c20f2e11-244e-4e77-8a53-bf978b3c14b6 // Ujwal : 5ee0b09aa1a84e0ab4498f3f // Naresh : 712020:38850a20-a476-4f68-adea-36ff0b0f84fd // Lyubo : 62c0ee212b6e4ddba1166992 // Sudeepto : 623913da7910a200718a15d7 // Shakthi : 712020:efaf05f9-8ec7-4cce-a1ad-f42329a86baa // Satya : 62e5cb0d4913d0b7348a37d3

// Available variables // PIYUSH, UJWAL, NARESH, LYUBO, SUDEEPTO, SHAKTHI, SATYA, Mohit, Martin, Junaid

// Define account IDs of users to be assigned issues // Naresh 712020:38850a20-a476-4f68-adea-36ff0b0f84fd // Satya 62e5cb0d4913d0b7348a37d3 // Lyubo 62c0ee212b6e4ddba1166992 // Ujwal 5ee0b09aa1a84e0ab4498f3f // Piyush 712020:c20f2e11-244e-4e77-8a53-bf978b3c14b6 // Sudeepto 623913da7910a200718a15d7 // Shakthi 712020:efaf05f9-8ec7-4cce-a1ad-f42329a86baa // Martin 712020:697ba254-3ad0-49ea-99c1-726692d816bf // Junaid 712020:b3c858bb-9c99-4a7d-a19b-64b60425dcec // Mohit 712020:12f2b7b8-b70d-477a-80ca-89d72ff97fd0

def users = ['712020:38850a20-a476-4f68-adea-36ff0b0f84fd', '62e5cb0d4913d0b7348a37d3', '62c0ee212b6e4ddba1166992', '5ee0b09aa1a84e0ab4498f3f','712020:c20f2e11-244e-4e77-8a53-bf978b3c14b6', '623913da7910a200718a15d7']

// Define issue key variable def issueKey = issue.key

// Check if lastIndex is null and set it to 0 if necessary if (lastIndex == null) { lastIndex = 0 }

// Update issue with next assignee based on round-robin index and users array def assignIssue = put("/rest/api/2/issue/${issueKey}") .header('Content-Type', 'application/json') .queryString("notifyUsers": false) .body([ fields: [ assignee: [accountId: users[lastIndex]] ] ]) .asString()

logger.info("Operation performed with status code ${assignIssue.status} and assigned issue to ${users[lastIndex]}")

// if (assignIssue.status == 204) { // Update the index for the next user assignment lastIndex = (lastIndex + 1) % users.size()

// Update the round-robin project property value
def updateRoundRobin = put("/rest/api/2/project/ITSUPP/properties/round-robin")
    .header('Content-Type', 'application/json')
    .header('Accept', 'application/json')
    .body([
        value: [
            lastIndex: lastIndex
        ]
    ])
    .asString()

// return 'Success'

// } else { // return "${assignIssue.status}: ${assignIssue.body}" // }