Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prune hook_task table #11416

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e1c9664
sketching out some of the code to add ability to prune hook_task tabl…
bhalbright Apr 14, 2020
ee83fe7
stubbed out more code for prune hook_task
bhalbright Apr 20, 2020
c4502dc
work on prune hook_task
bhalbright Apr 21, 2020
739dfe7
re-arranged on the settings page
bhalbright Apr 23, 2020
2cdecc1
got the form working for editing saving purging of webhook deliveries
bhalbright Apr 24, 2020
dd5a870
got the deletes running for prune hook_task
bhalbright May 8, 2020
dfb2505
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright May 8, 2020
1e800f5
added a couple unit tests; cleaned up delete routine a little
bhalbright May 11, 2020
2ae404b
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright May 11, 2020
c016b7c
added ENABLED setting in the ini
bhalbright May 11, 2020
eea3a74
defaulting run at start to false on prune hook_task
bhalbright May 11, 2020
1a56206
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright May 15, 2020
66c0d8b
added a condition to check is_hook_task_purge_enabled before deleting
bhalbright May 15, 2020
fde6937
removing prior mistake
bhalbright May 15, 2020
dd0f4a1
fixed error in webhook tests
bhalbright May 16, 2020
bc14884
changed query in DeleteDeliveredHookTasks to respect the is_hook_task…
bhalbright May 16, 2020
8a66680
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright May 16, 2020
125dc99
fixed misspelling in comment
bhalbright May 16, 2020
d1db4f2
formatting
bhalbright May 16, 2020
fd13812
changed var declaration
bhalbright May 16, 2020
a28df99
fix unit tests
bhalbright May 16, 2020
4651030
unit tests
bhalbright May 16, 2020
aec78da
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright May 17, 2020
38f6d30
adjusted to cron refactor; added missing string for cron page
bhalbright May 17, 2020
2170896
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright May 20, 2020
537c913
simplified hook_task prune
bhalbright May 20, 2020
b6c09c5
Update models/webhook.go
bhalbright May 21, 2020
ce8d93a
Update models/webhook.go
bhalbright May 21, 2020
3c45159
Update models/webhook.go
bhalbright May 21, 2020
28c73de
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright May 21, 2020
a803bf2
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright May 30, 2020
2c76c5f
Merge branch 'master' into prune-hook-task
zeripath Jul 31, 2020
4a83485
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright Aug 2, 2020
9b2b546
updated hook task delete to find the most recent delivery to delete a…
bhalbright Aug 2, 2020
a4caeca
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright Aug 5, 2020
83925c2
added blank line
bhalbright Aug 5, 2020
5decea3
gofmt migration files
bhalbright Aug 5, 2020
9a09960
gofmt file
bhalbright Aug 5, 2020
6f9af14
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright Aug 6, 2020
49ea492
added additional information about the prune hook_task process
bhalbright Aug 6, 2020
deaac3e
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright Aug 7, 2020
1709bc9
move migration out of the way
zeripath Sep 2, 2020
7ebc11c
Merge remote-tracking branch 'origin/master' into prune-hook-task
zeripath Sep 2, 2020
157fd96
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright Sep 10, 2020
dacb03b
changed a couple log statmentes to trace, should not have been error
bhalbright Sep 10, 2020
d1642ac
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright Sep 12, 2020
63551dd
created unit test to ensure that deleting delivered hook_task records…
bhalbright Sep 12, 2020
0341fc6
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright Sep 16, 2020
cffae2e
Merge branch 'master' of https://github.com/go-gitea/gitea into prune…
bhalbright Sep 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,15 @@ UPDATE_EXISTING = true
; Interval as a duration between each synchronization. (default every 24h)
SCHEDULE = @every 24h

; Prune hook_task table
[cron.prune_hook_task_table]
; Whether to enable the job
ENABLED = true
; Whether to always run at start up time (if ENABLED)
RUN_AT_START = false
; Time interval for job to run
SCHEDULE = @every 24h

