Comparing server and cloud projects migration

I used this to see the state of migrated projects and to cross check numbers after migration.
JCMA has improved a lot so this may a bit of overkill but I found it useful so I hope some of you will.
To be run in server Script Console.
It will compare and return the number of issues in projects on the server and cloud instances.
(The HTTPS, REST_SEARCH, SERVER, CLOUD are only there as this forum doesn’t allow posting multiple URLS.)

import groovyx.net.http.ContentType
import groovyx.net.http.EncoderRegistry
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
import groovy.json.JsonSlurper
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.component.ComponentAccessor
 
//CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
String authString = "username:secretword".bytes.encodeBase64().toString()
  
ProjectManager pMgr = ComponentAccessor.getProjectManager()
  
String HTTPS = "https"
String REST_SEARCH = "/rest/api/2/search?jql=project="
String SERVER = "://<myserver>"
String CLOUD = "://<mycloud>"
def yourProjectIssues = HTTPS + SERVER + REST_SEARCH
def urlEnd = "&maxResults=1"
logit.info("Start====")
  
def proj = pMgr.getProjectObjects()
int count = 0
proj.each() {Project p ->
    def svrUrl = yourProjectIssues + p.getKey() + urlEnd
    def svrTotal = get(svrUrl, authString)
    def cloudCount = getCloudProject(p.getKey(), logit)
    String compare = ""
    if (svrTotal && cloudCount) {
        if (svrTotal == cloudCount) {compare = "="}
        else if (svrTotal < cloudCount) {compare = "?"}
        else if (svrTotal > cloudCount) {compare = "running"}
    }
    if (cloudCount) {
        logit.info( p.getKey() + "," + svrTotal + "," + cloudCount + "," + compare )
        count++
    }
}
logit.info("Finish====. " + count)
  
public String getCloudProject(String project, Logger logit) {
    def baseUrl     = HTTPS + CLOUD
    String authString2 = "username:cloudtoken".bytes.encodeBase64().toString()
    StringBuffer jsonBody = new StringBuffer()
    jsonBody.append('{')
  
    jsonBody.append('"jql": "project = '+project+'",')
    jsonBody.append('"startAt": 0,')
    jsonBody.append('"maxResults": 1,')
    jsonBody.append('"fields": [')
    jsonBody.append('"summary",')
   // jsonBody.append('"assignee",')
    jsonBody.append('"key"')
    jsonBody.append(']')
     //jsonBody.append('"fieldsByKeys": false')
    jsonBody.append('}')
//   }
    RESTClient restClient
    HttpResponseDecorator response
 
    try {
        restClient = new RESTClient(baseUrl)
        restClient.encoderRegistry = new EncoderRegistry(charset: 'UTF-8')
        restClient.setHeaders([
            Authorization      : "Basic ${authString2}",
            "X-Atlassian-Token": "no-check",
            Accept: "*/*" ,
            "Content-Type": "application/json"
        ])
   
        response = restClient.post(path: '/rest/api/2/search' , contentType: ContentType.JSON, body: "${jsonBody.toString()}" )
        def jdata = groovy.json.JsonOutput.toJson(response.data)//.collectEntries{['worker':it.value.worker, 'projectKey':it.value.issue.projectKey,'started':Date.parse( 'yyyy-MM-dd',it.value.started[0]),'amount':it.value.sum{it.billableSeconds}]})
        def json = new JsonSlurper().parseText(jdata)
        return json.total
        //log.info(json.total)
    } catch (Exception e) {
        //log.info "Error      : ${e.getMessage()}"
        //log.info "Message    : ${e.response.data}"
        //log.info "Reason.    : ${e.response.getStatusLine().getReasonPhrase()}"
       // return null
    
    }
    return null
 
}


public String get(String url, String auth) {
     def connection = url.toURL().openConnection()
     connection.addRequestProperty("Authorization", "Basic ${auth}")
 
     connection.setRequestMethod("GET")
     connection.doOutput = false
     connection.connect()
     def data = connection.content.text
     def json = new JsonSlurper().parseText(data)
     return json.total
 }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.