Bhavya-org / Scripts

1 stars 0 forks source link

LSD to ISSD III - FO request type #65

Open pramodhm112 opened 3 months ago

pramodhm112 commented 3 months ago

import groovy.json.JsonSlurper

def sourceProjectKey = "LSD" def targetProjectKey = "ISSD" def issueKey = issue.key

// Check if the issue is in the source project if (issue.fields.project.key == sourceProjectKey) { def summary = issue.fields.summary def description = issue.fields.description def reporter = issue.fields.reporter?.accountId def requestType = issue.fields.customfield_10848.requestType?.name def sharingPersonaldata = issue.fields.customfield_11931?.value def apiIntegration = issue.fields.customfield_11935?.value

// Check if the request type is "Live or suspected security incident" and incident is "Yes" if (["PCS New Advisory Partner Contract", "PCS New Acquisition Partner Contract", "PCS New Lender Contract"].contains(requestType) && (sharingPersonaldata == "Yes" || apiIntegration == "Yes")) { def targetIssueTypeId = 10288

if (targetIssueTypeId) {
    def createIssuePayload = [
        fields: [
            project: [
                key: targetProjectKey
            ],
            summary: summary,
            description: description,
            reporter: reporter,
            issuetype: [
                id: targetIssueTypeId
            ]
        ]
    ]

    def createResult = post("/rest/api/2/issue")
        .header('Content-Type', 'application/json')
        .body(createIssuePayload)
        .asObject(Map)

    if (createResult.status == 201) {
        def newIssueKey = createResult.body.key

        def linkResult = post("/rest/api/2/issueLink")
            .header('Content-Type', 'application/json')
            .body([
                type: [
                    name: "Problem/Incident"
                ],
                inwardIssue: [
                    key: issueKey
                ],
                outwardIssue: [
                    key: newIssueKey
                ]
            ])
            .asObject(Map)

        if (linkResult.status == 201) {
            println "Issue ${newIssueKey} created and linked to ${issueKey} successfully."
        } else {
            println "Failed to link issue ${newIssueKey} to ${issueKey}: ${linkResult.body}"
        }
    } else {
        println "Failed to create issue in ${targetProjectKey}: ${createResult.status}"
        println "Response body: ${createResult.body}"
    }
}

} else { println "Issue ${issueKey} does not meet the criteria for request type and incident." } } else { println "Issue ${issueKey} is not in the source project ${sourceProjectKey}." }