diff --git a/cmd/app/client.go b/cmd/app/client.go index d2caea93..c68bedad 100644 --- a/cmd/app/client.go +++ b/cmd/app/client.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net/http" + "net/url" "github.com/harrisoncramer/gitlab.nvim/cmd/app/git" "github.com/hashicorp/go-retryablehttp" @@ -66,6 +67,14 @@ func NewClient() (*Client, error) { }, } + if proxy := pluginOptions.ConnectionSettings.Proxy; proxy != "" { + u, err := url.Parse(proxy) + if err != nil { + return nil, fmt.Errorf("parse proxy url: %w", err) + } + tr.Proxy = http.ProxyURL(u) + } + retryClient := retryablehttp.NewClient() retryClient.HTTPClient.Transport = tr gitlabOptions = append(gitlabOptions, gitlab.WithHTTPClient(retryClient.HTTPClient)) @@ -99,11 +108,11 @@ func InitProjectSettings(c *Client, gitInfo git.GitData) (*ProjectInfo, error) { project, _, err := c.GetProject(gitInfo.ProjectPath(), &opt) if err != nil { - return nil, fmt.Errorf(fmt.Sprintf("Error getting project at %s", gitInfo.RemoteUrl), err) + return nil, fmt.Errorf("error getting project at %s: %w", gitInfo.RemoteUrl, err) } if project == nil { - return nil, fmt.Errorf(fmt.Sprintf("Could not find project at %s", gitInfo.RemoteUrl), err) + return nil, fmt.Errorf("could not find project at %s", gitInfo.RemoteUrl) } projectId := fmt.Sprint(project.ID) diff --git a/cmd/app/config.go b/cmd/app/config.go index dc40dfe2..9d8bd0ac 100644 --- a/cmd/app/config.go +++ b/cmd/app/config.go @@ -13,6 +13,7 @@ type PluginOptions struct { } `json:"debug"` ChosenMrIID int `json:"chosen_mr_iid"` ConnectionSettings struct { + Proxy string `json:"proxy"` Insecure bool `json:"insecure"` Remote string `json:"remote"` } `json:"connection_settings"` diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt index e1c38bcc..19c6c707 100644 --- a/doc/gitlab.nvim.txt +++ b/doc/gitlab.nvim.txt @@ -161,6 +161,7 @@ you call this function with no values the defaults will be used: }, }, connection_settings = { + proxy = "", -- Configure a proxy URL to use when connecting to GitLab. Supports URL schemes: http, https, socks5 insecure = false, -- Like curl's --insecure option, ignore bad x509 certificates on connection remote = "origin", -- The default remote that your MRs target }, diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index 52627184..8ecec83c 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -62,6 +62,7 @@ M.settings = { }, }, connection_settings = { + proxy = "", insecure = false, remote = "origin", },