release/v0.9
Unknown 10 years ago
parent 237193ef2a
commit 8ef198dfac

@ -1,4 +1,4 @@
Gogs - Go Git Service Gogs - Go Git Service [![Go Walker](http://gowalker.org/api/v1/badge)](https://gowalker.org/github.com/gogits/gogs)
===================== =====================
Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language. Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language.
@ -7,6 +7,17 @@ Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language.
There are some very good products in this category such as [gitlab](http://gitlab.com), but the environment setup steps often make us crazy. So our goal of Gogs is to build a GitHub-like clone with very easy setup steps, which take advantages of the Go Programming Language. There are some very good products in this category such as [gitlab](http://gitlab.com), but the environment setup steps often make us crazy. So our goal of Gogs is to build a GitHub-like clone with very easy setup steps, which take advantages of the Go Programming Language.
## Overview
Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design.
## Installation
### Dependencies
- [Go Programming Language](http://golang.org): Main develop language.
- [libgit2](http://libgit2.github.com/): Git data manipulation.
## Acknowledgments ## Acknowledgments
- Logo inspired by [martini](https://github.com/martini-contrib). - Logo inspired by [martini](https://github.com/martini-contrib).

@ -11,10 +11,8 @@ import (
) )
var ( var (
// orm orm *xorm.Engine
orm *xorm.Engine repoRootPath string
// repository root path
root string
) )
type PublicKey struct { type PublicKey struct {

@ -1,3 +1,7 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package models package models
import ( import (

@ -1,3 +1,7 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package models package models
import ( import (
@ -33,7 +37,7 @@ func IsRepositoryExist(user *User, reposName string) (bool, error) {
// create a repository for a user or orgnaziation // create a repository for a user or orgnaziation
// //
func CreateRepository(user *User, reposName string) (*Repo, error) { func CreateRepository(user *User, reposName string) (*Repo, error) {
p := filepath.Join(root, user.Name) p := filepath.Join(repoRootPath, user.Name)
os.MkdirAll(p, os.ModePerm) os.MkdirAll(p, os.ModePerm)
f := filepath.Join(p, reposName) f := filepath.Join(p, reposName)
_, err := git.InitRepository(f, false) _, err := git.InitRepository(f, false)
@ -89,29 +93,22 @@ func UnWatchRepository() {
} }
// // DeleteRepository deletes a repository for a user or orgnaztion.
// delete a repository for a user or orgnaztion func DeleteRepository(user *User, reposName string) (err error) {
//
func DeleteRepository(user *User, reposName string) error {
session := orm.NewSession() session := orm.NewSession()
_, err := session.Delete(&Repo{OwnerId: user.Id, Name: reposName}) if _, err = session.Delete(&Repo{OwnerId: user.Id, Name: reposName}); err != nil {
if err != nil {
session.Rollback() session.Rollback()
return err return err
} }
_, err = session.Exec("update user set num_repos = num_repos - 1 where id = ?", user.Id) if _, err = session.Exec("update user set num_repos = num_repos - 1 where id = ?", user.Id); err != nil {
if err != nil {
session.Rollback() session.Rollback()
return err return err
} }
err = session.Commit() if err = session.Commit(); err != nil {
if err != nil {
session.Rollback() session.Rollback()
return err return err
} }
if err = os.RemoveAll(filepath.Join(repoRootPath, user.Name, reposName)); err != nil {
err = os.RemoveAll(filepath.Join(root, user.Name, reposName))
if err != nil {
// TODO: log and delete manully // TODO: log and delete manully
return err return err
} }

@ -1,3 +1,7 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package models package models
import ( import (
@ -7,18 +11,21 @@ import (
"time" "time"
"github.com/dchest/scrypt" "github.com/dchest/scrypt"
) // user type )
// User types.
const ( const (
Individual = iota + 1 UT_INDIVIDUAL = iota + 1
Organization UT_ORGANIZATION
) )
// login type // Login types.
const ( const (
Plain = iota + 1 LT_PLAIN = iota + 1
LDAP LT_LDAP
) )
// A User represents the object of individual and member of organization.
type User struct { type User struct {
Id int64 Id int64
LowerName string `xorm:"unique not null"` LowerName string `xorm:"unique not null"`
@ -36,6 +43,7 @@ type User struct {
Updated time.Time `xorm:"updated"` Updated time.Time `xorm:"updated"`
} }
// A Follow represents
type Follow struct { type Follow struct {
Id int64 Id int64
UserId int64 `xorm:"unique(s)"` UserId int64 `xorm:"unique(s)"`
@ -43,15 +51,17 @@ type Follow struct {
Created time.Time `xorm:"created"` Created time.Time `xorm:"created"`
} }
// Operation types of repository.
const ( const (
OpCreateRepo = iota + 1 OP_CREATE_REPO = iota + 1
OpDeleteRepo OP_DELETE_REPO
OpStarRepo OP_STAR_REPO
OpFollowRepo OP_FOLLOW_REPO
OpCommitRepo OP_COMMIT_REPO
OpPullRequest OP_PULL_REQUEST
) )
// A Action represents
type Action struct { type Action struct {
Id int64 Id int64
UserId int64 UserId int64
@ -62,34 +72,61 @@ type Action struct {
} }
var ( var (
ErrUserNotExist = errors.New("User not exist") ErrUserAlreadyExist = errors.New("User already exist")
ErrUserNotExist = errors.New("User does not exist")
) )
// user's name should be noncased unique // IsUserExist checks if given user name exist,
// the user name should be noncased unique.
func IsUserExist(name string) (bool, error) { func IsUserExist(name string) (bool, error) {
return orm.Get(&User{LowerName: strings.ToLower(name)}) return orm.Get(&User{LowerName: strings.ToLower(name)})
} }
func RegisterUser(user *User) error { // validateUser checks if user exist.
_, err := orm.Insert(user) func validateUser(name string) error {
isExist, err := IsUserExist(name)
if err != nil {
return err
} else if isExist {
return ErrUserAlreadyExist
}
return nil
}
// RegisterUser creates record of a new user.
func RegisterUser(user *User) (err error) {
if err = validateUser(user.Name); err != nil {
return err
}
_, err = orm.Insert(user)
return err return err
} }
func UpdateUser(user *User) error { // UpdateUser updates user's information.
_, err := orm.Id(user.Id).Update(user) func UpdateUser(user *User) (err error) {
_, err = orm.Id(user.Id).Update(user)
return err return err
} }
// DeleteUser completely deletes everything of the user.
func DeleteUser(user *User) error {
// TODO: check if has ownership of any repository.
_, err := orm.Delete(user)
// TODO: delete and update follower information.
return err
}
// EncodePasswd encodes password to safe format.
func (user *User) EncodePasswd(pass string) error { func (user *User) EncodePasswd(pass string) error {
newPasswd, err := scrypt.Key([]byte(user.Passwd), []byte("!#@FDEWREWR&*("), 16384, 8, 1, 64) newPasswd, err := scrypt.Key([]byte(user.Passwd), []byte("!#@FDEWREWR&*("), 16384, 8, 1, 64)
user.Passwd = fmt.Sprintf("%x", newPasswd) user.Passwd = fmt.Sprintf("%x", newPasswd)
return err return err
} }
// LoginUserPlain validates user by raw user name and password.
func LoginUserPlain(name, passwd string) (*User, error) { func LoginUserPlain(name, passwd string) (*User, error) {
user := User{Name: name} user := User{Name: name}
err := user.EncodePasswd(passwd) if err := user.EncodePasswd(passwd); err != nil {
if err != nil {
return nil, err return nil, err
} }
@ -103,6 +140,7 @@ func LoginUserPlain(name, passwd string) (*User, error) {
return &user, nil return &user, nil
} }
// FollowUser marks someone be another's follower.
func FollowUser(userId int64, followId int64) error { func FollowUser(userId int64, followId int64) error {
session := orm.NewSession() session := orm.NewSession()
defer session.Close() defer session.Close()
@ -125,6 +163,7 @@ func FollowUser(userId int64, followId int64) error {
return session.Commit() return session.Commit()
} }
// UnFollowUser unmarks someone be another's follower.
func UnFollowUser(userId int64, unFollowId int64) error { func UnFollowUser(userId int64, unFollowId int64) error {
session := orm.NewSession() session := orm.NewSession()
defer session.Close() defer session.Close()

Loading…
Cancel
Save