[git]
; The path of git executable. If empty, Gitea searches through the PATH environment.
PATH =
Expand Down
6 changes: 6 additions & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@ NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false`

- `SCHEDULE`: **@every 24h** : Interval as a duration between each synchronization, it will always attempt synchronization when the instance starts.

### Cron - Prune hook_task Table (`cron.prune_hook_task_table`)

- `ENABLED`: **true**: Enable service. In the repository table, there are two columns to additionally override the behavior per repository: is_hook_task_purge_enabled - enable or disable purging of hook_task data by repository and number_webhook_deliveries_to_keep - the process will leave the most recently delivered webhooks, this value controls how many are kept. These settings can also be modified per repository in the Gitea UI. By default, the process is enabled for every repository and 10 webhooks are kept.
- `RUN_AT_START`: **false**: Run prune hook_task at start time (if ENABLED).
- `SCHEDULE`: **@every 24h**: Cron syntax for pruning hook_task table.

lunny marked this conversation as resolved.
Show resolved Hide resolved
## Git (`git`)

- `PATH`: **""**: The path of git executable. If empty, Gitea searches through the PATH environment.
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ var migrations = []Migration{
NewMigration("Add Created and Updated to Milestone table", addCreatedAndUpdatedToMilestones),
// v150 -> v151
NewMigration("add primary key to repo_topic", addPrimaryKeyToRepoTopic),
// v151 -> v152
NewMigration("Add IsHookTaskPurgeEnabled and NumberWebhookDeliveriesToKeep columns to Repository table", addHookTaskPurge),
}

// GetCurrentDBVersion returns the current db version
Expand Down
27 changes: 27 additions & 0 deletions models/migrations/v151.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"code.gitea.io/gitea/modules/setting"

"xorm.io/xorm"
)

func addHookTaskPurge(x *xorm.Engine) error {
type Repository struct {
ID int64 `xorm:"pk autoincr"`
IsHookTaskPurgeEnabled bool `xorm:"NOT NULL DEFAULT true"`
NumberWebhookDeliveriesToKeep int64 `xorm:"NOT NULL DEFAULT 10"`
}

if err := x.Sync2(new(Repository)); err != nil {
return err
}

_, err := x.Exec("UPDATE repository SET is_hook_task_purge_enabled = ?, number_webhook_deliveries_to_keep = ?",
setting.Repository.DefaultIsHookTaskPurgeEnabled, setting.Repository.DefaultNumberWebhookDeliveriesToKeep)
return err
}
2 changes: 2 additions & 0 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ type Repository struct {
StatsIndexerStatus *RepoIndexerStatus `xorm:"-"`
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`
CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"`
IsHookTaskPurgeEnabled bool `xorm:"NOT NULL DEFAULT true"`
NumberWebhookDeliveriesToKeep int64 `xorm:"NOT NULL DEFAULT 10"`
Topics []string `xorm:"TEXT JSON"`

// Avatar: ID(10-20)-md5(32) - must fit into 64 symbols
Expand Down
28 changes: 28 additions & 0 deletions models/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,31 @@ func FindRepoUndeliveredHookTasks(repoID int64) ([]*HookTask, error) {
}
return tasks, nil
}

