mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Supports wildcard protected branch (#20825)
This PR introduce glob match for protected branch name. The separator is `/` and you can use `*` matching non-separator chars and use `**` across separator. It also supports input an exist or non-exist branch name as matching condition and branch name condition has high priority than glob rule. Should fix #2529 and #15705 screenshots <img width="1160" alt="image" src="https://user-images.githubusercontent.com/81045/205651179-ebb5492a-4ade-4bb4-a13c-965e8c927063.png"> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		@@ -378,7 +378,6 @@ func DeleteTeam(t *organization.Team) error {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	defer committer.Close()
 | 
			
		||||
	sess := db.GetEngine(ctx)
 | 
			
		||||
 | 
			
		||||
	if err := t.LoadRepositories(ctx); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
@@ -391,27 +390,15 @@ func DeleteTeam(t *organization.Team) error {
 | 
			
		||||
	// update branch protections
 | 
			
		||||
	{
 | 
			
		||||
		protections := make([]*git_model.ProtectedBranch, 0, 10)
 | 
			
		||||
		err := sess.In("repo_id",
 | 
			
		||||
		err := db.GetEngine(ctx).In("repo_id",
 | 
			
		||||
			builder.Select("id").From("repository").Where(builder.Eq{"owner_id": t.OrgID})).
 | 
			
		||||
			Find(&protections)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("findProtectedBranches: %w", err)
 | 
			
		||||
		}
 | 
			
		||||
		for _, p := range protections {
 | 
			
		||||
			lenIDs, lenApprovalIDs, lenMergeIDs := len(p.WhitelistTeamIDs), len(p.ApprovalsWhitelistTeamIDs), len(p.MergeWhitelistTeamIDs)
 | 
			
		||||
			p.WhitelistTeamIDs = util.SliceRemoveAll(p.WhitelistTeamIDs, t.ID)
 | 
			
		||||
			p.ApprovalsWhitelistTeamIDs = util.SliceRemoveAll(p.ApprovalsWhitelistTeamIDs, t.ID)
 | 
			
		||||
			p.MergeWhitelistTeamIDs = util.SliceRemoveAll(p.MergeWhitelistTeamIDs, t.ID)
 | 
			
		||||
			if lenIDs != len(p.WhitelistTeamIDs) ||
 | 
			
		||||
				lenApprovalIDs != len(p.ApprovalsWhitelistTeamIDs) ||
 | 
			
		||||
				lenMergeIDs != len(p.MergeWhitelistTeamIDs) {
 | 
			
		||||
				if _, err = sess.ID(p.ID).Cols(
 | 
			
		||||
					"whitelist_team_i_ds",
 | 
			
		||||
					"merge_whitelist_team_i_ds",
 | 
			
		||||
					"approvals_whitelist_team_i_ds",
 | 
			
		||||
				).Update(p); err != nil {
 | 
			
		||||
					return fmt.Errorf("updateProtectedBranches: %w", err)
 | 
			
		||||
				}
 | 
			
		||||
			if err := git_model.RemoveTeamIDFromProtectedBranch(ctx, p, t.ID); err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -432,7 +419,7 @@ func DeleteTeam(t *organization.Team) error {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Update organization number of teams.
 | 
			
		||||
	if _, err := sess.Exec("UPDATE `user` SET num_teams=num_teams-1 WHERE id=?", t.OrgID); err != nil {
 | 
			
		||||
	if _, err := db.Exec(ctx, "UPDATE `user` SET num_teams=num_teams-1 WHERE id=?", t.OrgID); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user