Last active
February 18, 2020 09:49
-
-
Save jechlin/6365d2e3c0ef4b94deb636db9c2cde7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, [])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!