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 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 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")) _, err := mg.AddColumn("users", mg.T.String("gitlab_token"))
return err return err
} }

View file

@ -13,21 +13,24 @@ const userTable = "users"
// SQL Queries to retrieve a user by their unique database key // SQL Queries to retrieve a user by their unique database key
const userFindIdStmt = ` const userFindIdStmt = `
SELECT id, email, password, token, name, gravatar, created, updated, admin, 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 = ? FROM users WHERE id = ?
` `
// SQL Queries to retrieve a user by their email address // SQL Queries to retrieve a user by their email address
const userFindEmailStmt = ` const userFindEmailStmt = `
SELECT id, email, password, token, name, gravatar, created, updated, admin, 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 = ? FROM users WHERE email = ?
` `
// SQL Queries to retrieve a list of all users // SQL Queries to retrieve a list of all users
const userStmt = ` const userStmt = `
SELECT id, email, password, token, name, gravatar, created, updated, admin, 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 FROM users
ORDER BY name ASC ORDER BY name ASC
` `

View file

@ -3,6 +3,7 @@ package handler
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"net/url"
"strconv" "strconv"
"time" "time"
@ -170,6 +171,14 @@ func AdminSettingsUpdate(w http.ResponseWriter, r *http.Request, u *User) error
settings.GitHubDomain = r.FormValue("GitHubDomain") settings.GitHubDomain = r.FormValue("GitHubDomain")
settings.GitHubApiUrl = r.FormValue("GitHubApiUrl") 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 // update smtp settings
settings.SmtpServer = r.FormValue("SmtpServer") settings.SmtpServer = r.FormValue("SmtpServer")
settings.SmtpPort = r.FormValue("SmtpPort") settings.SmtpPort = r.FormValue("SmtpPort")
@ -252,6 +261,8 @@ func InstallPost(w http.ResponseWriter, r *http.Request) error {
settings.Scheme = r.FormValue("Scheme") settings.Scheme = r.FormValue("Scheme")
settings.GitHubApiUrl = "https://api.github.com" settings.GitHubApiUrl = "https://api.github.com"
settings.GitHubDomain = "github.com" settings.GitHubDomain = "github.com"
settings.GitlabApiUrl = "https://gitlab.com"
settings.GitlabDomain = "gitlab.com"
database.SaveSettings(&settings) database.SaveSettings(&settings)
// add the user to the session object // 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/database"
. "github.com/drone/drone/pkg/model" . "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/bitbucket"
"github.com/drone/go-bitbucket/oauth1" "github.com/drone/go-bitbucket/oauth1"
"github.com/drone/go-github/github"
"github.com/drone/go-github/oauth2"
) )
// Create the User session. // 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 { func (g *GitlabHandler) Link(w http.ResponseWriter, r *http.Request, u *User) error {
var err error token := r.FormValue("token")
return err 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 { 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. // ns namespaces user and repo.
// Returns user%2Frepo // Returns user%2Frepo
func ns(user, repo string) string { 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/database"
. "github.com/drone/drone/pkg/model" . "github.com/drone/drone/pkg/model"
"github.com/drone/drone/pkg/queue" "github.com/drone/drone/pkg/queue"
"github.com/drone/go-github/github"
"github.com/drone/go-bitbucket/bitbucket" "github.com/drone/go-bitbucket/bitbucket"
"github.com/drone/go-github/github"
) )
type HookHandler struct { type HookHandler struct {

View file

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

View file

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

View file

@ -50,6 +50,13 @@
<input class="form-control form-control-large" type="text" name="GitHubApiUrl" value="{{.Settings.GitHubApiUrl}}" /> <input class="form-control form-control-large" type="text" name="GitHubApiUrl" value="{{.Settings.GitHubApiUrl}}" />
</div> </div>
</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="form-group">
<div class="alert">Bitbucket OAuth Consumer Key and Secret.</div> <div class="alert">Bitbucket OAuth Consumer Key and Secret.</div>
<label>Bitbucket Key and Secret:</label> <label>Bitbucket Key and Secret:</label>

View file

@ -16,6 +16,7 @@
<ul class="nav nav-pills nav-stacked"> <ul class="nav nav-pills nav-stacked">
<li><a href="/new/github.com">GitHub</a></li> <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> </ul>
</div><!-- ./col-xs-3 --> </div><!-- ./col-xs-3 -->

View file

@ -16,6 +16,7 @@
<ul class="nav nav-pills nav-stacked"> <ul class="nav nav-pills nav-stacked">
<li><a href="/new/github.com">GitHub</a></li> <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> </ul>
</div><!-- ./col-xs-3 --> </div><!-- ./col-xs-3 -->

View file

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

View file

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

View file

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

View file

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