IP: RC Code Review
This commit is contained in:
parent
6b43067e1b
commit
f76eb8a666
8 changed files with 42 additions and 71 deletions
|
@ -37,12 +37,7 @@ type Issue struct {
|
|||
}
|
||||
|
||||
// CreateIssue creates new issue for repository.
|
||||
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
|
||||
}
|
||||
|
||||
func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int, name, labels, content string, isPull bool) (issue *Issue, err error) {
|
||||
// TODO: find out mentions
|
||||
mentions := ""
|
||||
|
||||
|
@ -50,8 +45,8 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int,
|
|||
defer sess.Close()
|
||||
sess.Begin()
|
||||
|
||||
issue := &Issue{
|
||||
Index: count + 1,
|
||||
issue = &Issue{
|
||||
Index: int64(issueCount) + 1,
|
||||
Name: name,
|
||||
RepoId: repoId,
|
||||
PosterId: userId,
|
||||
|
@ -81,11 +76,6 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, issueCount int,
|
|||
return issue, nil
|
||||
}
|
||||
|
||||
// GetIssueCount returns count of issues in the repository.
|
||||
func GetIssueCount(repoId int64) (int64, error) {
|
||||
return orm.Count(&Issue{RepoId: repoId})
|
||||
}
|
||||
|
||||
// GetIssueById returns issue object by given id.
|
||||
func GetIssueByIndex(repoId, index int64) (*Issue, error) {
|
||||
issue := &Issue{RepoId: repoId, Index: index}
|
||||
|
@ -148,16 +138,10 @@ func GetIssues(userId, repoId, posterId, milestoneId int64, page int, isClosed,
|
|||
|
||||
// UpdateIssue updates information of issue.
|
||||
func UpdateIssue(issue *Issue) error {
|
||||
_, err := orm.Update(issue, &Issue{RepoId: issue.RepoId, Index: issue.Index})
|
||||
_, err := orm.Id(issue.Id).AllCols().Update(issue)
|
||||
return err
|
||||
}
|
||||
|
||||
func CloseIssue() {
|
||||
}
|
||||
|
||||
func ReopenIssue() {
|
||||
}
|
||||
|
||||
// Label represents a list of labels of repository for issues.
|
||||
type Label struct {
|
||||
Id int64
|
||||
|
@ -197,8 +181,7 @@ func CreateComment(userId, issueId, commitId, line int64, content string) error
|
|||
sess.Begin()
|
||||
|
||||
if _, err := orm.Insert(&Comment{PosterId: userId, IssueId: issueId,
|
||||
CommitId: commitId, Line: line, Content: content,
|
||||
}); err != nil {
|
||||
CommitId: commitId, Line: line, Content: content}); err != nil {
|
||||
sess.Rollback()
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -96,12 +96,11 @@ func IsRepositoryExist(user *User, repoName string) (bool, error) {
|
|||
has, err := orm.Where("lower_name = ?", strings.ToLower(repoName)).Get(&repo)
|
||||
if err != nil {
|
||||
return has, err
|
||||
} else if !has {
|
||||
return false, nil
|
||||
}
|
||||
s, err := os.Stat(RepoPath(user.Name, repoName))
|
||||
if err != nil {
|
||||
return false, nil // Error simply means does not exist, but we don't want to show up.
|
||||
}
|
||||
return s.IsDir(), nil
|
||||
|
||||
return com.IsDir(RepoPath(user.Name, repoName)), nil
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -224,16 +223,24 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
|
|||
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Trace("stderr(1): %s", stderr)
|
||||
if len(stderr) > 0 {
|
||||
log.Trace("stderr(1): %s", stderr)
|
||||
}
|
||||
|
||||
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
|
||||
"-m", "Init commit"); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Trace("stderr(2): %s", stderr)
|
||||
if len(stderr) > 0 {
|
||||
log.Trace("stderr(2): %s", stderr)
|
||||
}
|
||||
|
||||
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Trace("stderr(3): %s", stderr)
|
||||
if len(stderr) > 0 {
|
||||
log.Trace("stderr(3): %s", stderr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -243,10 +250,9 @@ func createHookUpdate(hookPath, content string) error {
|
|||
return err
|
||||
}
|
||||
defer pu.Close()
|
||||
if _, err = pu.WriteString(content); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
_, err = pu.WriteString(content)
|
||||
return err
|
||||
}
|
||||
|
||||
// InitRepository initializes README and .gitignore if needed.
|
||||
|
@ -322,10 +328,7 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
|
|||
}
|
||||
|
||||
// Apply changes and commit.
|
||||
if err := initRepoCommit(tmpDir, user.NewGitSig()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return initRepoCommit(tmpDir, user.NewGitSig())
|
||||
}
|
||||
|
||||
// UserRepo reporesents a repository with user name.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue