From 7ea202451236ed0db9c81a33cb7b0e4e866b0423 Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 17 Dec 2018 20:52:55 -0500 Subject: [PATCH] Fix in bugs --- gitlab.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gitlab.go b/gitlab.go index 7c06436..e7833e4 100644 --- a/gitlab.go +++ b/gitlab.go @@ -9,6 +9,7 @@ import ( "net/url" "os" "path/filepath" + "strings" "golang.org/x/oauth2" @@ -60,8 +61,9 @@ func NewGitLabClient(source Source) (*gitlabClient, error) { } return &gitlabClient{ - client: client, - repository: source.Repository, + client: client, + repository: source.Repository, + accessToken: source.AccessToken, }, nil } @@ -236,13 +238,22 @@ func (g *gitlabClient) DownloadProjectFile(filePath, destPath string) error { } defer out.Close() + // e.g. (group/project) + (/uploads/hash/filename) filePathRef, err := url.Parse(g.repository + filePath) if err != nil { return err } + // e.g. (https://gitlab-instance/api/v4) + (/group/project/uploads/hash/filename) projectFileUrl := g.client.BaseURL().ResolveReference(filePathRef) + // https://gitlab.com/gitlab-org/gitlab-ce/issues/51447 + nonApiUrl := strings.Replace(projectFileUrl.String(), "/api/v4", "", 1) + projectFileUrl, err = url.Parse(nonApiUrl) + if err != nil { + return err + } + client := &http.Client{} req, err := http.NewRequest("GET", projectFileUrl.String(), nil) if err != nil {