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?