|
|
@ -70,20 +70,18 @@ func init() { |
|
|
|
// repository. It implemented interface base.Actioner so that can be
|
|
|
|
// repository. It implemented interface base.Actioner so that can be
|
|
|
|
// used in template render.
|
|
|
|
// used in template render.
|
|
|
|
type Action struct { |
|
|
|
type Action struct { |
|
|
|
ID int64 `xorm:"pk autoincr"` |
|
|
|
ID int64 `xorm:"pk autoincr"` |
|
|
|
UserID int64 `xorm:"INDEX"` // Receiver user id.
|
|
|
|
UserID int64 `xorm:"INDEX"` // Receiver user id.
|
|
|
|
OpType ActionType |
|
|
|
OpType ActionType |
|
|
|
ActUserID int64 `xorm:"INDEX"` // Action user id.
|
|
|
|
ActUserID int64 `xorm:"INDEX"` // Action user id.
|
|
|
|
ActUserName string // Action user name.
|
|
|
|
ActUser *User `xorm:"-"` |
|
|
|
ActAvatar string `xorm:"-"` |
|
|
|
RepoID int64 `xorm:"INDEX"` |
|
|
|
RepoID int64 `xorm:"INDEX"` |
|
|
|
Repo *Repository `xorm:"-"` |
|
|
|
RepoUserName string |
|
|
|
RefName string |
|
|
|
RepoName string |
|
|
|
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"` |
|
|
|
RefName string |
|
|
|
Content string `xorm:"TEXT"` |
|
|
|
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"` |
|
|
|
Created time.Time `xorm:"-"` |
|
|
|
Content string `xorm:"TEXT"` |
|
|
|
CreatedUnix int64 `xorm:"INDEX"` |
|
|
|
Created time.Time `xorm:"-"` |
|
|
|
|
|
|
|
CreatedUnix int64 `xorm:"INDEX"` |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// BeforeInsert will be invoked by XORM before inserting a record
|
|
|
|
// BeforeInsert will be invoked by XORM before inserting a record
|
|
|
@ -106,42 +104,71 @@ func (a *Action) GetOpType() int { |
|
|
|
return int(a.OpType) |
|
|
|
return int(a.OpType) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (a *Action) loadActUser() { |
|
|
|
|
|
|
|
if a.ActUser != nil { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
a.ActUser, err = GetUserByID(a.ActUserID) |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} else if IsErrUserNotExist(err) { |
|
|
|
|
|
|
|
a.ActUser = NewGhostUser() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.Error(4, "GetUserByID(%d): %v", a.ActUserID, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (a *Action) loadRepo() { |
|
|
|
|
|
|
|
if a.ActUser != nil { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
a.Repo, err = GetRepositoryByID(a.RepoID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Error(4, "GetRepositoryByID(%d): %v", a.RepoID, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetActUserName gets the action's user name.
|
|
|
|
// GetActUserName gets the action's user name.
|
|
|
|
func (a *Action) GetActUserName() string { |
|
|
|
func (a *Action) GetActUserName() string { |
|
|
|
return a.ActUserName |
|
|
|
a.loadActUser() |
|
|
|
|
|
|
|
return a.ActUser.Name |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ShortActUserName gets the action's user name trimmed to max 20
|
|
|
|
// ShortActUserName gets the action's user name trimmed to max 20
|
|
|
|
// chars.
|
|
|
|
// chars.
|
|
|
|
func (a *Action) ShortActUserName() string { |
|
|
|
func (a *Action) ShortActUserName() string { |
|
|
|
return base.EllipsisString(a.ActUserName, 20) |
|
|
|
return base.EllipsisString(a.GetActUserName(), 20) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetRepoUserName returns the name of the action repository owner.
|
|
|
|
// GetRepoUserName returns the name of the action repository owner.
|
|
|
|
func (a *Action) GetRepoUserName() string { |
|
|
|
func (a *Action) GetRepoUserName() string { |
|
|
|
return a.RepoUserName |
|
|
|
a.loadRepo() |
|
|
|
|
|
|
|
return a.Repo.MustOwner().Name |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ShortRepoUserName returns the name of the action repository owner
|
|
|
|
// ShortRepoUserName returns the name of the action repository owner
|
|
|
|
// trimmed to max 20 chars.
|
|
|
|
// trimmed to max 20 chars.
|
|
|
|
func (a *Action) ShortRepoUserName() string { |
|
|
|
func (a *Action) ShortRepoUserName() string { |
|
|
|
return base.EllipsisString(a.RepoUserName, 20) |
|
|
|
return base.EllipsisString(a.GetRepoUserName(), 20) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetRepoName returns the name of the action repository.
|
|
|
|
// GetRepoName returns the name of the action repository.
|
|
|
|
func (a *Action) GetRepoName() string { |
|
|
|
func (a *Action) GetRepoName() string { |
|
|
|
return a.RepoName |
|
|
|
a.loadRepo() |
|
|
|
|
|
|
|
return a.Repo.Name |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ShortRepoName returns the name of the action repository
|
|
|
|
// ShortRepoName returns the name of the action repository
|
|
|
|
// trimmed to max 33 chars.
|
|
|
|
// trimmed to max 33 chars.
|
|
|
|
func (a *Action) ShortRepoName() string { |
|
|
|
func (a *Action) ShortRepoName() string { |
|
|
|
return base.EllipsisString(a.RepoName, 33) |
|
|
|
return base.EllipsisString(a.GetRepoName(), 33) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetRepoPath returns the virtual path to the action repository.
|
|
|
|
// GetRepoPath returns the virtual path to the action repository.
|
|
|
|
func (a *Action) GetRepoPath() string { |
|
|
|
func (a *Action) GetRepoPath() string { |
|
|
|
return path.Join(a.RepoUserName, a.RepoName) |
|
|
|
return path.Join(a.GetRepoUserName(), a.GetRepoName()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ShortRepoPath returns the virtual path to the action repository
|
|
|
|
// ShortRepoPath returns the virtual path to the action repository
|
|
|
@ -205,13 +232,12 @@ func (a *Action) GetIssueContent() string { |
|
|
|
|
|
|
|
|
|
|
|
func newRepoAction(e Engine, u *User, repo *Repository) (err error) { |
|
|
|
func newRepoAction(e Engine, u *User, repo *Repository) (err error) { |
|
|
|
if err = notifyWatchers(e, &Action{ |
|
|
|
if err = notifyWatchers(e, &Action{ |
|
|
|
ActUserID: u.ID, |
|
|
|
ActUserID: u.ID, |
|
|
|
ActUserName: u.Name, |
|
|
|
ActUser: u, |
|
|
|
OpType: ActionCreateRepo, |
|
|
|
OpType: ActionCreateRepo, |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoUserName: repo.Owner.Name, |
|
|
|
Repo: repo, |
|
|
|
RepoName: repo.Name, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
|
|
|
|
}); err != nil { |
|
|
|
}); err != nil { |
|
|
|
return fmt.Errorf("notify watchers '%d/%d': %v", u.ID, repo.ID, err) |
|
|
|
return fmt.Errorf("notify watchers '%d/%d': %v", u.ID, repo.ID, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -227,14 +253,13 @@ func NewRepoAction(u *User, repo *Repository) (err error) { |
|
|
|
|
|
|
|
|
|
|
|
func renameRepoAction(e Engine, actUser *User, oldRepoName string, repo *Repository) (err error) { |
|
|
|
func renameRepoAction(e Engine, actUser *User, oldRepoName string, repo *Repository) (err error) { |
|
|
|
if err = notifyWatchers(e, &Action{ |
|
|
|
if err = notifyWatchers(e, &Action{ |
|
|
|
ActUserID: actUser.ID, |
|
|
|
ActUserID: actUser.ID, |
|
|
|
ActUserName: actUser.Name, |
|
|
|
ActUser: actUser, |
|
|
|
OpType: ActionRenameRepo, |
|
|
|
OpType: ActionRenameRepo, |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoUserName: repo.Owner.Name, |
|
|
|
Repo: repo, |
|
|
|
RepoName: repo.Name, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
Content: oldRepoName, |
|
|
|
Content: oldRepoName, |
|
|
|
|
|
|
|
}); err != nil { |
|
|
|
}); err != nil { |
|
|
|
return fmt.Errorf("notify watchers: %v", err) |
|
|
|
return fmt.Errorf("notify watchers: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -521,15 +546,14 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { |
|
|
|
|
|
|
|
|
|
|
|
refName := git.RefEndName(opts.RefFullName) |
|
|
|
refName := git.RefEndName(opts.RefFullName) |
|
|
|
if err = NotifyWatchers(&Action{ |
|
|
|
if err = NotifyWatchers(&Action{ |
|
|
|
ActUserID: pusher.ID, |
|
|
|
ActUserID: pusher.ID, |
|
|
|
ActUserName: pusher.Name, |
|
|
|
ActUser: pusher, |
|
|
|
OpType: opType, |
|
|
|
OpType: opType, |
|
|
|
Content: string(data), |
|
|
|
Content: string(data), |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoUserName: repo.MustOwner().Name, |
|
|
|
Repo: repo, |
|
|
|
RepoName: repo.Name, |
|
|
|
RefName: refName, |
|
|
|
RefName: refName, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
|
|
|
|
}); err != nil { |
|
|
|
}); err != nil { |
|
|
|
return fmt.Errorf("NotifyWatchers: %v", err) |
|
|
|
return fmt.Errorf("NotifyWatchers: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -598,14 +622,13 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { |
|
|
|
|
|
|
|
|
|
|
|
func transferRepoAction(e Engine, doer, oldOwner *User, repo *Repository) (err error) { |
|
|
|
func transferRepoAction(e Engine, doer, oldOwner *User, repo *Repository) (err error) { |
|
|
|
if err = notifyWatchers(e, &Action{ |
|
|
|
if err = notifyWatchers(e, &Action{ |
|
|
|
ActUserID: doer.ID, |
|
|
|
ActUserID: doer.ID, |
|
|
|
ActUserName: doer.Name, |
|
|
|
ActUser: doer, |
|
|
|
OpType: ActionTransferRepo, |
|
|
|
OpType: ActionTransferRepo, |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoUserName: repo.Owner.Name, |
|
|
|
Repo: repo, |
|
|
|
RepoName: repo.Name, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
Content: path.Join(oldOwner.Name, repo.Name), |
|
|
|
Content: path.Join(oldOwner.Name, repo.Name), |
|
|
|
|
|
|
|
}); err != nil { |
|
|
|
}); err != nil { |
|
|
|
return fmt.Errorf("notifyWatchers: %v", err) |
|
|
|
return fmt.Errorf("notifyWatchers: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
@ -628,14 +651,13 @@ func TransferRepoAction(doer, oldOwner *User, repo *Repository) error { |
|
|
|
|
|
|
|
|
|
|
|
func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue) error { |
|
|
|
func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue) error { |
|
|
|
return notifyWatchers(e, &Action{ |
|
|
|
return notifyWatchers(e, &Action{ |
|
|
|
ActUserID: doer.ID, |
|
|
|
ActUserID: doer.ID, |
|
|
|
ActUserName: doer.Name, |
|
|
|
ActUser: doer, |
|
|
|
OpType: ActionMergePullRequest, |
|
|
|
OpType: ActionMergePullRequest, |
|
|
|
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title), |
|
|
|
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title), |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoID: repo.ID, |
|
|
|
RepoUserName: repo.Owner.Name, |
|
|
|
Repo: repo, |
|
|
|
RepoName: repo.Name, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
IsPrivate: repo.IsPrivate, |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|