Skip to content

Instantly share code, notes, and snippets.

@jechlin
Last active February 18, 2020 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jechlin/6365d2e3c0ef4b94deb636db9c2cde7d to your computer and use it in GitHub Desktop.
Save jechlin/6365d2e3c0ef4b94deb636db9c2cde7d to your computer and use it in GitHub Desktop.
import com.atlassian.bitbucket.event.repository.RepositoryCreatedEvent
import com.atlassian.bitbucket.event.repository.RepositoryPushEvent
import com.atlassian.bitbucket.scm.git.GitAgent
import com.atlassian.bitbucket.scm.git.command.GitCommandBuilderFactory
import com.atlassian.event.api.EventPublisher
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.canned.bitbucket.bulkedit.StringCommandOutputHandler
import com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketBaseScript
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import groovy.transform.BaseScript
@BaseScript BitbucketBaseScript baseScript
def gitAgent = ScriptRunnerImpl.getOsgiService(GitAgent)
def eventPublisher = ComponentLocator.getComponent(EventPublisher)
def repository = (event as RepositoryCreatedEvent).repository
def builder = (gitCommandBuilderFactory as GitCommandBuilderFactory).builder(repository)
def newTree = builder
.command("write-tree")
.build(StringCommandOutputHandler.stringOut())
.call()
def newCommit = builder
.command("commit-tree")
.argument(newTree)
.argument("-m")
.argument("Initial commit")
.build(StringCommandOutputHandler.stringOut())
.call()
gitAgent.createRef(repository, "refs/heads/master", newCommit)
eventPublisher.publish(new RepositoryPushEvent("", repository, []))
@adirlau
Copy link

adirlau commented Feb 18, 2020

com.atlassian.bitbucket.scm.git.GitAgent this class is depricated since 5.10 version. Do you have any idea how to createRef using another class? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment