package com.onresolve.jira.groovy.test.workflow.testscripts.remote

// tag::ex1[]
import com.atlassian.bitbucket.project.ProjectService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.remote.RemoteControl

@Grapes([ // <1>
    @Grab("com.atlassian.bitbucket.server:bitbucket-api:5.1.0"),
    @GrabExclude("com.atlassian.annotations:atlassian-annotations")
])
def dummy = 1 // <2>

def jraProjectKeys = ComponentAccessor.projectManager.projectObjects*.key

def bbsProjKeys = RemoteControl.forPrimaryBitbucketAppLink().exec {
    def projectService = ComponentLocator.getComponent(ProjectService)
    projectService.findAllKeys()
}

(jraProjectKeys - bbsProjKeys).each {
    log.warn("No Bitbucket project for JIRA project: $it")
    // create it...
}

(bbsProjKeys - jraProjectKeys).each {
    log.warn("No JIRA project for Bitbucket project: $it")
    // create it...
}
// end::ex1[]
