mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Move mirror sync actions to notification (#9022)
* Move mirror sync actions to notification * fix lint
This commit is contained in:
parent
e3f22ad2cc
commit
8ab35eefc4
8 changed files with 135 additions and 81 deletions
|
@ -5,6 +5,7 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
@ -206,3 +207,52 @@ func (*actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode
|
|||
log.Error("NotifyWatchers [%d]: %v", pr.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *models.PushCommits) {
|
||||
data, err := json.Marshal(commits)
|
||||
if err != nil {
|
||||
log.Error("json.Marshal: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.NotifyWatchers(&models.Action{
|
||||
ActUserID: repo.OwnerID,
|
||||
ActUser: repo.MustOwner(),
|
||||
OpType: models.ActionMirrorSyncPush,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
RefName: refName,
|
||||
Content: string(data),
|
||||
}); err != nil {
|
||||
log.Error("notifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
|
||||
if err := models.NotifyWatchers(&models.Action{
|
||||
ActUserID: repo.OwnerID,
|
||||
ActUser: repo.MustOwner(),
|
||||
OpType: models.ActionMirrorSyncCreate,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
RefName: refFullName,
|
||||
}); err != nil {
|
||||
log.Error("notifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) {
|
||||
if err := models.NotifyWatchers(&models.Action{
|
||||
ActUserID: repo.OwnerID,
|
||||
ActUser: repo.MustOwner(),
|
||||
OpType: models.ActionMirrorSyncCreate,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
RefName: refFullName,
|
||||
}); err != nil {
|
||||
log.Error("notifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue