Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First time importing pull request from public to private #107

Open
maksyche opened this issue Nov 27, 2019 · 5 comments
Open

First time importing pull request from public to private #107

maksyche opened this issue Nov 27, 2019 · 5 comments

Comments

@maksyche
Copy link

Hello!

I'm stuck on importing PRs.

  • I have private and public repositories.
  • Before release I need to import some PRs from public to private repository. There have been zero migrations using Copybara before and repositories have zero commits in common.
  • Copybara obviously cannot find parent commit. I tell it to use latest master commit as parent and it replaces new code in private with the old one from public which is not the part of the PR.

But I need to migrate only PR changes. I think I can use something like patch. Is there any solutions for doing it using Copybara?

Here's my current config:

core.workflow(
  name = "import_pr_from_oss",

  origin = git.github_pr_origin(
    url = publicRepoUrl,
    state = "ALL",
    use_merge = True,
  ),
  destination = git.github_pr_destination(
    url = internalRepoUrl,
    destination_ref = "master-internal", # TODO: Update to master after test
    integrates = [],
  ),
  mode = "CHANGE_REQUEST",
  set_rev_id = False,

  authoring = authoring.pass_thru("**authoring here**"),

  # Including/excluding files
  origin_files = glob(["**"], exclude = [

    # exclude hidden files
    ".**",
    "**/.**",

    # exclude all private sources
    "private/**",

    # exclude helper scripts and related
    "**.sh",
    "**.log",
    "**.rc",
    "revision.txt",

    # exclude generated bits
    "**/target/**",
    "**/node_modules/**",

  ]) + glob([

    # keep some specified files
    ".circleci/config.yml",
    "**/.placeholder",
    ".mvn/**",
  ]),

  destination_files = glob(["**"], exclude = [

    # exclude hidden files
    ".**",
    "**/.**",

    # exclude all private sources
    "private/**",

    # exclude helper scripts and related
    "**.sh",
    "**.log",
    "**.rc",
    "revision.txt",

    # exclude generated bits
    "**/target/**",
    "**/node_modules/**",
  ]) + glob([

    # keep some specified files
    ".circleci/config.yml",
    "**/.placeholder",
    ".mvn/**",
  ]),

  transformations = [
    metadata.save_author(),
    metadata.expose_label("COPYBARA_INTEGRATE_REVIEW")
    metadata.replace_message("${GITHUB_PR_TITLE}\n\n${GITHUB_PR_BODY}\n\nSubmitted by: @${GITHUB_PR_USER}\n\nExternal PR number: #${GITHUB_PR_NUMBER}"),
  ],

Thank you!

@DarthHater
Copy link
Contributor

@mikelalcon we are working to get Copybara working on an existing project (nexus repository, wee!), and this is holding us up a bit. Any thoughts?

@mikelalcon
Copy link
Collaborator

Hi!

core.workflow has smart_prune field. Unfortunately, this field usage is not implemented for git.destination. The use case is when you do scrubbing from internal to external repo.

Keeping that usage apart, there is not usage for it, as the source should converge to one version (internal and external).

The other option is to use patch.apply or git.origin patch field. This allows you to apply internal only patches to the import. (This would be used if external is the SoT)

@maksyche
Copy link
Author

maksyche commented Dec 3, 2019

Hi!

core.workflow has smart_prune field. Unfortunately, this field usage is not implemented for git.destination. The use case is when you do scrubbing from internal to external repo.

Keeping that usage apart, there is not usage for it, as the source should converge to one version (internal and external).

The other option is to use patch.apply or git.origin patch field. This allows you to apply internal only patches to the import. (This would be used if external is the SoT)

Thank you!
Is there any examples with patch usage? I cannot find them in docs

@mikelalcon
Copy link
Collaborator

We don't have. Here is an example:

Assuming you have this file structure:

copy.bara.sky
patches/patch1.patch
patches/patch2.patch

You would add:

origin = git.github_pr_origin(
   ...
   patch = patch.apply(["patches/patch1.patch", "patches/patch2.patch"]),
   ...
)

or

transformations = [
   ...
   patch.apply(["patches/patch1.patch", "patches/patch2.patch"]),
   ...
]

The advantage of the git origin version is that if you generate the patch from the origin repo ( maybe do an initial temporary and local git apply of the internal patch to the external repo and then save that patch) it will use 3way merge when applying the patch.

@armooo
Copy link

armooo commented Feb 12, 2020

I took a shot at adding smart_prune support in #112. At least for my use case it has allowed importing PRs from github when scrubbing was used in the export process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants