mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
IP: RC Code Review
This commit is contained in:
@@ -60,10 +60,10 @@ func (a Action) GetContent() string {
|
||||
|
||||
// CommitRepoAction adds new action for committing repository.
|
||||
func CommitRepoAction(userId int64, userName string,
|
||||
repoId int64, repoName string, refName string, commits *base.PushCommits) error {
|
||||
repoId int64, repoName string, refName string, commit *base.PushCommits) error {
|
||||
log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName)
|
||||
|
||||
bs, err := json.Marshal(commits)
|
||||
bs, err := json.Marshal(commit)
|
||||
if err != nil {
|
||||
log.Error("action.CommitRepoAction(json): %d/%s", userId, repoName)
|
||||
return err
|
||||
@@ -91,16 +91,13 @@ func CommitRepoAction(userId int64, userName string,
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRepoAction records action for create repository.
|
||||
func NewRepoAction(user *User, repo *Repository) error {
|
||||
_, err := orm.InsertOne(&Action{
|
||||
UserId: user.Id,
|
||||
ActUserId: user.Id,
|
||||
ActUserName: user.Name,
|
||||
OpType: OP_CREATE_REPO,
|
||||
RepoId: repo.Id,
|
||||
RepoName: repo.Name,
|
||||
})
|
||||
// NewRepoAction adds new action for creating repository.
|
||||
func NewRepoAction(user *User, repo *Repository) (err error) {
|
||||
if err = NotifyWatchers(&Action{ActUserId: user.Id, ActUserName: user.Name, OpType: OP_CREATE_REPO,
|
||||
RepoId: repo.Id, RepoName: repo.Name}); err != nil {
|
||||
log.Error("action.NewRepoAction(notify watchers): %d/%s", user.Id, repo.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Trace("action.NewRepoAction: %s/%s", user.LowerName, repo.LowerName)
|
||||
return err
|
||||
|
@@ -37,7 +37,7 @@ type Issue struct {
|
||||
}
|
||||
|
||||
// CreateIssue creates new issue for repository.
|
||||
func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, content string, isPull bool) (*Issue, error) {
|
||||
func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int, name, labels, content string, isPull bool) (*Issue, error) {
|
||||
count, err := GetIssueCount(repoId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -46,6 +46,10 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, co
|
||||
// TODO: find out mentions
|
||||
mentions := ""
|
||||
|
||||
sess := orm.NewSession()
|
||||
defer sess.Close()
|
||||
sess.Begin()
|
||||
|
||||
issue := &Issue{
|
||||
Index: count + 1,
|
||||
Name: name,
|
||||
@@ -58,8 +62,23 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, co
|
||||
Mentions: mentions,
|
||||
Content: content,
|
||||
}
|
||||
_, err = orm.Insert(issue)
|
||||
return issue, err
|
||||
if _, err = sess.Insert(issue); err != nil {
|
||||
sess.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rawSql := "UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?"
|
||||
if _, err = sess.Exec(rawSql, repoId); err != nil {
|
||||
sess.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = sess.Commit(); err != nil {
|
||||
sess.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return issue, nil
|
||||
}
|
||||
|
||||
// GetIssueCount returns count of issues in the repository.
|
||||
|
@@ -10,12 +10,12 @@ import (
|
||||
|
||||
"github.com/lunny/xorm"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
)
|
||||
|
||||
func init() {
|
||||
LoadModelsConfig()
|
||||
NewEngine()
|
||||
|
||||
var err error
|
||||
orm, err = xorm.NewEngine("sqlite3", "./test.db")
|
||||
if err != nil {
|
||||
@@ -25,26 +25,31 @@ func init() {
|
||||
orm.ShowSQL = true
|
||||
orm.ShowDebug = true
|
||||
|
||||
err = orm.Sync(&User{}, &Repo{})
|
||||
err = orm.Sync(&User{}, &Repository{})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
root = "test"
|
||||
base.RepoRootPath = "test"
|
||||
}
|
||||
|
||||
func TestCreateRepository(t *testing.T) {
|
||||
user := User{Id: 1, Type: Individual}
|
||||
_, err := CreateRepository(&user, "test")
|
||||
user := User{Id: 1, Name: "foobar", Type: UT_INDIVIDUAL}
|
||||
_, err := CreateRepository(&user, "test", "", "", "test repo desc", false, false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteRepository(t *testing.T) {
|
||||
user := User{Id: 1, Type: Individual}
|
||||
err := DeleteRepository(&user, "test")
|
||||
err := DeleteRepository(1, 1, "foobar")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommitRepoAction(t *testing.T) {
|
||||
Convey("Create a commit repository action", t, func() {
|
||||
|
||||
})
|
||||
}
|
||||
|
@@ -72,20 +72,22 @@ func NewRepoContext() {
|
||||
|
||||
// Repository represents a git repository.
|
||||
type Repository struct {
|
||||
Id int64
|
||||
OwnerId int64 `xorm:"unique(s)"`
|
||||
ForkId int64
|
||||
LowerName string `xorm:"unique(s) index not null"`
|
||||
Name string `xorm:"index not null"`
|
||||
Description string
|
||||
Website string
|
||||
NumWatches int
|
||||
NumStars int
|
||||
NumForks int
|
||||
IsPrivate bool
|
||||
IsBare bool
|
||||
Created time.Time `xorm:"created"`
|
||||
Updated time.Time `xorm:"updated"`
|
||||
Id int64
|
||||
OwnerId int64 `xorm:"unique(s)"`
|
||||
ForkId int64
|
||||
LowerName string `xorm:"unique(s) index not null"`
|
||||
Name string `xorm:"index not null"`
|
||||
Description string
|
||||
Website string
|
||||
NumWatches int
|
||||
NumStars int
|
||||
NumForks int
|
||||
NumIssues int
|
||||
NumClosedIssues int
|
||||
IsPrivate bool
|
||||
IsBare bool
|
||||
Created time.Time `xorm:"created"`
|
||||
Updated time.Time `xorm:"updated"`
|
||||
}
|
||||
|
||||
// IsRepositoryExist returns true if the repository with given name under user has already existed.
|
||||
@@ -491,11 +493,16 @@ func NotifyWatchers(act *Action) error {
|
||||
if err != nil {
|
||||
return errors.New("repo.NotifyWatchers(get watches): " + err.Error())
|
||||
}
|
||||
watches = append(watches, Watch{UserId: act.ActUserId})
|
||||
|
||||
// Add feed for actioner.
|
||||
act.UserId = act.ActUserId
|
||||
if _, err = orm.InsertOne(act); err != nil {
|
||||
return errors.New("repo.NotifyWatchers(create action): " + err.Error())
|
||||
}
|
||||
|
||||
for i := range watches {
|
||||
if act.ActUserId == watches[i].UserId && i > 0 {
|
||||
continue // Do not add twice in case author watches his/her repository.
|
||||
if act.ActUserId == watches[i].UserId {
|
||||
continue
|
||||
}
|
||||
|
||||
act.UserId = watches[i].UserId
|
||||
|
Reference in New Issue
Block a user