Integrate PR from public github repo to internal bitbucket repo

161 views
Skip to first unread message

Andreas Doppelhofer

unread,
Dec 3, 2018, 5:17:26 AM12/3/18
to Copybara OSS

Hello,

i have the following scenario. I want to sync our internal bitbucket repo with an external public github repo and migrate pull requests from public github repo to our internal bitbucket repo. But I don’t want to sync all the stuff from internal repo to outside (we have some interal dirs which I do not want to sync to public) Source of truth will be the internal repo.

 

Following repo structure:

 

Internal bitbucketrepo a.git:

private/somefile

public/somefilesA

public/somefilesB

 

 

public githubrepo a.git: (everything from interal public will be moved to .)

somefilesA

somefilesB

 

here is my initial sync sky file and command for private -> public initial sync

 * docker run -e COPYBARA_CONFIG='copy.bara.sky' -e COPYBARA_OPTIONS='--force' -v ~/.ssh:/root/.ssh -v ~/.gitconfig:/root/.gitconfig -v "$(pwd)":/usr/src/app -it copybara copybara

--

# Update these references to your orginzations repos

sourceUrl = "ssh://g...@bitbucket.xxx/a.git"

destinationUrl = "g...@github.com:some_user/a.git"

 

core.workflow(

    name = "default",

    #mode="ITERATIVE",

    origin = git.origin(

        url = sourceUrl,

        ref = "master",

    ),

    destination = git.destination(

        url = destinationUrl,

        fetch = "master",

        push = "master",

    ),

    # Change path to the folder you want to publish publicly

    origin_files = glob(["public/**"]),

 

    authoring = authoring.pass_thru("a.d. <a.d.@someurl.com>"),

 

    # Change the path here to the folder you want to publish publicly

    transformations = [

            core.move("public", ""),

        ],

)

--

 

here is my integrate sky file and command for private -> public migration

* docker run -e COPYBARA_CONFIG='copy.bara.sky' -v ~/.ssh:/root/.ssh -v ~/.gitconfig:/root/.gitconfig -v "$(pwd)":/usr/src/app -it copybara copybara

--

sourceUrl = "ssh://g...@bitbucket.xxx/a.git"

destinationUrl = "g...@github.com:some_user/a.git"

 

core.workflow(

    name = "default",

    mode="ITERATIVE",

    origin = git.origin(

        url = sourceUrl,

        ref = "master",

    ),

    destination = git.destination(

        url = destinationUrl,

        fetch = "master",

        push = "master",

    ),

    # Change path to the folder you want to publish publicly

    origin_files = glob(["public/**"]),

 

    authoring = authoring.pass_thru("a.d. <a.d.@someurl.com>"),

 

    # Change the path here to the folder you want to publish publicly

    transformations = [

            core.move("public", ""),

        ],

)

--

 

And now this should do the PR stuff from public github to private bitbucket repo

(all sync stuff from previous is fine, so I created a PR and try to integrate it in my repo)

BUT if I run this command everything get’s deleted in my private repo except the changes in public folder.

(the PR contains only one change in the file ‘somefilesA’)

 

docker run -e COPYBARA_CONFIG='copy.bara.sky' -e COPYBARA_SOURCEREF='1' -v ~/.ssh:/root/.ssh -v ~/.gitconfig:/root/.gitconfig -v "$(pwd)":/usr/src/app -it copybara copybara

--

sourceUrl = "g...@github.com:some_user/a.git"

destinationUrl = "ssh://g...@bitbucket.xxx/a.git"

 

core.workflow(

    name = "default",

    origin = git.github_pr_origin(

        url = sourceUrl,

        use_merge = True,

    ),

    destination = git.destination(

        url = destinationUrl,

        fetch = "master",

        push = "master",

        integrates = []

    ),

    mode = "CHANGE_REQUEST",

    set_rev_id = False,

    # Change path to the folder you want to publish publicly

    origin_files = glob(["**"], exclude = ["private/**"]),

 

 

 

    authoring = authoring.pass_thru("a.d. <a.d.@someurl.com>"),

    transformations = [

      metadata.save_author(),

      metadata.expose_label("COPYBARA_INTEGRATE_REVIEW"),

      metadata.expose_label("GITHUB_PR_NUMBER", new_name ="Closes", separator=" #"),

      core.move("", "public")

    ],

)

--

 

What I’m doing wrong? For me it would be nice, that if I’m migrating a PR to the internal bitbucket, there also a PR will be created to verify it. I do not want to commit it directly to master. (but if isn’t possible, maybe bitbucket api missing, I prefere to commit the PR to a dedicated PR branch, maybe PR_1..) So how to I configure this PR merge from public to private correctly?

 

Thx! Andreas

Andreas Doppelhofer

unread,
Dec 3, 2018, 6:50:46 AM12/3/18
to Copybara OSS
if i use following config, the PR is merged into the private repo (master branch). So the "new" question is, how to create a PR in private bitbucket instead of merging into master...

core.workflow(
    name = "default",
    origin = git.github_pr_origin(
        url = sourceUrl,
        use_merge = True,
    ),
    destination = git.destination(
        url = destinationUrl,
        fetch = "master",
        push = "master",
        integrates = []
    ),
    mode = "CHANGE_REQUEST",
    set_rev_id = False,
    # Change path to the folder you want to publish publicly
    origin_files = glob(["**"], exclude = ["private/**"]),
    destination_files = glob(["public/**"], exclude = ["private/"]),

Miguel Alcon

unread,
Dec 3, 2018, 1:51:53 PM12/3/18
to andreas.doppe...@gmail.com, copybara...@googlegroups.com
As you found, the problem was in the destination_files. IIUC, for public to private you'll need:

origin_files = glob(["**"]), # The default, you can omit
destination_files = glob(["**"], exclude = ["private/**"]),

Regarding to creating PR in bitbucket: Currently we don't have support for bitbucket. But we would be open to accept a git.bitbucket_pr_destination if you want to contribute it.

Cheers,
Mikel.



--
You received this message because you are subscribed to the Google Groups "Copybara OSS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to copybara-discu...@googlegroups.com.
To post to this group, send email to copybara...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/copybara-discuss/0871d16d-55d3-41f6-a9b3-c44456a01a80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Doppelhofer

unread,
Dec 4, 2018, 8:43:10 AM12/4/18
to Copybara OSS
Thx for your response. Currently creating an internal branch for an external PR fits our needs. 

But i have 1 more question. If i create a new internal release branch or create a tag how to i sync it correctly to the public github repo?
Only changing master to a release/1.1 in my config (i used the --force for copybara) create a "new" standalone commit. :-(


    authoring = authoring.pass_thru("a.d. <a....@someurl.com>"),
    transformations = [
      metadata.save_author(),
      metadata.expose_label("COPYBARA_INTEGRATE_REVIEW"),
      metadata.expose_label("GITHUB_PR_NUMBER", new_name ="Closes", separator=" #"),
      core.move("", "public")
    ],
)

Miguel Alcon

unread,
Dec 10, 2018, 2:54:22 PM12/10/18
to Andreas Doppelhofer, Copybara OSS
Hi,

Yes we don't have a good way of doing multibranch movement (you can create a workflow per branch but it won't connect them). Also we don't cannot move tag -> tag (proper move, since it would require to move the branch and then creating a tag from the branch).


Reply all
Reply to author
Forward
0 new messages