Skip to content

Commit 8407621

Browse files
sebastian-sauerzeripath
authored andcommitted
Config option to disable automatic repo watching (#5852)
Add a new config option to enable / disable the automatic watching of repos for new repositories and if a user is added to a team. Fixes #653 Signed-off-by: Sebastian Sauer <[email protected]>
1 parent b8a81cb commit 8407621

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

custom/conf/app.ini.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME = true
368368
NO_REPLY_ADDRESS = noreply.example.org
369369
; Show Registration button
370370
SHOW_REGISTRATION_BUTTON = true
371+
; Default value for AutoWatchNewRepos
372+
; When adding a repo to a team or creating a new repo all team members will watch the
373+
; repo automatically if enabled
374+
AUTO_WATCH_NEW_REPOS = true
371375

372376
[webhook]
373377
; Hook task queue length, increase if webhook shooting starts hanging

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
207207
- `EMAIL_DOMAIN_WHITELIST`: **\<empty\>**: If non-empty, list of domain names that can only be used to register
208208
on this instance.
209209
- `SHOW_REGISTRATION_BUTTON`: **! DISABLE\_REGISTRATION**: Show Registration Button
210+
- `AUTO_WATCH_NEW_REPOS`: **true** Enable this to let all organisation users watch new repos when they are created
210211

211212
## Webhook (`webhook`)
212213

models/org_team.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"strings"
1212

1313
"code.gitea.io/gitea/modules/log"
14+
"code.gitea.io/gitea/modules/setting"
15+
1416
"github.com/go-xorm/xorm"
1517
)
1618

@@ -123,14 +125,18 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
123125
return fmt.Errorf("recalculateAccesses: %v", err)
124126
}
125127

126-
if err = t.getMembers(e); err != nil {
127-
return fmt.Errorf("getMembers: %v", err)
128-
}
129-
for _, u := range t.Members {
130-
if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
131-
return fmt.Errorf("watchRepo: %v", err)
128+
// Make all team members watch this repo if enabled in global settings
129+
if setting.Service.AutoWatchNewRepos {
130+
if err = t.getMembers(e); err != nil {
131+
return fmt.Errorf("getMembers: %v", err)
132+
}
133+
for _, u := range t.Members {
134+
if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
135+
return fmt.Errorf("watchRepo: %v", err)
136+
}
132137
}
133138
}
139+
134140
return nil
135141
}
136142

@@ -618,9 +624,10 @@ func AddTeamMember(team *Team, userID int64) error {
618624
if err := repo.recalculateTeamAccesses(sess, 0); err != nil {
619625
return err
620626
}
621-
622-
if err = watchRepo(sess, userID, repo.ID, true); err != nil {
623-
return err
627+
if setting.Service.AutoWatchNewRepos {
628+
if err = watchRepo(sess, userID, repo.ID, true); err != nil {
629+
return err
630+
}
624631
}
625632
}
626633

models/repo.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"github.com/Unknwon/com"
3535
"github.com/go-xorm/builder"
3636
"github.com/go-xorm/xorm"
37-
"github.com/mcuadros/go-version"
38-
"gopkg.in/ini.v1"
37+
version "github.com/mcuadros/go-version"
38+
ini "gopkg.in/ini.v1"
3939
)
4040

4141
var repoWorkingPool = sync.NewExclusivePool()
@@ -1353,9 +1353,12 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
13531353
}
13541354
}
13551355

1356-
if err = watchRepo(e, doer.ID, repo.ID, true); err != nil {
1357-
return fmt.Errorf("watchRepo: %v", err)
1358-
} else if err = newRepoAction(e, u, repo); err != nil {
1356+
if setting.Service.AutoWatchNewRepos {
1357+
if err = watchRepo(e, doer.ID, repo.ID, true); err != nil {
1358+
return fmt.Errorf("watchRepo: %v", err)
1359+
}
1360+
}
1361+
if err = newRepoAction(e, u, repo); err != nil {
13591362
return fmt.Errorf("newRepoAction: %v", err)
13601363
}
13611364

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ var Service struct {
12471247
DefaultAllowOnlyContributorsToTrackTime bool
12481248
NoReplyAddress string
12491249
EnableUserHeatmap bool
1250+
AutoWatchNewRepos bool
12501251

12511252
// OpenID settings
12521253
EnableOpenIDSignIn bool
@@ -1281,6 +1282,7 @@ func newService() {
12811282
Service.DefaultAllowOnlyContributorsToTrackTime = sec.Key("DEFAULT_ALLOW_ONLY_CONTRIBUTORS_TO_TRACK_TIME").MustBool(true)
12821283
Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")
12831284
Service.EnableUserHeatmap = sec.Key("ENABLE_USER_HEATMAP").MustBool(true)
1285+
Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true)
12841286

12851287
sec = Cfg.Section("openid")
12861288
Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)

0 commit comments

Comments
 (0)