Add gitlab options add admin page.

This commit is contained in:
Nurahmadie 2014-03-29 11:51:02 +00:00
parent ea4917e278
commit 15770e6237
15 changed files with 66 additions and 28 deletions

View file

@ -17,9 +17,14 @@ func (r *rev20140328201430) Up(mg *MigrationDriver) error {
return err
}
if _, err := mg.Tx.Exec(`update settings set gitlab_domain='gitlab.com', gitlab_apiurl='https://gitlab.com'`); err != nil {
if _, err := mg.Tx.Exec(`update settings set gitlab_domain=?`, "gitlab.com"); err != nil {
return err
}
if _, err := mg.Tx.Exec(`update settings set gitlab_apiurl=?`, "https://gitlab.com"); err != nil {
return err
}
_, err := mg.AddColumn("users", mg.T.String("gitlab_token"))
return err
}
@ -29,6 +34,6 @@ func (r *rev20140328201430) Down(mg *MigrationDriver) error {
if _, err := mg.DropColumns("users", "gitlab_token"); err != nil {
return err
}
_, err:= mg.DropColumns("settings", "gitlab_domain", "gitlab_apiurl")
_, err := mg.DropColumns("settings", "gitlab_domain", "gitlab_apiurl")
return err
}

View file

@ -13,21 +13,24 @@ const userTable = "users"
// SQL Queries to retrieve a user by their unique database key
const userFindIdStmt = `
SELECT id, email, password, token, name, gravatar, created, updated, admin,
github_login, github_token, bitbucket_login, bitbucket_token, bitbucket_secret
github_login, github_token, bitbucket_login, bitbucket_token, bitbucket_secret,
gitlab_token
FROM users WHERE id = ?
`
// SQL Queries to retrieve a user by their email address
const userFindEmailStmt = `
SELECT id, email, password, token, name, gravatar, created, updated, admin,
github_login, github_token, bitbucket_login, bitbucket_token, bitbucket_secret
github_login, github_token, bitbucket_login, bitbucket_token, bitbucket_secret,
gitlab_token
FROM users WHERE email = ?
`
// SQL Queries to retrieve a list of all users
const userStmt = `
SELECT id, email, password, token, name, gravatar, created, updated, admin,
github_login, github_token, bitbucket_login, bitbucket_token, bitbucket_secret
github_login, github_token, bitbucket_login, bitbucket_token, bitbucket_secret,
gitlab_token
FROM users
ORDER BY name ASC
`

View file