// DeleteDeliveredHookTasks deletes delivered hook tasks of one repository, leaving the most recent delivered based on the parameter
func DeleteDeliveredHookTasks(repoID int64, numberDeliveriesToKeep int64) error {
bhalbright marked this conversation as resolved.
Show resolved Hide resolved
var deliveryDates = make([]int64, 0, 10)
err := x.Table("hook_task").
Where("hook_task.repo_id = ? AND hook_task.is_delivered = ?", repoID, true).
Cols("hook_task.delivered").
Join("INNER", "repository", "hook_task.repo_id = repository.id").
And("repository.is_hook_task_purge_enabled = ?", true).
OrderBy("hook_task.delivered desc").
Limit(1, int(numberDeliveriesToKeep)).
Find(&deliveryDates)
if err != nil {
return err
}

if len(deliveryDates) > 0 {
deletes, err := x.
Where("repo_id = ? and is_delivered = ? and delivered <= ?", repoID, true, deliveryDates[0]).
lunny marked this conversation as resolved.
Show resolved Hide resolved
Delete(new(HookTask))
if err != nil {
return err
}
log.Trace("From repo %d deleted in total %d from hook_task", repoID, deletes)
}

return nil
}
56 changes: 56 additions & 0 deletions models/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package models
import (
"encoding/json"
"testing"
"time"

api "code.gitea.io/gitea/modules/structs"

Expand Down Expand Up @@ -245,3 +246,58 @@ func TestUpdateHookTask(t *testing.T) {
assert.NoError(t, UpdateHookTask(hook))
AssertExistsAndLoadBean(t, hook)
}

func TestDeleteDeliveredHookTasks_DeletesDelivered(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you insert 2 and limit to 1
and check if only the right one has been deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I added a test where I created a new webhook that was delievered "now" and then called the delete method where 1 is kept...and then verified that the newly created webhook is still present.

hookTask := &HookTask{
RepoID: 3,
HookID: 3,
Type: GITEA,
URL: "http://www.example.com/unit_test",
Payloader: &api.PushPayload{},
IsDelivered: true,
}
AssertNotExistsBean(t, hookTask)
assert.NoError(t, CreateHookTask(hookTask))
AssertExistsAndLoadBean(t, hookTask)

assert.NoError(t, DeleteDeliveredHookTasks(3, 0))
AssertNotExistsBean(t, hookTask)
}

func TestDeleteDeliveredHookTasks_LeavesUndelivered(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
hookTask := &HookTask{
RepoID: 2,
HookID: 4,
Type: GITEA,
URL: "http://www.example.com/unit_test",
Payloader: &api.PushPayload{},
IsDelivered: false,
}
AssertNotExistsBean(t, hookTask)
assert.NoError(t, CreateHookTask(hookTask))
AssertExistsAndLoadBean(t, hookTask)

assert.NoError(t, DeleteDeliveredHookTasks(3, 0))
AssertExistsAndLoadBean(t, hookTask)
}

func TestDeleteDeliveredHookTasks_LeavesMostRecentTask(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
hookTask := &HookTask{
RepoID: 2,
HookID: 4,
Type: GITEA,
URL: "http://www.example.com/unit_test",
Payloader: &api.PushPayload{},
IsDelivered: true,
Delivered: time.Now().UnixNano(),
}
AssertNotExistsBean(t, hookTask)
assert.NoError(t, CreateHookTask(hookTask))
AssertExistsAndLoadBean(t, hookTask)

assert.NoError(t, DeleteDeliveredHookTasks(3, 1))
AssertExistsAndLoadBean(t, hookTask)
}
2 changes: 2 additions & 0 deletions modules/auth/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ type RepoSettingForm struct {
// Admin settings
EnableHealthCheck bool
EnableCloseIssuesViaCommitInAnyBranch bool
IsHookTaskPurgeEnabled bool
NumberWebhookDeliveriesToKeep int64
}

// Validate validates the fields
Expand Down
11 changes: 11 additions & 0 deletions modules/cron/tasks_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ func registerUpdateMigrationPosterID() {
})
}

func registerPrunHookTaskTable() {
RegisterTaskFatal("prune_hook_task_table", &BaseConfig{
Enabled: true,
RunAtStart: false,
Schedule: "@every 24h",
}, func(ctx context.Context, _ *models.User, _ Config) error {
return repository_service.PruneHookTaskTable(ctx)
})
}

