mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Formatting
This commit is contained in:
		
							
								
								
									
										13
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | ||||
| Gogs - Go Git Service | ||||
| Gogs - Go Git Service [](https://gowalker.org/github.com/gogits/gogs) | ||||
| ===================== | ||||
|  | ||||
| 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. | ||||
|  | ||||
| ## 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 | ||||
|  | ||||
| - Logo inspired by [martini](https://github.com/martini-contrib). | ||||
|   | ||||
| @@ -11,10 +11,8 @@ import ( | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	// orm | ||||
| 	orm *xorm.Engine | ||||
| 	// repository root path | ||||
| 	root string | ||||
| 	orm          *xorm.Engine | ||||
| 	repoRootPath string | ||||
| ) | ||||
|  | ||||
| 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 | ||||
|  | ||||
| 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 | ||||
|  | ||||
| import ( | ||||
| @@ -33,7 +37,7 @@ func IsRepositoryExist(user *User, reposName string) (bool, error) { | ||||
| // create a repository for a user or orgnaziation | ||||
| // | ||||
| 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) | ||||
| 	f := filepath.Join(p, reposName) | ||||
| 	_, err := git.InitRepository(f, false) | ||||
| @@ -89,29 +93,22 @@ func UnWatchRepository() { | ||||
|  | ||||
| } | ||||
|  | ||||
| // | ||||
| // delete a repository for a user or orgnaztion | ||||
| // | ||||
| func DeleteRepository(user *User, reposName string) error { | ||||
| // DeleteRepository deletes a repository for a user or orgnaztion. | ||||
| func DeleteRepository(user *User, reposName string) (err error) { | ||||
| 	session := orm.NewSession() | ||||
| 	_, err := session.Delete(&Repo{OwnerId: user.Id, Name: reposName}) | ||||
| 	if err != nil { | ||||
| 	if _, err = session.Delete(&Repo{OwnerId: user.Id, Name: reposName}); err != nil { | ||||
| 		session.Rollback() | ||||
| 		return err | ||||
| 	} | ||||
| 	_, err = session.Exec("update user set num_repos = num_repos - 1 where id = ?", user.Id) | ||||
| 	if err != nil { | ||||
| 	if _, err = session.Exec("update user set num_repos = num_repos - 1 where id = ?", user.Id); err != nil { | ||||
| 		session.Rollback() | ||||
| 		return err | ||||
| 	} | ||||
| 	err = session.Commit() | ||||
| 	if err != nil { | ||||
| 	if err = session.Commit(); err != nil { | ||||
| 		session.Rollback() | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	err = os.RemoveAll(filepath.Join(root, user.Name, reposName)) | ||||
| 	if err != nil { | ||||
| 	if err = os.RemoveAll(filepath.Join(repoRootPath, user.Name, reposName)); err != nil { | ||||
| 		// TODO: log and delete manully | ||||
| 		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 | ||||
|  | ||||
| import ( | ||||
| @@ -7,18 +11,21 @@ import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/dchest/scrypt" | ||||
| ) // user type | ||||
| const ( | ||||
| 	Individual = iota + 1 | ||||
| 	Organization | ||||
| ) | ||||
|  | ||||
| // login type | ||||
| // User types. | ||||
| const ( | ||||
| 	Plain = iota + 1 | ||||
| 	LDAP | ||||
| 	UT_INDIVIDUAL = iota + 1 | ||||
| 	UT_ORGANIZATION | ||||
| ) | ||||
|  | ||||
| // Login types. | ||||
| const ( | ||||
| 	LT_PLAIN = iota + 1 | ||||
| 	LT_LDAP | ||||
| ) | ||||
|  | ||||
| // A User represents the object of individual and member of organization. | ||||
| type User struct { | ||||
| 	Id            int64 | ||||
| 	LowerName     string `xorm:"unique not null"` | ||||
| @@ -36,6 +43,7 @@ type User struct { | ||||
| 	Updated       time.Time `xorm:"updated"` | ||||
| } | ||||
|  | ||||
| // A Follow represents | ||||
| type Follow struct { | ||||
| 	Id       int64 | ||||
| 	UserId   int64     `xorm:"unique(s)"` | ||||
| @@ -43,15 +51,17 @@ type Follow struct { | ||||
| 	Created  time.Time `xorm:"created"` | ||||
| } | ||||
|  | ||||
| // Operation types of repository. | ||||
| const ( | ||||
| 	OpCreateRepo = iota + 1 | ||||
| 	OpDeleteRepo | ||||
| 	OpStarRepo | ||||
| 	OpFollowRepo | ||||
| 	OpCommitRepo | ||||
| 	OpPullRequest | ||||
| 	OP_CREATE_REPO = iota + 1 | ||||
| 	OP_DELETE_REPO | ||||
| 	OP_STAR_REPO | ||||
| 	OP_FOLLOW_REPO | ||||
| 	OP_COMMIT_REPO | ||||
| 	OP_PULL_REQUEST | ||||
| ) | ||||
|  | ||||
| // A Action represents | ||||
| type Action struct { | ||||
| 	Id      int64 | ||||
| 	UserId  int64 | ||||
| @@ -62,34 +72,61 @@ type Action struct { | ||||
| } | ||||
|  | ||||
| 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) { | ||||
| 	return orm.Get(&User{LowerName: strings.ToLower(name)}) | ||||
| } | ||||
|  | ||||
| func RegisterUser(user *User) error { | ||||
| 	_, err := orm.Insert(user) | ||||
| // validateUser checks if user exist. | ||||
| 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 | ||||
| } | ||||
|  | ||||
| func UpdateUser(user *User) error { | ||||
| 	_, err := orm.Id(user.Id).Update(user) | ||||
| // UpdateUser updates user's information. | ||||
| func UpdateUser(user *User) (err error) { | ||||
| 	_, err = orm.Id(user.Id).Update(user) | ||||
| 	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 { | ||||
| 	newPasswd, err := scrypt.Key([]byte(user.Passwd), []byte("!#@FDEWREWR&*("), 16384, 8, 1, 64) | ||||
| 	user.Passwd = fmt.Sprintf("%x", newPasswd) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| // LoginUserPlain validates user by raw user name and password. | ||||
| func LoginUserPlain(name, passwd string) (*User, error) { | ||||
| 	user := User{Name: name} | ||||
| 	err := user.EncodePasswd(passwd) | ||||
| 	if err != nil { | ||||
| 	if err := user.EncodePasswd(passwd); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| @@ -103,6 +140,7 @@ func LoginUserPlain(name, passwd string) (*User, error) { | ||||
| 	return &user, nil | ||||
| } | ||||
|  | ||||
| // FollowUser marks someone be another's follower. | ||||
| func FollowUser(userId int64, followId int64) error { | ||||
| 	session := orm.NewSession() | ||||
| 	defer session.Close() | ||||
| @@ -125,6 +163,7 @@ func FollowUser(userId int64, followId int64) error { | ||||
| 	return session.Commit() | ||||
| } | ||||
|  | ||||
| // UnFollowUser unmarks someone be another's follower. | ||||
| func UnFollowUser(userId int64, unFollowId int64) error { | ||||
| 	session := orm.NewSession() | ||||
| 	defer session.Close() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user