@ -3,6 +3,7 @@ package handler
import (
"fmt"
"net/http"
"net/url"
"strconv"
"time"
@ -170,6 +171,14 @@ func AdminSettingsUpdate(w http.ResponseWriter, r *http.Request, u *User) error
settings.GitHubDomain = r.FormValue("GitHubDomain")
settings.GitHubApiUrl = r.FormValue("GitHubApiUrl")
// update gitlab settings
settings.GitlabApiUrl = r.FormValue("GitlabApiUrl")
glUrl, err := url.Parse(settings.GitlabApiUrl)
if err != nil {
return RenderError(w, err, http.StatusBadRequest)
}
settings.GitlabDomain = glUrl.Host
// update smtp settings
settings.SmtpServer = r.FormValue("SmtpServer")
settings.SmtpPort = r.FormValue("SmtpPort")
@ -252,6 +261,8 @@ func InstallPost(w http.ResponseWriter, r *http.Request) error {
settings.Scheme = r.FormValue("Scheme")
settings.GitHubApiUrl = "https://api.github.com"
settings.GitHubDomain = "github.com"
settings.GitlabApiUrl = "https://gitlab.com"
settings.GitlabDomain = "gitlab.com"
database.SaveSettings(&settings)
// add the user to the session object

View file

@ -6,10 +6,10 @@ import (
"github.com/drone/drone/pkg/database"
. "github.com/drone/drone/pkg/model"
"github.com/drone/go-github/github"
"github.com/drone/go-github/oauth2"
"github.com/drone/go-bitbucket/bitbucket"
"github.com/drone/go-bitbucket/oauth1"
"github.com/drone/go-github/github"
"github.com/drone/go-github/oauth2"
)
// Create the User session.

View file

@ -44,8 +44,22 @@ func (g *GitlabHandler) Add(w http.ResponseWriter, r *http.Request, u *User) err
}
func (g *GitlabHandler) Link(w http.ResponseWriter, r *http.Request, u *User) error {
var err error
return err
token := r.FormValue("token")
u.GitlabToken = token
if err := database.SaveUser(u); err != nil {
return RenderError(w, err, http.StatusBadRequest)
}
settings := database.SettingsMust()
gl := gogitlab.NewGitlab(settings.GitlabApiUrl, g.apiPath, u.GitlabToken)
_, err := gl.CurrentUser()
if err != nil {
return fmt.Errorf("Private Token is not valid: %q", err)
}
http.Redirect(w, r, "/new/gitlab", http.StatusSeeOther)
return nil
}
func (g *GitlabHandler) Create(w http.ResponseWriter, r *http.Request, u *User) error {
@ -125,5 +139,5 @@ func (g *GitlabHandler) newGitlabRepo(u *User, owner, name string) (*Repo, error
// ns namespaces user and repo.
// Returns user%2Frepo
func ns(user, repo string) string {
return fmt.Sprintf("%s%%252F%s", user, repo)
return fmt.Sprintf("%s%%2F%s", user, repo)
}

View file

@ -10,8 +10,8 @@ import (
"github.com/drone/drone/pkg/database"
. "github.com/drone/drone/pkg/model"
"github.com/drone/drone/pkg/queue"
"github.com/drone/go-github/github"
"github.com/drone/go-bitbucket/bitbucket"
"github.com/drone/go-github/github"
)
type HookHandler struct {

View file

@ -7,8 +7,8 @@ import (
"github.com/drone/drone/pkg/channel"
"github.com/drone/drone/pkg/database"
. "github.com/drone/drone/pkg/model"
"github.com/drone/go-github/github"
"github.com/drone/go-bitbucket/bitbucket"
"github.com/drone/go-github/github"
"launchpad.net/goyaml"
)

View file

@ -10,8 +10,8 @@ import (
"github.com/drone/drone/pkg/database"
"github.com/drone/drone/pkg/handler"
"github.com/drone/drone/pkg/queue"
"github.com/drone/drone/pkg/model"
"github.com/drone/drone/pkg/queue"
dbtest "github.com/drone/drone/pkg/database/testing"
. "github.com/smartystreets/goconvey/convey"
@ -190,11 +190,9 @@ func Test_GitLabCreate(t *testing.T) {
// it is just proof-of-concepting a testing strategy, so we'll
// revisit later.
// server is a test HTTP server used to provide mock API responses.
var glServer *httptest.Server
func SetupGitlabFixtures() {
dbtest.Setup()

View file

@ -50,6 +50,13 @@
<input class="form-control form-control-large" type="text" name="GitHubApiUrl" value="{{.Settings.GitHubApiUrl}}" />
</div>
</div>
<div class="form-group">
<div class="alert">GitLab Settings</div>
<label>Base URL for GitLab: <small>(e.g. https://gitlab.com)</small></label>
<div>
<input class="form-control form-control-xlarge" type="text" name="GitlabApiUrl" value="{{.Settings.GitlabApiUrl}}" />
</div>
</div>
<div class="form-group">
<div class="alert">Bitbucket OAuth Consumer Key and Secret.</div>
<label>Bitbucket Key and Secret:</label>

View file

@ -15,7 +15,8 @@
<div class="col-xs-3">
<ul class="nav nav-pills nav-stacked">
<li><a href="/new/github.com">GitHub</a></li>
<li class="active"><a href="/new/bitbucket.org">Bitbucket</a></li>
<li class="active"><a href="/new/bitbucket.org">Bitbucket</a></li>
<li><a href="/new/gitlab">GitLab</a></li>
</ul>
</div><!-- ./col-xs-3 -->

View file

@ -15,7 +15,8 @@
<div class="col-xs-3">
<ul class="nav nav-pills nav-stacked">
<li><a href="/new/github.com">GitHub</a></li>
<li class="active"><a href="/new/bitbucket.org">Bitbucket</a></li>
<li class="active"><a href="/new/bitbucket.org">Bitbucket</a></li>
<li><a href="/new/gitlab">GitLab</a></li>
</ul>
</div><!-- ./col-xs-3 -->

View file

@ -15,8 +15,8 @@
<div class="col-xs-3">
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="/new/github.com">GitHub</a></li>
<li><a href="/new/gitlab">GitLab</a></li>
<li><a href="/new/bitbucket.org">Bitbucket</a></li>
<li><a href="/new/gitlab">GitLab</a></li>
</ul>
</div><!-- ./col-xs-3 -->

View file

@ -15,8 +15,8 @@
<div class="col-xs-3">
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="/new/github.com">GitHub</a></li>
<li><a href="/new/gitlab">GitLab</a></li>
<li><a href="/new/bitbucket.org">Bitbucket</a></li>
<li><a href="/new/gitlab">GitLab</a></li>
</ul>
</div><!-- ./col-xs-3 -->

View file

@ -1,11 +1,11 @@
{{ define "title" }}GitHub · Add Repository{{ end }}
{{ define "title" }}GitLab · Add Repository{{ end }}
{{ define "content" }}
<div class="subhead">
<div class="container">
<h1>
<span>Repository Setup</span>
<small>GitHub</small>
<small>GitLab</small>
</h1>
</div><!-- ./container -->
</div><!-- ./subhead -->
@ -15,8 +15,8 @@
<div class="col-xs-3">
<ul class="nav nav-pills nav-stacked">
<li><a href="/new/github.com">GitHub</a></li>
<li><a href="/new/bitbucket.org">Bitbucket</a></li>
<li class="active"><a href="/new/gitlab">GitLab</a></li>
<li><a href="/new/bitbucket.org">Bitbucket <small>(coming soon)</small></a></li>
</ul>
</div><!-- ./col-xs-3 -->
@ -25,11 +25,11 @@
Enter your repository details
<a class="btn btn-default pull-right" href="/auth/login/github" style="font-size: 18px;background:#f4f4f4;">Re-Link Account</a>
</div>
<form class="form-repo" method="POST" action="/new/github.com">
<input type="hidden" name="domain" autocomplete="off" value="{{.Settings.GitHubDomain}}">
<form class="form-repo" method="POST" action="/new/gitlab">
<input type="hidden" name="domain" autocomplete="off" value="{{.Settings.GitlabDomain}}">
<div class="field-group">
<div>
<label>GitHub Owner</label>
<label>GitLab Owner</label>
<div>
<input class="form-control form-control-large" type="text" name="owner" autocomplete="off">
</div>

View file

@ -15,8 +15,8 @@
<div class="col-xs-3">
<ul class="nav nav-pills nav-stacked">
<li><a href="/new/github.com">GitHub</a></li>
<li><a href="/new/bitbucket.org">Bitbucket</a></li>
<li class="active"><a href="/new/gitlab">GitLab</a></li>
<li><a href="/new/bitbucket.org">Bitbucket <small>(coming soon)</small></a></li>
</ul>
</div><!-- ./col-xs-3 -->
@ -28,8 +28,6 @@
<div><input class="form-control form-control-large" type="text" name="token" autocomplete="off"></div>
</div>
</div>
<div class="alert alert-success hide" id="successAlert"></div>
<div class="alert alert-error hide" id="failureAlert"></div>
<div class="form-actions">
<input class="btn btn-primary" id="submitButton" type="submit" value="Link" data-loading-text="Saving ..">
<a class="btn btn-default" href="/dashboard">Cancel</a>