Running gofmt on remote for bitbucket server

This commit is contained in:
Joachim Hill-Grannec 2016-04-20 11:59:47 -07:00
parent 262f505779
commit 95b1f347ba
4 changed files with 189 additions and 219 deletions

View file

@ -11,18 +11,16 @@ package bitbucketserver
// Needs a pem private key added to /var/lib/bitbucketserver/private_key.pem // Needs a pem private key added to /var/lib/bitbucketserver/private_key.pem
// After that you should be good to go // After that you should be good to go
import ( import (
"net/url"
log "github.com/Sirupsen/logrus"
"net/http"
"github.com/drone/drone/model"
"fmt"
"io/ioutil"
"strconv"
"encoding/json" "encoding/json"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/drone/drone/model"
"github.com/mrjones/oauth" "github.com/mrjones/oauth"
"io/ioutil"
"net/http"
"net/url"
"strconv"
) )
type BitbucketServer struct { type BitbucketServer struct {
@ -68,16 +66,12 @@ func Load(config string) *BitbucketServer{
bitbucketserver.Consumer = *NewClient(bitbucketserver.ConsumerRSA, bitbucketserver.ConsumerKey, bitbucketserver.URL) bitbucketserver.Consumer = *NewClient(bitbucketserver.ConsumerRSA, bitbucketserver.ConsumerKey, bitbucketserver.URL)
return &bitbucketserver return &bitbucketserver
} }
func (bs *BitbucketServer) Login(res http.ResponseWriter, req *http.Request) (*model.User, bool, error) { func (bs *BitbucketServer) Login(res http.ResponseWriter, req *http.Request) (*model.User, bool, error) {
log.Info("Starting to login for bitbucketServer") log.Info("Starting to login for bitbucketServer")
log.Info("getting the requestToken") log.Info("getting the requestToken")
requestToken, url, err := bs.Consumer.GetRequestTokenAndUrl("oob") requestToken, url, err := bs.Consumer.GetRequestTokenAndUrl("oob")
if err != nil { if err != nil {
@ -124,7 +118,6 @@ func (bs *BitbucketServer) Login(res http.ResponseWriter, req *http.Request) (*m
user.Avatar = avatarLink(mUser.EmailAddress) user.Avatar = avatarLink(mUser.EmailAddress)
return &user, bs.Open, nil return &user, bs.Open, nil
} }
@ -133,7 +126,7 @@ func (bs *BitbucketServer) Auth(token, secret string) (string, error) {
if len(token) == 0 { if len(token) == 0 {
return "", fmt.Errorf("Hasn't logged in yet") return "", fmt.Errorf("Hasn't logged in yet")
} }
return token, nil; return token, nil
} }
func (bs *BitbucketServer) Repo(u *model.User, owner, name string) (*model.Repo, error) { func (bs *BitbucketServer) Repo(u *model.User, owner, name string) (*model.Repo, error) {
@ -176,11 +169,9 @@ func (bs *BitbucketServer) Repo(u *model.User, owner, name string) (*model.Repo,
repo.Branch = "master" repo.Branch = "master"
repo.Kind = model.RepoGit repo.Kind = model.RepoGit
return repo, nil
return repo, nil;
} }
func (bs *BitbucketServer) Repos(u *model.User) ([]*model.RepoLite, error) { func (bs *BitbucketServer) Repos(u *model.User) ([]*model.RepoLite, error) {
log.Info("Staring repos for bitbucketServer " + u.Login) log.Info("Staring repos for bitbucketServer " + u.Login)
var repos = []*model.RepoLite{} var repos = []*model.RepoLite{}
@ -204,8 +195,7 @@ func (bs *BitbucketServer) Repos(u *model.User) ([]*model.RepoLite, error){
}) })
} }
return repos, nil
return repos, nil;
} }
func (bs *BitbucketServer) Perm(u *model.User, owner, repo string) (*model.Perm, error) { func (bs *BitbucketServer) Perm(u *model.User, owner, repo string) (*model.Perm, error) {
@ -238,13 +228,12 @@ func (bs *BitbucketServer) File(u *model.User, r *model.Repo, b *model.Build, f
log.Error(err) log.Error(err)
} }
return responseBytes, nil
return responseBytes, nil;
} }
func (bs *BitbucketServer) Status(u *model.User, r *model.Repo, b *model.Build, link string) error { func (bs *BitbucketServer) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
log.Info("Staring status for bitbucketServer") log.Info("Staring status for bitbucketServer")
return nil; return nil
} }
func (bs *BitbucketServer) Netrc(user *model.User, r *model.Repo) (*model.Netrc, error) { func (bs *BitbucketServer) Netrc(user *model.User, r *model.Repo) (*model.Netrc, error) {
@ -268,7 +257,7 @@ func (bs *BitbucketServer) Activate(u *model.User, r *model.Repo, k *model.Key,
return err return err
} }
log.Info(hook) log.Info(hook)
return nil; return nil
} }
func (bs *BitbucketServer) Deactivate(u *model.User, r *model.Repo, link string) error { func (bs *BitbucketServer) Deactivate(u *model.User, r *model.Repo, link string) error {
@ -278,7 +267,7 @@ func (bs *BitbucketServer) Deactivate(u *model.User, r *model.Repo, link string)
if err != nil { if err != nil {
return err return err
} }
return nil; return nil
} }
func (bs *BitbucketServer) Hook(r *http.Request) (*model.Repo, *model.Build, error) { func (bs *BitbucketServer) Hook(r *http.Request) (*model.Repo, *model.Build, error) {
@ -292,8 +281,6 @@ func (bs *BitbucketServer) Hook(r *http.Request) (*model.Repo, *model.Build, err
var hookPost postHook var hookPost postHook
json.Unmarshal(contents, &hookPost) json.Unmarshal(contents, &hookPost)
buildModel := &model.Build{} buildModel := &model.Build{}
buildModel.Event = model.EventPush buildModel.Event = model.EventPush
buildModel.Ref = hookPost.RefChanges[0].RefID buildModel.Ref = hookPost.RefChanges[0].RefID
@ -313,14 +300,12 @@ func (bs *BitbucketServer) Hook(r *http.Request) (*model.Repo, *model.Build, err
repo.Branch = "master" repo.Branch = "master"
repo.Kind = model.RepoGit repo.Kind = model.RepoGit
return repo, buildModel, nil; return repo, buildModel, nil
} }
func (bs *BitbucketServer) String() string { func (bs *BitbucketServer) String() string {
return "bitbucketserver" return "bitbucketserver"
} }
type HookDetail struct { type HookDetail struct {
Key string `"json:key"` Key string `"json:key"`
Name string `"json:name"` Name string `"json:name"`
@ -335,8 +320,6 @@ type Hook struct {
Details *HookDetail `"json:details"` Details *HookDetail `"json:details"`
} }
// Enable hook for named repository // Enable hook for named repository
func (bs *BitbucketServer) CreateHook(client *http.Client, project, slug, hook_key, link string) (*Hook, error) { func (bs *BitbucketServer) CreateHook(client *http.Client, project, slug, hook_key, link string) (*Hook, error) {
@ -360,8 +343,3 @@ func (bs *BitbucketServer)DeleteHook(client *http.Client, project, slug, hook_ke
return nil return nil
} }

View file

@ -1,16 +1,15 @@
package bitbucketserver package bitbucketserver
import ( import (
"net/http"
"crypto/tls" "crypto/tls"
log "github.com/Sirupsen/logrus"
"io/ioutil"
"encoding/pem"
"crypto/x509" "crypto/x509"
"encoding/pem"
log "github.com/Sirupsen/logrus"
"github.com/mrjones/oauth" "github.com/mrjones/oauth"
"io/ioutil"
"net/http"
) )
func NewClient(ConsumerRSA string, ConsumerKey string, URL string) *oauth.Consumer { func NewClient(ConsumerRSA string, ConsumerKey string, URL string) *oauth.Consumer {
//TODO: make this configurable //TODO: make this configurable
privateKeyFileContents, err := ioutil.ReadFile(ConsumerRSA) privateKeyFileContents, err := ioutil.ReadFile(ConsumerRSA)
@ -51,9 +50,3 @@ func NewClientWithToken(Consumer *oauth.Consumer, AccessToken string) *http.Clie
} }
return client return client
} }

View file

@ -1,14 +1,14 @@
package bitbucketserver package bitbucketserver
import ( import (
"net/http"
"bytes" "bytes"
"io/ioutil"
"fmt"
"strings"
"crypto/md5" "crypto/md5"
log "github.com/Sirupsen/logrus"
"encoding/hex" "encoding/hex"
"fmt"
log "github.com/Sirupsen/logrus"
"io/ioutil"
"net/http"
"strings"
) )
func avatarLink(email string) (url string) { func avatarLink(email string) (url string) {

View file

@ -1,6 +1,5 @@
package bitbucketserver package bitbucketserver
type postHook struct { type postHook struct {
Changesets struct { Changesets struct {
Filter interface{} `json:"filter"` Filter interface{} `json:"filter"`