@@ -164,68 +164,70 @@ func (repo *Repository) GetWatchers(page int) ([]*User, error) {
164
164
return users , sess .Find (& users )
165
165
}
166
166
167
- func notifyWatchers (e Engine , act * Action ) error {
168
- // Add feeds for user self and all watchers.
169
- watches , err := getWatchers (e , act .RepoID )
170
- if err != nil {
171
- return fmt .Errorf ("get watchers: %v" , err )
172
- }
173
-
174
- // Add feed for actioner.
175
- act .UserID = act .ActUserID
176
- if _ , err = e .InsertOne (act ); err != nil {
177
- return fmt .Errorf ("insert new actioner: %v" , err )
178
- }
179
-
180
- act .loadRepo ()
181
- // check repo owner exist.
182
- if err := act .Repo .getOwner (e ); err != nil {
183
- return fmt .Errorf ("can't get repo owner: %v" , err )
184
- }
167
+ func notifyWatchers (e Engine , actions ... * Action ) error {
168
+ for _ , act := range actions {
169
+ // Add feeds for user self and all watchers.
170
+ watches , err := getWatchers (e , act .RepoID )
171
+ if err != nil {
172
+ return fmt .Errorf ("get watchers: %v" , err )
173
+ }
185
174
186
- // Add feed for organization
187
- if act .Repo .Owner .IsOrganization () && act .ActUserID != act .Repo .Owner .ID {
188
- act .ID = 0
189
- act .UserID = act .Repo .Owner .ID
175
+ // Add feed for actioner.
176
+ act .UserID = act .ActUserID
190
177
if _ , err = e .InsertOne (act ); err != nil {
191
178
return fmt .Errorf ("insert new actioner: %v" , err )
192
179
}
193
- }
194
180
195
- for i := range watches {
196
- if act .ActUserID == watches [i ].UserID {
197
- continue
181
+ act .loadRepo ()
182
+ // check repo owner exist.
183
+ if err := act .Repo .getOwner (e ); err != nil {
184
+ return fmt .Errorf ("can't get repo owner: %v" , err )
198
185
}
199
186
200
- act .ID = 0
201
- act .UserID = watches [i ].UserID
202
- act .Repo .Units = nil
203
-
204
- switch act .OpType {
205
- case ActionCommitRepo , ActionPushTag , ActionDeleteTag , ActionDeleteBranch :
206
- if ! act .Repo .checkUnitUser (e , act .UserID , false , UnitTypeCode ) {
207
- continue
187
+ // Add feed for organization
188
+ if act .Repo .Owner .IsOrganization () && act .ActUserID != act .Repo .Owner .ID {
189
+ act .ID = 0
190
+ act .UserID = act .Repo .Owner .ID
191
+ if _ , err = e .InsertOne (act ); err != nil {
192
+ return fmt .Errorf ("insert new actioner: %v" , err )
208
193
}
209
- case ActionCreateIssue , ActionCommentIssue , ActionCloseIssue , ActionReopenIssue :
210
- if ! act .Repo .checkUnitUser (e , act .UserID , false , UnitTypeIssues ) {
194
+ }
195
+
196
+ for i := range watches {
197
+ if act .ActUserID == watches [i ].UserID {
211
198
continue
212
199
}
213
- case ActionCreatePullRequest , ActionMergePullRequest , ActionClosePullRequest , ActionReopenPullRequest :
214
- if ! act .Repo .checkUnitUser (e , act .UserID , false , UnitTypePullRequests ) {
215
- continue
200
+
201
+ act .ID = 0
202
+ act .UserID = watches [i ].UserID
203
+ act .Repo .Units = nil
204
+
205
+ switch act .OpType {
206
+ case ActionCommitRepo , ActionPushTag , ActionDeleteTag , ActionDeleteBranch :
207
+ if ! act .Repo .checkUnitUser (e , act .UserID , false , UnitTypeCode ) {
208
+ continue
209
+ }
210
+ case ActionCreateIssue , ActionCommentIssue , ActionCloseIssue , ActionReopenIssue :
211
+ if ! act .Repo .checkUnitUser (e , act .UserID , false , UnitTypeIssues ) {
212
+ continue
213
+ }
214
+ case ActionCreatePullRequest , ActionMergePullRequest , ActionClosePullRequest , ActionReopenPullRequest :
215
+ if ! act .Repo .checkUnitUser (e , act .UserID , false , UnitTypePullRequests ) {
216
+ continue
217
+ }
216
218
}
217
- }
218
219
219
- if _ , err = e .InsertOne (act ); err != nil {
220
- return fmt .Errorf ("insert new action: %v" , err )
220
+ if _ , err = e .InsertOne (act ); err != nil {
221
+ return fmt .Errorf ("insert new action: %v" , err )
222
+ }
221
223
}
222
224
}
223
225
return nil
224
226
}
225
227
226
228
// NotifyWatchers creates batch of actions for every watcher.
227
- func NotifyWatchers (act * Action ) error {
228
- return notifyWatchers (x , act )
229
+ func NotifyWatchers (actions ... * Action ) error {
230
+ return notifyWatchers (x , actions ... )
229
231
}
230
232
231
233
// NotifyWatchersActions creates batch of actions for every watcher.
0 commit comments