gotsunami/gitlab-copy

Current version overwrites From host information with To host information

Closed this issue · 4 comments

Very happy to have found this utility. It helped me to solve capturing a snapshot of a repo that was too large to export/import by bringing over just the current state and then using this tool to get the issues brought over.

After successfully testing gitlab-copy and getting it to work on sample repos that both lived under the same base host (and shared a token) I wasn't initially successful when I tried using https://gitlab.host.a to https://gitlab.host.b. The error shown was that the project couldn't be found.

I finally figured out how to build and use a local version of the code (I am a complete 'go' novice) so I could add print statements to see why and found that the Migration had the DstClient token and baseURL stored in the SrcClient.
It seeems the new refactoring of the GitLaber in to gitlab/client.go causes the fromgl to get overwritten by the togl values in migration/issues.go when creating. a new migration.
In gitlab/client.go the init() sets the DefaultClient

DefaultClient = new(Client). 

In migrations/issue.go:

fromgl := gitlab.DefaultClientFrom.New(nil, c.SrcPrj.Token)
...
togl := gitlab.DefaultClientTo.New(nil, c.DstPrj.Token)   

The setting of togl changes the ptr-value of DefaultClient & fromgl as well

Again, I'm new to Go so I may be missing something obvious, however here's what the print output shows. (names modified to be generic and tokens redacted)
show-failure-config.yml:

from:
    url: https://git.from.co
    project: group_name/myproject
    token: from-token-string
to:
    url: https://gitlab.to.com
    token: to-token-string
    project: group_to/subgroup/otherproject

And the output:

~/go/src/github.com/gotsunami/gitlab-copy/bin/gitlab-copy show-failure-config.yml
DUMMY MODE: won't apply anything (stats only)
--
Creating a new Migration...
DefaultClient address: &{<nil>}
setting fromgl from 'gitlab.DefaultCient.New'
fromgl address: &{0xc4200d01e0}
DefaultClient address: &{0xc4200d01e0}
setting togl from 'gitlab.DefaultCient.New'
togl address: &{0xc4200d03c0}
DefaultClient address: &{0xc4200d03c0}
fromgl address: &{0xc4200d03c0}
====
fromgl.BaseURL is: https://gitlab.to.com/api/v4/
togl.BaseURL is: https://gitlab.to.com/api/v4/

2021/07/29 19:41:23 source project 'group_name/myproject' not found

For my immediate needs I worked around the issue by creating two additional DefaultClient vars: DefaultClientTo and DefaultClientFrom and initializing them in init() and using them to set the fromgl and togl to become the Src and Dst in EndPoint. However I think the right fix is more in line with creating a new GitLaber client for each item. I wasn't sure why the package var DefaultClient was involved.

As a final note, even after I got it working with my hack, I wasn't able to copy attachments to notes. I saw this had been reported as fixed with #15 but it wasn't working for me. I figured I'd be happy with what I got.

Well, I had similar issue, like @alexandraohlson.
Here quick fix:

client.go - here add func

func CreateNew() GitLaber {
	return new(Client)
}

issue.go - here replace all gitlab.DefaultClient to gitlab.CreateNew()

gitlab.CreateNew().New(nil, c.SrcPrj.Token)

also replace p, err := m.project(m.Endpoint.SrcClient, name, "target") to p, err := m.project(m.Endpoint.DstClient, name, "target")

also at yml file must be id of src and target project, NOT path.

from:
    url: https://gitlab.mydomain.com
    token: atoken
    project: namespace/project
to:
    url: https://gitlab.myotherdomain.com
    token: anothertoken
    project: namespace/project

is not valid

from:
    url: https://gitlab.mydomain.com
    token: atoken
    project: 5
to:
    url: https://gitlab.myotherdomain.com
    token: anothertoken
    project: 8

is valid

maybe @matm update description of repo?

Fixed allmost issues in fork https://github.com/Zubastic/gitlab-copy

@Zubastic could you please create an updated build for your forked repo? Due to Gitlab Api v3 depreciated there are bunch of errors when compiling your fork.
Thank you

matm commented

Fixed by #55