Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Rebase against github using ScriptRunner

Hi,

I have forked a repository from github and imported it into our Bitbucket instance.

I edited one file and pushed to our Bitbucket repository.

I'm now trying to automate a rebase against the GitHub repository but have no knowledge at all on Groovy nor Bitbucket API. After hours of research, I have made this Custom Schedule Job inline script which does not work of course:

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.repository.Repository
import com.atlassian.bitbucket.repository.RepositoryService
import com.atlassian.bitbucket.repository.RefService
import com.atlassian.bitbucket.repository.Branch
import com.atlassian.bitbucket.user.ApplicationUser
import com.atlassian.bitbucket.user.UserService
import com.atlassian.bitbucket.scm.git.command.GitRebaseCommandParameters
import com.atlassian.bitbucket.scm.git.command.GitExtendedCommandFactory

def repositoryService = ComponentLocator.getComponent(RepositoryService.class)
def refService = ComponentLocator.getComponent(RefService.class)
def cmdFactory = ComponentLocator.getComponent(GitExtendedCommandFactory.class)
def userService = ComponentLocator.getComponent(UserService.class)

Repository rep = repositoryService.getBySlug("RUST", "crates.io-mirror")
Branch master = refService.getDefaultBranch(rep)
ApplicationUser user = userService.findUserByEmail("the_committer@my_company.com")

def paramsBuilder = new GitRebaseCommandParameters.Builder(master, "https://github.com/rust-lang/crates.io-index.git")
paramsBuilder.dryRun(true).committer(user)

def rebase = cmdFactory.rebase(rep, paramsBuilder.build())
rebase.call()

This gives me the following error:

2021-03-18 15:27:06,990 ERROR [c.o.s.j.AbstractCustomScheduledJob]: *************************************************************************************
2021-03-18 15:27:06,995 ERROR [c.o.s.j.AbstractCustomScheduledJob]: Script job: 'Update crates.io mirror' failed
com.atlassian.bitbucket.validation.ArgumentValidationException: The specified upstream, 'https://github.com/rust-lang/crates.io-index.git', is not valid. The upstream must be specified as a full 40-character SHA-1.
at com.atlassian.stash.internal.scm.git.DefaultGitExtendedCommandFactory.rebase(DefaultGitExtendedCommandFactory.java:236)
at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
at com.sun.proxy.$Proxy438.rebase(Unknown Source)
at com.atlassian.bitbucket.scm.git.command.GitExtendedCommandFactory$rebase.call(Unknown Source)
at Script16.run(Script16.groovy:23)
at com.atlassian.stash.internal.scm.git.DefaultGitExtendedCommandFactory.rebase(DefaultGitExtendedCommandFactory.java:236)
at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
at com.sun.proxy.$Proxy438.rebase(Unknown Source)
at com.atlassian.bitbucket.scm.git.command.GitExtendedCommandFactory$rebase.call(Unknown Source)
at Script16.run(Script16.groovy:23)

So the upstream parameters is a SHA-1 string, so I guess I can't refer to a repository outside Bitbucket this way.

How can I do this rebase against a public GitHub repository?

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,741 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you