func initBasicTasks() {
registerUpdateMirrorTask()
registerRepoHealthCheck()
Expand All @@ -116,4 +126,5 @@ func initBasicTasks() {
registerSyncExternalUsers()
registerDeletedBranchesCleanup()
registerUpdateMigrationPosterID()
registerPrunHookTaskTable()
}
2 changes: 2 additions & 0 deletions modules/repository/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (_ *m
IsPrivate: opts.IsPrivate,
IsFsckEnabled: !opts.IsMirror,
CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch,
IsHookTaskPurgeEnabled: setting.Repository.DefaultIsHookTaskPurgeEnabled,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we real have to set it on repo creation?
instead of use global default until user change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I was implementing the way "CloseIssuesViaCommitInAnyBranch" is done...but I think you are suggesting that the columns added to repository would be null by default, and would only have values if the user overrides the settings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

NumberWebhookDeliveriesToKeep: setting.Repository.DefaultNumberWebhookDeliveriesToKeep,
Status: opts.Status,
IsEmpty: !opts.AutoInit,
}
Expand Down
22 changes: 12 additions & 10 deletions modules/repository/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,18 @@ func GenerateGitContent(ctx models.DBContext, templateRepo, generateRepo *models
// GenerateRepository generates a repository from a template
func GenerateRepository(ctx models.DBContext, doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
generateRepo := &models.Repository{
OwnerID: owner.ID,
Owner: owner,
OwnerName: owner.Name,
Name: opts.Name,
LowerName: strings.ToLower(opts.Name),
Description: opts.Description,
IsPrivate: opts.Private,
IsEmpty: !opts.GitContent || templateRepo.IsEmpty,
IsFsckEnabled: templateRepo.IsFsckEnabled,
TemplateID: templateRepo.ID,
OwnerID: owner.ID,
Owner: owner,
OwnerName: owner.Name,
Name: opts.Name,
LowerName: strings.ToLower(opts.Name),
Description: opts.Description,
IsPrivate: opts.Private,
IsEmpty: !opts.GitContent || templateRepo.IsEmpty,
IsFsckEnabled: templateRepo.IsFsckEnabled,
IsHookTaskPurgeEnabled: templateRepo.IsHookTaskPurgeEnabled,
NumberWebhookDeliveriesToKeep: templateRepo.NumberWebhookDeliveriesToKeep,
TemplateID: templateRepo.ID,
}

if err = models.CreateRepository(ctx, doer, owner, generateRepo); err != nil {
Expand Down
49 changes: 49 additions & 0 deletions modules/repository/prune_hook_task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package repository

import (
"context"
"fmt"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"

"xorm.io/builder"
zeripath marked this conversation as resolved.
Show resolved Hide resolved
)

// PruneHookTaskTable deletes rows from hook_task as needed.
func PruneHookTaskTable(ctx context.Context) error {
log.Trace("Doing: PruneHookTaskTable")

if err := models.Iterate(
models.DefaultDBContext(),
new(models.Repository),
builder.Expr("id>0 AND is_hook_task_purge_enabled=?", true),
func(idx int, bean interface{}) error {
select {
case <-ctx.Done():
return fmt.Errorf("Aborted due to shutdown")
default:
}
repo := bean.(*models.Repository)
repoPath := repo.RepoPath()
log.Trace("Running prune hook_task table on repository %s", repoPath)
if err := models.DeleteDeliveredHookTasks(repo.ID, repo.NumberWebhookDeliveriesToKeep); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may fail on sqlite. I think use a Find but not Iterate is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I totally understand, can you elaborate? I saw Iterate usage other places like for example (if I'm understanding):
https://github.com/go-gitea/gitea/blob/master/modules/repository/check.go#L25
https://github.com/go-gitea/gitea/blob/master/modules/repository/hooks.go#L159

But I'm happy to refactor it if it is a problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When did some database operations on an iterate maybe affect a lock on sqlite. If other places also have the problems, they also needs to be changed.

desc := fmt.Sprintf("Failed to prune hook_task on repository (%s): %v", repoPath, err)
log.Warn(desc)
if err = models.CreateRepositoryNotice(desc); err != nil {
log.Error("CreateRepositoryNotice: %v", err)
}
}
return nil
},
); err != nil {
return err
}

log.Trace("Finished: PruneHookTaskTable")
return nil
}
4 changes: 4 additions & 0 deletions modules/setting/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var (
AccessControlAllowOrigin string
UseCompatSSHURI bool
DefaultCloseIssuesViaCommitsInAnyBranch bool
DefaultIsHookTaskPurgeEnabled bool
DefaultNumberWebhookDeliveriesToKeep int64
EnablePushCreateUser bool
EnablePushCreateOrg bool
DisabledRepoUnits []string
Expand Down Expand Up @@ -139,6 +141,8 @@ var (
AccessControlAllowOrigin: "",
UseCompatSSHURI: false,
DefaultCloseIssuesViaCommitsInAnyBranch: false,
DefaultIsHookTaskPurgeEnabled: true,
DefaultNumberWebhookDeliveriesToKeep: 10,
EnablePushCreateUser: false,
EnablePushCreateOrg: false,
DisabledRepoUnits: []string{},
Expand Down
3 changes: 3 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,8 @@ settings.projects_desc = Enable Repository Projects
settings.admin_settings = Administrator Settings
settings.admin_enable_health_check = Enable Repository Health Checks (git fsck)
settings.admin_enable_close_issues_via_commit_in_any_branch = Close an issue via a commit made in a non default branch
settings.admin_enable_hook_task_purge_1 = Purge webhook delivery notifications
settings.admin_enable_hook_task_purge_2 = Webhook deliveries to keep
settings.danger_zone = Danger Zone
settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name.
settings.convert = Convert to Regular Repository
Expand Down Expand Up @@ -1968,6 +1970,7 @@ dashboard.resync_all_sshkeys.desc = (Not needed for the built-in SSH server.)
dashboard.resync_all_hooks = Resynchronize pre-receive, update and post-receive hooks of all repositories.
dashboard.reinit_missing_repos = Reinitialize all missing Git repositories for which records exist
dashboard.sync_external_users = Synchronize external user data
dashboard.prune_hook_task_table = Prune hook_task table.
dashboard.server_uptime = Server Uptime
dashboard.current_goroutine = Current Goroutines
dashboard.current_memory_usage = Current Memory Usage
Expand Down
8 changes: 8 additions & 0 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
repo.CloseIssuesViaCommitInAnyBranch = form.EnableCloseIssuesViaCommitInAnyBranch
}

if repo.IsHookTaskPurgeEnabled != form.IsHookTaskPurgeEnabled {
repo.IsHookTaskPurgeEnabled = form.IsHookTaskPurgeEnabled
}

if form.IsHookTaskPurgeEnabled && repo.NumberWebhookDeliveriesToKeep != form.NumberWebhookDeliveriesToKeep {
repo.NumberWebhookDeliveriesToKeep = form.NumberWebhookDeliveriesToKeep
}

if err := models.UpdateRepository(repo, false); err != nil {
ctx.ServerError("UpdateRepository", err)
return
Expand Down
19 changes: 15 additions & 4 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,22 @@
<label>{{.i18n.Tr "repo.settings.admin_enable_health_check"}}</label>
</div>
</div>
<div class="ui checkbox">
<input name="enable_close_issues_via_commit_in_any_branch" type="checkbox" {{ if .Repository.CloseIssuesViaCommitInAnyBranch }}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.admin_enable_close_issues_via_commit_in_any_branch"}}</label>
<div class="field">
<div class="ui checkbox">
<input name="enable_close_issues_via_commit_in_any_branch" type="checkbox" {{ if .Repository.CloseIssuesViaCommitInAnyBranch }}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.admin_enable_close_issues_via_commit_in_any_branch"}}</label>
</div>
</div>
<div class="field">
<div class="ui checkbox">
<input class="enable-webhooks-to-keep" id="is_hook_task_purge_enabled" name="is_hook_task_purge_enabled" data-target="#number_webhook_deliveries_to_keep_box" type="checkbox" {{ if .Repository.IsHookTaskPurgeEnabled }}checked{{end}}>
<label for="is_hook_task_purge_enabled">{{.i18n.Tr "repo.settings.admin_enable_hook_task_purge_1"}}</label>
</div>
</div>
<div class="field {{if not .Repository.IsHookTaskPurgeEnabled}}disabled{{end}}" id="number_webhook_deliveries_to_keep_box">
<label for="number_webhook_deliveries_to_keep">{{.i18n.Tr "repo.settings.admin_enable_hook_task_purge_2"}}</label>
<input id="number_webhook_deliveries_to_keep" name="number_webhook_deliveries_to_keep" type="number" value="{{ .Repository.NumberWebhookDeliveriesToKeep }}">
</div>

<div class="ui divider"></div>
<div class="field">
<button class="ui green button">{{$.i18n.Tr "repo.settings.update_settings"}}</button>
Expand Down
11 changes: 11 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,17 @@ async function initRepository() {
if (typeof $(this).data('context') !== 'undefined') $($(this).data('context')).addClass('disabled');
}
});

// Enable number of webhooks to keep.
bhalbright marked this conversation as resolved.
Show resolved Hide resolved
$('.enable-webhooks-to-keep').change(function () {
if (this.checked) {
$($(this).data('target')).removeClass('disabled');
if (!$(this).data('context')) $($(this).data('context')).addClass('disabled');
} else {
$($(this).data('target')).addClass('disabled');
if (!$(this).data('context')) $($(this).data('context')).removeClass('disabled');
}
});
}

// Labels
Expand Down