Skip to content

Commit 8561f26

Browse files
manuelluisGitealafriks
authored
Fix branch/tag notifications in mirror sync (#13855)
* Fix branch/tag notifications in mirror sync * Fix gofmt Co-authored-by: Gitea <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent d0d59e3 commit 8561f26

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

services/mirror/mirror.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func parseRemoteUpdateOutput(output string) []*mirrorSyncResult {
149149

150150
switch {
151151
case strings.HasPrefix(lines[i], " * "): // New reference
152+
if strings.HasPrefix(lines[i], " * [new tag]") {
153+
refName = git.TagPrefix + refName
154+
} else if strings.HasPrefix(lines[i], " * [new branch]") {
155+
refName = git.BranchPrefix + refName
156+
}
152157
results = append(results, &mirrorSyncResult{
153158
refName: refName,
154159
oldCommitID: gitShortEmptySha,
@@ -438,6 +443,21 @@ func syncMirror(repoID string) {
438443

439444
// Create reference
440445
if result.oldCommitID == gitShortEmptySha {
446+
if tp == git.TagPrefix {
447+
tp = "tag"
448+
} else if tp == git.BranchPrefix {
449+
tp = "branch"
450+
}
451+
commitID, err := gitRepo.GetRefCommitID(result.refName)
452+
if err != nil {
453+
log.Error("gitRepo.GetRefCommitID [repo_id: %s, ref_name: %s]: %v", m.RepoID, result.refName, err)
454+
continue
455+
}
456+
notification.NotifySyncPushCommits(m.Repo.MustOwner(), m.Repo, &repo_module.PushUpdateOptions{
457+
RefFullName: result.refName,
458+
OldCommitID: git.EmptySHA,
459+
NewCommitID: commitID,
460+
}, repo_module.NewPushCommits())
441461
notification.NotifySyncCreateRef(m.Repo.MustOwner(), m.Repo, tp, result.refName)
442462
continue
443463
}

0 commit comments

Comments
 (0)