Compare commits

...

3 Commits

Author SHA1 Message Date
C-Y-X
125949598f
Merge 0603f1029c into 821d2fc2a3 2024-05-18 01:18:50 +09:00
wxiaoguang
821d2fc2a3
Simplify mirror repository API logic (#30963)
Fix #30921
2024-05-17 16:07:41 +00:00
C-Y-X
0603f1029c Added support for custom Telegram proxy host 2024-03-08 17:54:10 +08:00
8 changed files with 26 additions and 21 deletions

View File

@ -217,7 +217,7 @@ type EditRepoOption struct {
Archived *bool `json:"archived,omitempty"`
// set to a string like `8h30m0s` to set the mirror interval time
MirrorInterval *string `json:"mirror_interval,omitempty"`
// enable prune - remove obsolete remote-tracking references
// enable prune - remove obsolete remote-tracking references when mirroring
EnablePrune *bool `json:"enable_prune,omitempty"`
}

View File

@ -2438,6 +2438,7 @@ settings.tags.protection.none = There are no protected tags.
settings.tags.protection.pattern.description = You can use a single name or a glob pattern or regular expression to match multiple tags. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.com/usage/protected-tags">protected tags guide</a>.
settings.bot_token = Bot Token
settings.chat_id = Chat ID
settings.custom_host= Custom Host
settings.thread_id = Thread ID
settings.matrix.homeserver_url = Homeserver URL
settings.matrix.room_id = Room ID

View File

@ -1062,16 +1062,10 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
repo := ctx.Repo.Repository
// only update mirror if interval or enable prune are provided
if opts.MirrorInterval == nil && opts.EnablePrune == nil {
return nil
}
// these values only make sense if the repo is a mirror
// Skip this update if the repo is not a mirror, do not return error.
// Because reporting errors only makes the logic more complex&fragile, it doesn't really help end users.
if !repo.IsMirror {
err := fmt.Errorf("repo is not a mirror, can not change mirror interval")
ctx.Error(http.StatusUnprocessableEntity, err.Error(), err)
return err
return nil
}
// get the mirror from the repo

View File

@ -425,15 +425,19 @@ func TelegramHooksEditPost(ctx *context.Context) {
func telegramHookParams(ctx *context.Context) webhookParams {
form := web.GetForm(ctx).(*forms.NewTelegramHookForm)
if form.CustomHost == "" {
form.CustomHost = "https://api.telegram.org"
}
return webhookParams{
Type: webhook_module.TELEGRAM,
URL: fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage?chat_id=%s&message_thread_id=%s", url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID), url.QueryEscape(form.ThreadID)),
URL: fmt.Sprintf("%s/bot%s/sendMessage?chat_id=%s&message_thread_id=%s", form.CustomHost, url.PathEscape(form.BotToken), url.QueryEscape(form.ChatID), url.QueryEscape(form.ThreadID)),
ContentType: webhook.ContentTypeJSON,
WebhookForm: form.WebhookForm,
Meta: &webhook_service.TelegramMeta{
BotToken: form.BotToken,
ChatID: form.ChatID,
ThreadID: form.ThreadID,
BotToken: form.BotToken,
ChatID: form.ChatID,
CustomHost: form.CustomHost,
ThreadID: form.ThreadID,
},
}
}

View File

@ -351,9 +351,10 @@ func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) b
// NewTelegramHookForm form for creating telegram hook
type NewTelegramHookForm struct {
BotToken string `binding:"Required"`
ChatID string `binding:"Required"`
ThreadID string
BotToken string `binding:"Required"`
ChatID string `binding:"Required"`
CustomHost string
ThreadID string
WebhookForm
}

View File

@ -27,9 +27,10 @@ type (
// TelegramMeta contains the telegram metadata
TelegramMeta struct {
BotToken string `json:"bot_token"`
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
BotToken string `json:"bot_token"`
ChatID string `json:"chat_id"`
CustomHost string `json:"custom_host"`
ThreadID string `json:"thread_id"`
}
)

View File

@ -10,6 +10,10 @@
<label for="chat_id">{{ctx.Locale.Tr "repo.settings.chat_id"}}</label>
<input id="chat_id" name="chat_id" type="text" value="{{.TelegramHook.ChatID}}" required>
</div>
<div class="field {{if .Err_CustomHost}}error{{end}}">
<label for="custom_host">{{ctx.Locale.Tr "repo.settings.custom_host"}}</label>
<input id="custom_host" name="custom_host" type="text" value="{{.TelegramHook.CustomHost}}" placeholder="https://api.telegram.org">
</div>
<div class="field {{if .Err_ThreadID}}error{{end}}">
<label for="thread_id">{{ctx.Locale.Tr "repo.settings.thread_id"}}</label>
<input id="thread_id" name="thread_id" type="text" value="{{.TelegramHook.ThreadID}}">

View File

@ -20753,7 +20753,7 @@
"x-go-name": "Description"
},
"enable_prune": {
"description": "enable prune - remove obsolete remote-tracking references",
"description": "enable prune - remove obsolete remote-tracking references when mirroring",
"type": "boolean",
"x-go-name": "EnablePrune"
},