-
Notifications
You must be signed in to change notification settings - Fork 91
Add GitLab support #10
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
Conversation
For now based on non-expiring access token Also adds a settings endpoint to detect if GitHub or GitLab is enabled
d3043ca
to
51e2bb1
Compare
r.URL.Scheme = target.Scheme | ||
r.URL.Host = target.Host | ||
r.URL.Path = singleJoiningSlash(target.Path, gitlabPathRegexp.ReplaceAllString(r.URL.Path, "/")) | ||
if targetQuery == "" || r.URL.RawQuery == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a little confusing - but totally fine.
if targetQuery == "" {
r.URL.RawQuery = r.URL.RawQuery
} else if r.URL.RawQuery == "" {
r.URL.RawQuery = targetQuery
} else {
r.URL.RawQuery = targetQuery + "&" + r.URL.RawQuery
}
} else { | ||
r.URL.RawQuery = targetQuery + "&" + r.URL.RawQuery | ||
} | ||
if _, ok := r.Header["User-Agent"]; !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're removing it if it is not set? I'm confused. Also, personally, I'd use the Get
and Del
methods.
if h := r.Header.Get("User-Agent"); h == "" {
r.Header.Del("User-Agent")
}
api/gitlab.go
Outdated
} | ||
|
||
log := getLogEntry(r) | ||
log.Infof("Proxying to GitHub: %v", r.URL.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Hub/Lab/
api/gitlab.go
Outdated
apiURL := singleJoiningSlash(endpoint, "/repos/"+config.GitLab.Repo) | ||
target, err := url.Parse(apiURL) | ||
if err != nil { | ||
handleError(internalServerError("Unable to process GitHub endpoint"), w, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Hub/Lab/
api/gitlab.go
Outdated
} | ||
|
||
if !gitlabAllowedRegexp.MatchString(r.URL.Path) { | ||
return errors.New("Access to endpoint not allowed: this part of GitHub's API has been restricted") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Hub/Lab/
func (t *GitLabTransport) RoundTrip(r *http.Request) (*http.Response, error) { | ||
resp, err := http.DefaultTransport.RoundTrip(r) | ||
if err == nil { | ||
// remove CORS headers from GitHub and use our own |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Hub/Lab/
Closes #9 |
Is there any work left to be done on this before it can be merged into master? |
For now based on non-expiring access token.
Also adds a settings endpoint to detect if GitHub or GitLab is enabled.