added token to post-commit hooks

This commit is contained in:
Brad Rydzewski
2014-10-22 00:13:47 -07:00
parent dfb0210cf5
commit 7009778176
11 changed files with 172 additions and 13 deletions

View File

@@ -26,7 +26,7 @@ type Commit struct {
// SetAuthor sets the author's email address and calculate the Gravatar hash.
func (c *Commit) SetAuthor(email string) {
c.Author = email
c.Gravatar = createGravatar(email)
c.Gravatar = CreateGravatar(email)
}
// Returns the Short (--short) Commit Hash.

View File

@@ -18,6 +18,7 @@ type RepoParams map[string]string
type Repo struct {
ID int64 `meddler:"repo_id,pk" json:"-"`
UserID int64 `meddler:"user_id" json:"-"`
Token string `meddler:"repo_token" json:"-"`
Remote string `meddler:"repo_remote" json:"remote"`
Host string `meddler:"repo_host" json:"host"`
Owner string `meddler:"repo_owner" json:"owner"`

View File

@@ -24,7 +24,7 @@ type User struct {
func NewUser(remote, login, email string) *User {
user := User{}
user.Token = generateToken()
user.Token = GenerateToken()
user.Login = login
user.Remote = remote
user.Active = true
@@ -35,7 +35,7 @@ func NewUser(remote, login, email string) *User {
// SetEmail sets the email address and calculate the Gravatar hash.
func (u *User) SetEmail(email string) {
u.Email = email
u.Gravatar = createGravatar(email)
u.Gravatar = CreateGravatar(email)
}
func (u *User) IsStale() bool {

View File

@@ -14,9 +14,9 @@ var chars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567
// default token length
var length = 40
// generateToken generates random strings good for use in URIs to
// GenerateToken generates random strings good for use in URIs to
// identify unique objects.
func generateToken() string {
func GenerateToken() string {
b := make([]byte, length)
r := make([]byte, length+(length/4)) // storage for random bytes.
clen := byte(len(chars))
@@ -40,7 +40,7 @@ func generateToken() string {
// helper function to create a Gravatar Hash
// for the given Email address.
func createGravatar(email string) string {
func CreateGravatar(email string) string {
email = strings.ToLower(strings.TrimSpace(email))
hash := md5.New()
hash.Write([]byte(email))

View File

@@ -4,15 +4,15 @@ import (
"testing"
)
func Test_createGravatar(t *testing.T) {
var got, want = createGravatar("dr_cooper@caltech.edu"), "2b77ba83e2216ddcd11fe8c24b70c2a3"
func Test_CreateGravatar(t *testing.T) {
var got, want = CreateGravatar("dr_cooper@caltech.edu"), "2b77ba83e2216ddcd11fe8c24b70c2a3"
if got != want {
t.Errorf("Got gravatar hash %s, want %s", got, want)
}
}
func Test_generateToken(t *testing.T) {
token := generateToken()
func Test_GenerateToken(t *testing.T) {
token := GenerateToken()
if len(token) != length {
t.Errorf("Want token length %d, got %d", length, len(token))
}