Skip to content

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

Merged
merged 3 commits into from
Jun 4, 2018
Merged

Add GitLab support #10

merged 3 commits into from
Jun 4, 2018

Conversation

biilmann
Copy link
Member

For now based on non-expiring access token.

Also adds a settings endpoint to detect if GitHub or GitLab is enabled.

For now based on non-expiring access token
Also adds a settings endpoint to detect if GitHub or GitLab is enabled
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 == "" {
Copy link
Member

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 {
Copy link
Member

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())
Copy link
Member

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)
Copy link
Member

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")
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Hub/Lab/

@tech4him1
Copy link

Closes #9

@agonopol
Copy link

Is there any work left to be done on this before it can be merged into master?

@biilmann biilmann merged commit 73c75b2 into master Jun 4, 2018
@biilmann biilmann deleted the gitlab-support branch June 4, 2018 23:07
@tech4him1 tech4him1 mentioned this pull request Mar 11, 2019
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

Successfully merging this pull request may close these issues.

4 participants