diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-05-26 09:04:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-26 01:04:48 +0000 |
commit | f9cfd6ce5bd7f27e2655fd307022461a802fc49c (patch) | |
tree | 9279cab7249c1c7e66a81e694f1096e709c1a8a1 /services/webhook | |
parent | 26fa94bc25ecba731a12af16b6172768389287a7 (diff) | |
download | gitea-f9cfd6ce5bd7f27e2655fd307022461a802fc49c.tar.gz gitea-f9cfd6ce5bd7f27e2655fd307022461a802fc49c.zip |
Use the type RefName for all the needed places and fix pull mirror sync bugs (#24634)
This PR replaces all string refName as a type `git.RefName` to make the
code more maintainable.
Fix #15367
Replaces #23070
It also fixed a bug that tags are not sync because `git remote --prune
origin` will not remove local tags if remote removed.
We in fact should use `git fetch --prune --tags origin` but not `git
remote update origin` to do the sync.
Some answer from ChatGPT as ref.
> If the git fetch --prune --tags command is not working as expected,
there could be a few reasons why. Here are a few things to check:
>
>Make sure that you have the latest version of Git installed on your
system. You can check the version by running git --version in your
terminal. If you have an outdated version, try updating Git and see if
that resolves the issue.
>
>Check that your Git repository is properly configured to track the
remote repository's tags. You can check this by running git config
--get-all remote.origin.fetch and verifying that it includes
+refs/tags/*:refs/tags/*. If it does not, you can add it by running git
config --add remote.origin.fetch "+refs/tags/*:refs/tags/*".
>
>Verify that the tags you are trying to prune actually exist on the
remote repository. You can do this by running git ls-remote --tags
origin to list all the tags on the remote repository.
>
>Check if any local tags have been created that match the names of tags
on the remote repository. If so, these local tags may be preventing the
git fetch --prune --tags command from working properly. You can delete
local tags using the git tag -d command.
---------
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'services/webhook')
-rw-r--r-- | services/webhook/dingtalk.go | 6 | ||||
-rw-r--r-- | services/webhook/discord.go | 6 | ||||
-rw-r--r-- | services/webhook/feishu.go | 6 | ||||
-rw-r--r-- | services/webhook/matrix.go | 4 | ||||
-rw-r--r-- | services/webhook/msteams.go | 6 | ||||
-rw-r--r-- | services/webhook/notifier.go | 30 | ||||
-rw-r--r-- | services/webhook/slack.go | 4 | ||||
-rw-r--r-- | services/webhook/telegram.go | 6 | ||||
-rw-r--r-- | services/webhook/wechatwork.go | 6 |
9 files changed, 37 insertions, 37 deletions
diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go index 99ee6e4d19..69fae03299 100644 --- a/services/webhook/dingtalk.go +++ b/services/webhook/dingtalk.go @@ -36,7 +36,7 @@ func (d *DingtalkPayload) JSONPayload() ([]byte, error) { // Create implements PayloadConvertor Create method func (d *DingtalkPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf("[%s] %s %s created", p.Repo.FullName, p.RefType, refName) return createDingtalkPayload(title, title, fmt.Sprintf("view ref %s", refName), p.Repo.HTMLURL+"/src/"+util.PathEscapeSegments(refName)), nil @@ -45,7 +45,7 @@ func (d *DingtalkPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // Delete implements PayloadConvertor Delete method func (d *DingtalkPayload) Delete(p *api.DeletePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf("[%s] %s %s deleted", p.Repo.FullName, p.RefType, refName) return createDingtalkPayload(title, title, fmt.Sprintf("view ref %s", refName), p.Repo.HTMLURL+"/src/"+util.PathEscapeSegments(refName)), nil @@ -61,7 +61,7 @@ func (d *DingtalkPayload) Fork(p *api.ForkPayload) (api.Payloader, error) { // Push implements PayloadConvertor Push method func (d *DingtalkPayload) Push(p *api.PushPayload) (api.Payloader, error) { var ( - branchName = git.RefEndName(p.Ref) + branchName = git.RefName(p.Ref).ShortName() commitDesc string ) diff --git a/services/webhook/discord.go b/services/webhook/discord.go index 02f0fb8720..204587eca5 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -112,7 +112,7 @@ var _ PayloadConvertor = &DiscordPayload{} // Create implements PayloadConvertor Create method func (d *DiscordPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf("[%s] %s %s created", p.Repo.FullName, p.RefType, refName) return d.createPayload(p.Sender, title, "", p.Repo.HTMLURL+"/src/"+util.PathEscapeSegments(refName), greenColor), nil @@ -121,7 +121,7 @@ func (d *DiscordPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // Delete implements PayloadConvertor Delete method func (d *DiscordPayload) Delete(p *api.DeletePayload) (api.Payloader, error) { // deleted tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf("[%s] %s %s deleted", p.Repo.FullName, p.RefType, refName) return d.createPayload(p.Sender, title, "", p.Repo.HTMLURL+"/src/"+util.PathEscapeSegments(refName), redColor), nil @@ -137,7 +137,7 @@ func (d *DiscordPayload) Fork(p *api.ForkPayload) (api.Payloader, error) { // Push implements PayloadConvertor Push method func (d *DiscordPayload) Push(p *api.PushPayload) (api.Payloader, error) { var ( - branchName = git.RefEndName(p.Ref) + branchName = git.RefName(p.Ref).ShortName() commitDesc string ) diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go index 4fbf8f76a9..885cde3bc5 100644 --- a/services/webhook/feishu.go +++ b/services/webhook/feishu.go @@ -48,7 +48,7 @@ var _ PayloadConvertor = &FeishuPayload{} // Create implements PayloadConvertor Create method func (f *FeishuPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() text := fmt.Sprintf("[%s] %s %s created", p.Repo.FullName, p.RefType, refName) return newFeishuTextPayload(text), nil @@ -57,7 +57,7 @@ func (f *FeishuPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // Delete implements PayloadConvertor Delete method func (f *FeishuPayload) Delete(p *api.DeletePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() text := fmt.Sprintf("[%s] %s %s deleted", p.Repo.FullName, p.RefType, refName) return newFeishuTextPayload(text), nil @@ -73,7 +73,7 @@ func (f *FeishuPayload) Fork(p *api.ForkPayload) (api.Payloader, error) { // Push implements PayloadConvertor Push method func (f *FeishuPayload) Push(p *api.PushPayload) (api.Payloader, error) { var ( - branchName = git.RefEndName(p.Ref) + branchName = git.RefName(p.Ref).ShortName() commitDesc string ) diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go index cf2b503cdc..df97b43b64 100644 --- a/services/webhook/matrix.go +++ b/services/webhook/matrix.go @@ -73,7 +73,7 @@ func MatrixLinkFormatter(url, text string) string { // MatrixLinkToRef Matrix-formatter link to a repo ref func MatrixLinkToRef(repoURL, ref string) string { - refName := git.RefEndName(ref) + refName := git.RefName(ref).ShortName() switch { case strings.HasPrefix(ref, git.BranchPrefix): return MatrixLinkFormatter(repoURL+"/src/branch/"+util.PathEscapeSegments(refName), refName) @@ -95,7 +95,7 @@ func (m *MatrixPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // Delete composes Matrix payload for delete a branch or tag. func (m *MatrixPayload) Delete(p *api.DeletePayload) (api.Payloader, error) { - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() repoLink := MatrixLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName) text := fmt.Sprintf("[%s:%s] %s deleted by %s", repoLink, refName, p.RefType, p.Sender.UserName) diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go index 60ef334ded..6ad58a6247 100644 --- a/services/webhook/msteams.go +++ b/services/webhook/msteams.go @@ -70,7 +70,7 @@ var _ PayloadConvertor = &MSTeamsPayload{} // Create implements PayloadConvertor Create method func (m *MSTeamsPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf("[%s] %s %s created", p.Repo.FullName, p.RefType, refName) return createMSTeamsPayload( @@ -87,7 +87,7 @@ func (m *MSTeamsPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // Delete implements PayloadConvertor Delete method func (m *MSTeamsPayload) Delete(p *api.DeletePayload) (api.Payloader, error) { // deleted tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf("[%s] %s %s deleted", p.Repo.FullName, p.RefType, refName) return createMSTeamsPayload( @@ -119,7 +119,7 @@ func (m *MSTeamsPayload) Fork(p *api.ForkPayload) (api.Payloader, error) { // Push implements PayloadConvertor Push method func (m *MSTeamsPayload) Push(p *api.PushPayload) (api.Payloader, error) { var ( - branchName = git.RefEndName(p.Ref) + branchName = git.RefName(p.Ref).ShortName() commitDesc string ) diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index bd25e20805..e10c83e02f 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -596,7 +596,7 @@ func (m *webhookNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mo } if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{ - Ref: opts.RefFullName, + Ref: opts.RefFullName.String(), Before: opts.OldCommitID, After: opts.NewCommitID, CompareURL: setting.AppURL + commits.CompareURL, @@ -747,15 +747,15 @@ func (m *webhookNotifier) NotifyPullReviewRequest(ctx context.Context, doer *use } } -func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { +func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) { apiPusher := convert.ToUser(ctx, pusher, nil) apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone) - refName := git.RefEndName(refFullName) + refName := refFullName.ShortName() if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventCreate, &api.CreatePayload{ - Ref: refName, + Ref: refName, // FIXME: should it be a full ref name? Sha: refID, - RefType: refType, + RefType: refFullName.RefGroup(), Repo: apiRepo, Sender: apiPusher, }); err != nil { @@ -784,19 +784,19 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(ctx context.Context, doe } } -func (m *webhookNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { +func (m *webhookNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) { apiPusher := convert.ToUser(ctx, pusher, nil) apiRepo := convert.ToRepo(ctx, repo, perm.AccessModeNone) - refName := git.RefEndName(refFullName) + refName := refFullName.ShortName() if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventDelete, &api.DeletePayload{ - Ref: refName, - RefType: refType, + Ref: refName, // FIXME: should it be a full ref name? + RefType: refFullName.RefGroup(), PusherType: api.PusherTypeUser, Repo: apiRepo, Sender: apiPusher, }); err != nil { - log.Error("PrepareWebhooks.(delete %s): %v", refType, err) + log.Error("PrepareWebhooks.(delete %s): %v", refFullName.RefGroup(), err) } } @@ -838,7 +838,7 @@ func (m *webhookNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use } if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{ - Ref: opts.RefFullName, + Ref: opts.RefFullName.String(), Before: opts.OldCommitID, After: opts.NewCommitID, CompareURL: setting.AppURL + commits.CompareURL, @@ -853,12 +853,12 @@ func (m *webhookNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use } } -func (m *webhookNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) { - m.NotifyCreateRef(ctx, pusher, repo, refType, refFullName, refID) +func (m *webhookNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) { + m.NotifyCreateRef(ctx, pusher, repo, refFullName, refID) } -func (m *webhookNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) { - m.NotifyDeleteRef(ctx, pusher, repo, refType, refFullName) +func (m *webhookNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) { + m.NotifyDeleteRef(ctx, pusher, repo, refFullName) } func (m *webhookNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { diff --git a/services/webhook/slack.go b/services/webhook/slack.go index c2d4a7731e..0cb27bb3dd 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -93,7 +93,7 @@ func SlackLinkFormatter(url, text string) string { // SlackLinkToRef slack-formatter link to a repo ref func SlackLinkToRef(repoURL, ref string) string { url := git.RefURL(repoURL, ref) - refName := git.RefEndName(ref) + refName := git.RefName(ref).ShortName() return SlackLinkFormatter(url, refName) } @@ -110,7 +110,7 @@ func (s *SlackPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // Delete composes Slack payload for delete a branch or tag. func (s *SlackPayload) Delete(p *api.DeletePayload) (api.Payloader, error) { - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName) text := fmt.Sprintf("[%s:%s] %s deleted by %s", repoLink, refName, p.RefType, p.Sender.UserName) diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go index e5c731fc92..2d0484648b 100644 --- a/services/webhook/telegram.go +++ b/services/webhook/telegram.go @@ -57,7 +57,7 @@ func (t *TelegramPayload) JSONPayload() ([]byte, error) { // Create implements PayloadConvertor Create method func (t *TelegramPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf(`[<a href="%s">%s</a>] %s <a href="%s">%s</a> created`, p.Repo.HTMLURL, p.Repo.FullName, p.RefType, p.Repo.HTMLURL+"/src/"+refName, refName) @@ -67,7 +67,7 @@ func (t *TelegramPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // Delete implements PayloadConvertor Delete method func (t *TelegramPayload) Delete(p *api.DeletePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf(`[<a href="%s">%s</a>] %s <a href="%s">%s</a> deleted`, p.Repo.HTMLURL, p.Repo.FullName, p.RefType, p.Repo.HTMLURL+"/src/"+refName, refName) @@ -84,7 +84,7 @@ func (t *TelegramPayload) Fork(p *api.ForkPayload) (api.Payloader, error) { // Push implements PayloadConvertor Push method func (t *TelegramPayload) Push(p *api.PushPayload) (api.Payloader, error) { var ( - branchName = git.RefEndName(p.Ref) + branchName = git.RefName(p.Ref).ShortName() commitDesc string ) diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go index dc8810c4a6..a7680f1c67 100644 --- a/services/webhook/wechatwork.go +++ b/services/webhook/wechatwork.go @@ -56,7 +56,7 @@ var _ PayloadConvertor = &WechatworkPayload{} // Create implements PayloadConvertor Create method func (f *WechatworkPayload) Create(p *api.CreatePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf("[%s] %s %s created", p.Repo.FullName, p.RefType, refName) return newWechatworkMarkdownPayload(title), nil @@ -65,7 +65,7 @@ func (f *WechatworkPayload) Create(p *api.CreatePayload) (api.Payloader, error) // Delete implements PayloadConvertor Delete method func (f *WechatworkPayload) Delete(p *api.DeletePayload) (api.Payloader, error) { // created tag/branch - refName := git.RefEndName(p.Ref) + refName := git.RefName(p.Ref).ShortName() title := fmt.Sprintf("[%s] %s %s deleted", p.Repo.FullName, p.RefType, refName) return newWechatworkMarkdownPayload(title), nil @@ -81,7 +81,7 @@ func (f *WechatworkPayload) Fork(p *api.ForkPayload) (api.Payloader, error) { // Push implements PayloadConvertor Push method func (f *WechatworkPayload) Push(p *api.PushPayload) (api.Payloader, error) { var ( - branchName = git.RefEndName(p.Ref) + branchName = git.RefName(p.Ref).ShortName() commitDesc string ) |