@@ -70,20 +70,18 @@ func init() {
70
70
// repository. It implemented interface base.Actioner so that can be
71
71
// used in template render.
72
72
type Action struct {
73
- ID int64 `xorm:"pk autoincr"`
74
- UserID int64 `xorm:"INDEX"` // Receiver user id.
75
- OpType ActionType
76
- ActUserID int64 `xorm:"INDEX"` // Action user id.
77
- ActUserName string `xorm:"-"`
78
- ActAvatar string `xorm:"-"`
79
- RepoID int64 `xorm:"INDEX"`
80
- RepoUserName string `xorm:"-"`
81
- RepoName string `xorm:"-"`
82
- RefName string
83
- IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"`
84
- Content string `xorm:"TEXT"`
85
- Created time.Time `xorm:"-"`
86
- CreatedUnix int64 `xorm:"INDEX"`
73
+ ID int64 `xorm:"pk autoincr"`
74
+ UserID int64 `xorm:"INDEX"` // Receiver user id.
75
+ OpType ActionType
76
+ ActUserID int64 `xorm:"INDEX"` // Action user id.
77
+ ActUser * User `xorm:"-"`
78
+ RepoID int64 `xorm:"INDEX"`
79
+ Repo * Repository `xorm:"-"`
80
+ RefName string
81
+ IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"`
82
+ Content string `xorm:"TEXT"`
83
+ Created time.Time `xorm:"-"`
84
+ CreatedUnix int64 `xorm:"INDEX"`
87
85
}
88
86
89
87
// BeforeInsert will be invoked by XORM before inserting a record
@@ -106,42 +104,71 @@ func (a *Action) GetOpType() int {
106
104
return int (a .OpType )
107
105
}
108
106
107
+ func (a * Action ) loadActUser () {
108
+ if a .ActUser != nil {
109
+ return
110
+ }
111
+ var err error
112
+ a .ActUser , err = GetUserByID (a .ActUserID )
113
+ if err == nil {
114
+ return
115
+ } else if IsErrUserNotExist (err ) {
116
+ a .ActUser = NewGhostUser ()
117
+ } else {
118
+ log .Error (4 , "GetUserByID(%d): %v" , a .ActUserID , err )
119
+ }
120
+ }
121
+
122
+ func (a * Action ) loadRepo () {
123
+ if a .ActUser != nil {
124
+ return
125
+ }
126
+ var err error
127
+ a .Repo , err = GetRepositoryByID (a .RepoID )
128
+ if err != nil {
129
+ log .Error (4 , "GetRepositoryByID(%d): %v" , a .RepoID , err )
130
+ }
131
+ }
132
+
109
133
// GetActUserName gets the action's user name.
110
134
func (a * Action ) GetActUserName () string {
111
- return a .ActUserName
135
+ a .loadActUser ()
136
+ return a .ActUser .Name
112
137
}
113
138
114
139
// ShortActUserName gets the action's user name trimmed to max 20
115
140
// chars.
116
141
func (a * Action ) ShortActUserName () string {
117
- return base .EllipsisString (a .ActUserName , 20 )
142
+ return base .EllipsisString (a .GetActUserName () , 20 )
118
143
}
119
144
120
145
// GetRepoUserName returns the name of the action repository owner.
121
146
func (a * Action ) GetRepoUserName () string {
122
- return a .RepoUserName
147
+ a .loadRepo ()
148
+ return a .Repo .MustOwner ().Name
123
149
}
124
150
125
151
// ShortRepoUserName returns the name of the action repository owner
126
152
// trimmed to max 20 chars.
127
153
func (a * Action ) ShortRepoUserName () string {
128
- return base .EllipsisString (a .RepoUserName , 20 )
154
+ return base .EllipsisString (a .GetRepoUserName () , 20 )
129
155
}
130
156
131
157
// GetRepoName returns the name of the action repository.
132
158
func (a * Action ) GetRepoName () string {
133
- return a .RepoName
159
+ a .loadRepo ()
160
+ return a .Repo .Name
134
161
}
135
162
136
163
// ShortRepoName returns the name of the action repository
137
164
// trimmed to max 33 chars.
138
165
func (a * Action ) ShortRepoName () string {
139
- return base .EllipsisString (a .RepoName , 33 )
166
+ return base .EllipsisString (a .GetRepoName () , 33 )
140
167
}
141
168
142
169
// GetRepoPath returns the virtual path to the action repository.
143
170
func (a * Action ) GetRepoPath () string {
144
- return path .Join (a .RepoUserName , a .RepoName )
171
+ return path .Join (a .GetRepoUserName () , a .GetRepoName () )
145
172
}
146
173
147
174
// ShortRepoPath returns the virtual path to the action repository
@@ -205,13 +232,12 @@ func (a *Action) GetIssueContent() string {
205
232
206
233
func newRepoAction (e Engine , u * User , repo * Repository ) (err error ) {
207
234
if err = notifyWatchers (e , & Action {
208
- ActUserID : u .ID ,
209
- ActUserName : u .Name ,
210
- OpType : ActionCreateRepo ,
211
- RepoID : repo .ID ,
212
- RepoUserName : repo .Owner .Name ,
213
- RepoName : repo .Name ,
214
- IsPrivate : repo .IsPrivate ,
235
+ ActUserID : u .ID ,
236
+ ActUser : u ,
237
+ OpType : ActionCreateRepo ,
238
+ RepoID : repo .ID ,
239
+ Repo : repo ,
240
+ IsPrivate : repo .IsPrivate ,
215
241
}); err != nil {
216
242
return fmt .Errorf ("notify watchers '%d/%d': %v" , u .ID , repo .ID , err )
217
243
}
@@ -227,14 +253,13 @@ func NewRepoAction(u *User, repo *Repository) (err error) {
227
253
228
254
func renameRepoAction (e Engine , actUser * User , oldRepoName string , repo * Repository ) (err error ) {
229
255
if err = notifyWatchers (e , & Action {
230
- ActUserID : actUser .ID ,
231
- ActUserName : actUser .Name ,
232
- OpType : ActionRenameRepo ,
233
- RepoID : repo .ID ,
234
- RepoUserName : repo .Owner .Name ,
235
- RepoName : repo .Name ,
236
- IsPrivate : repo .IsPrivate ,
237
- Content : oldRepoName ,
256
+ ActUserID : actUser .ID ,
257
+ ActUser : actUser ,
258
+ OpType : ActionRenameRepo ,
259
+ RepoID : repo .ID ,
260
+ Repo : repo ,
261
+ IsPrivate : repo .IsPrivate ,
262
+ Content : oldRepoName ,
238
263
}); err != nil {
239
264
return fmt .Errorf ("notify watchers: %v" , err )
240
265
}
@@ -521,15 +546,14 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
521
546
522
547
refName := git .RefEndName (opts .RefFullName )
523
548
if err = NotifyWatchers (& Action {
524
- ActUserID : pusher .ID ,
525
- ActUserName : pusher .Name ,
526
- OpType : opType ,
527
- Content : string (data ),
528
- RepoID : repo .ID ,
529
- RepoUserName : repo .MustOwner ().Name ,
530
- RepoName : repo .Name ,
531
- RefName : refName ,
532
- IsPrivate : repo .IsPrivate ,
549
+ ActUserID : pusher .ID ,
550
+ ActUser : pusher ,
551
+ OpType : opType ,
552
+ Content : string (data ),
553
+ RepoID : repo .ID ,
554
+ Repo : repo ,
555
+ RefName : refName ,
556
+ IsPrivate : repo .IsPrivate ,
533
557
}); err != nil {
534
558
return fmt .Errorf ("NotifyWatchers: %v" , err )
535
559
}
@@ -598,14 +622,13 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
598
622
599
623
func transferRepoAction (e Engine , doer , oldOwner * User , repo * Repository ) (err error ) {
600
624
if err = notifyWatchers (e , & Action {
601
- ActUserID : doer .ID ,
602
- ActUserName : doer .Name ,
603
- OpType : ActionTransferRepo ,
604
- RepoID : repo .ID ,
605
- RepoUserName : repo .Owner .Name ,
606
- RepoName : repo .Name ,
607
- IsPrivate : repo .IsPrivate ,
608
- Content : path .Join (oldOwner .Name , repo .Name ),
625
+ ActUserID : doer .ID ,
626
+ ActUser : doer ,
627
+ OpType : ActionTransferRepo ,
628
+ RepoID : repo .ID ,
629
+ Repo : repo ,
630
+ IsPrivate : repo .IsPrivate ,
631
+ Content : path .Join (oldOwner .Name , repo .Name ),
609
632
}); err != nil {
610
633
return fmt .Errorf ("notifyWatchers: %v" , err )
611
634
}
@@ -628,14 +651,13 @@ func TransferRepoAction(doer, oldOwner *User, repo *Repository) error {
628
651
629
652
func mergePullRequestAction (e Engine , doer * User , repo * Repository , issue * Issue ) error {
630
653
return notifyWatchers (e , & Action {
631
- ActUserID : doer .ID ,
632
- ActUserName : doer .Name ,
633
- OpType : ActionMergePullRequest ,
634
- Content : fmt .Sprintf ("%d|%s" , issue .Index , issue .Title ),
635
- RepoID : repo .ID ,
636
- RepoUserName : repo .Owner .Name ,
637
- RepoName : repo .Name ,
638
- IsPrivate : repo .IsPrivate ,
654
+ ActUserID : doer .ID ,
655
+ ActUser : doer ,
656
+ OpType : ActionMergePullRequest ,
657
+ Content : fmt .Sprintf ("%d|%s" , issue .Index , issue .Title ),
658
+ RepoID : repo .ID ,
659
+ Repo : repo ,
660
+ IsPrivate : repo .IsPrivate ,
639
661
})
640
662
}
641
663
0 commit comments