You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

branches.go 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. // Copyright 2016 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "context"
  7. "fmt"
  8. "strings"
  9. "time"
  10. "code.gitea.io/gitea/modules/base"
  11. "code.gitea.io/gitea/modules/log"
  12. "code.gitea.io/gitea/modules/timeutil"
  13. "code.gitea.io/gitea/modules/util"
  14. "github.com/gobwas/glob"
  15. )
  16. // ProtectedBranch struct
  17. type ProtectedBranch struct {
  18. ID int64 `xorm:"pk autoincr"`
  19. RepoID int64 `xorm:"UNIQUE(s)"`
  20. BranchName string `xorm:"UNIQUE(s)"`
  21. CanPush bool `xorm:"NOT NULL DEFAULT false"`
  22. EnableWhitelist bool
  23. WhitelistUserIDs []int64 `xorm:"JSON TEXT"`
  24. WhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
  25. EnableMergeWhitelist bool `xorm:"NOT NULL DEFAULT false"`
  26. WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"`
  27. MergeWhitelistUserIDs []int64 `xorm:"JSON TEXT"`
  28. MergeWhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
  29. EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"`
  30. StatusCheckContexts []string `xorm:"JSON TEXT"`
  31. EnableApprovalsWhitelist bool `xorm:"NOT NULL DEFAULT false"`
  32. ApprovalsWhitelistUserIDs []int64 `xorm:"JSON TEXT"`
  33. ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
  34. RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"`
  35. BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"`
  36. BlockOnOfficialReviewRequests bool `xorm:"NOT NULL DEFAULT false"`
  37. BlockOnOutdatedBranch bool `xorm:"NOT NULL DEFAULT false"`
  38. DismissStaleApprovals bool `xorm:"NOT NULL DEFAULT false"`
  39. RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
  40. ProtectedFilePatterns string `xorm:"TEXT"`
  41. CreatedUnix timeutil.TimeStamp `xorm:"created"`
  42. UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
  43. }
  44. // IsProtected returns if the branch is protected
  45. func (protectBranch *ProtectedBranch) IsProtected() bool {
  46. return protectBranch.ID > 0
  47. }
  48. // CanUserPush returns if some user could push to this protected branch
  49. func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
  50. if !protectBranch.CanPush {
  51. return false
  52. }
  53. if !protectBranch.EnableWhitelist {
  54. if user, err := GetUserByID(userID); err != nil {
  55. log.Error("GetUserByID: %v", err)
  56. return false
  57. } else if repo, err := GetRepositoryByID(protectBranch.RepoID); err != nil {
  58. log.Error("GetRepositoryByID: %v", err)
  59. return false
  60. } else if writeAccess, err := HasAccessUnit(user, repo, UnitTypeCode, AccessModeWrite); err != nil {
  61. log.Error("HasAccessUnit: %v", err)
  62. return false
  63. } else {
  64. return writeAccess
  65. }
  66. }
  67. if base.Int64sContains(protectBranch.WhitelistUserIDs, userID) {
  68. return true
  69. }
  70. if len(protectBranch.WhitelistTeamIDs) == 0 {
  71. return false
  72. }
  73. in, err := IsUserInTeams(userID, protectBranch.WhitelistTeamIDs)
  74. if err != nil {
  75. log.Error("IsUserInTeams: %v", err)
  76. return false
  77. }
  78. return in
  79. }
  80. // IsUserMergeWhitelisted checks if some user is whitelisted to merge to this branch
  81. func (protectBranch *ProtectedBranch) IsUserMergeWhitelisted(userID int64, permissionInRepo Permission) bool {
  82. if !protectBranch.EnableMergeWhitelist {
  83. // Then we need to fall back on whether the user has write permission
  84. return permissionInRepo.CanWrite(UnitTypeCode)
  85. }
  86. if base.Int64sContains(protectBranch.MergeWhitelistUserIDs, userID) {
  87. return true
  88. }
  89. if len(protectBranch.MergeWhitelistTeamIDs) == 0 {
  90. return false
  91. }
  92. in, err := IsUserInTeams(userID, protectBranch.MergeWhitelistTeamIDs)
  93. if err != nil {
  94. log.Error("IsUserInTeams: %v", err)
  95. return false
  96. }
  97. return in
  98. }
  99. // IsUserOfficialReviewer check if user is official reviewer for the branch (counts towards required approvals)
  100. func (protectBranch *ProtectedBranch) IsUserOfficialReviewer(user *User) (bool, error) {
  101. return protectBranch.isUserOfficialReviewer(x, user)
  102. }
  103. func (protectBranch *ProtectedBranch) isUserOfficialReviewer(e Engine, user *User) (bool, error) {
  104. repo, err := getRepositoryByID(e, protectBranch.RepoID)
  105. if err != nil {
  106. return false, err
  107. }
  108. if !protectBranch.EnableApprovalsWhitelist {
  109. // Anyone with write access is considered official reviewer
  110. writeAccess, err := hasAccessUnit(e, user, repo, UnitTypeCode, AccessModeWrite)
  111. if err != nil {
  112. return false, err
  113. }
  114. return writeAccess, nil
  115. }
  116. if base.Int64sContains(protectBranch.ApprovalsWhitelistUserIDs, user.ID) {
  117. return true, nil
  118. }
  119. inTeam, err := isUserInTeams(e, user.ID, protectBranch.ApprovalsWhitelistTeamIDs)
  120. if err != nil {
  121. return false, err
  122. }
  123. return inTeam, nil
  124. }
  125. // HasEnoughApprovals returns true if pr has enough granted approvals.
  126. func (protectBranch *ProtectedBranch) HasEnoughApprovals(pr *PullRequest) bool {
  127. if protectBranch.RequiredApprovals == 0 {
  128. return true
  129. }
  130. return protectBranch.GetGrantedApprovalsCount(pr) >= protectBranch.RequiredApprovals
  131. }
  132. // GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist.
  133. func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(pr *PullRequest) int64 {
  134. sess := x.Where("issue_id = ?", pr.IssueID).
  135. And("type = ?", ReviewTypeApprove).
  136. And("official = ?", true).
  137. And("dismissed = ?", false)
  138. if protectBranch.DismissStaleApprovals {
  139. sess = sess.And("stale = ?", false)
  140. }
  141. approvals, err := sess.Count(new(Review))
  142. if err != nil {
  143. log.Error("GetGrantedApprovalsCount: %v", err)
  144. return 0
  145. }
  146. return approvals
  147. }
  148. // MergeBlockedByRejectedReview returns true if merge is blocked by rejected reviews
  149. func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(pr *PullRequest) bool {
  150. if !protectBranch.BlockOnRejectedReviews {
  151. return false
  152. }
  153. rejectExist, err := x.Where("issue_id = ?", pr.IssueID).
  154. And("type = ?", ReviewTypeReject).
  155. And("official = ?", true).
  156. And("dismissed = ?", false).
  157. Exist(new(Review))
  158. if err != nil {
  159. log.Error("MergeBlockedByRejectedReview: %v", err)
  160. return true
  161. }
  162. return rejectExist
  163. }
  164. // MergeBlockedByOfficialReviewRequests block merge because of some review request to official reviewer
  165. // of from official review
  166. func (protectBranch *ProtectedBranch) MergeBlockedByOfficialReviewRequests(pr *PullRequest) bool {
  167. if !protectBranch.BlockOnOfficialReviewRequests {
  168. return false
  169. }
  170. has, err := x.Where("issue_id = ?", pr.IssueID).
  171. And("type = ?", ReviewTypeRequest).
  172. And("official = ?", true).
  173. Exist(new(Review))
  174. if err != nil {
  175. log.Error("MergeBlockedByOfficialReviewRequests: %v", err)
  176. return true
  177. }
  178. return has
  179. }
  180. // MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch
  181. func (protectBranch *ProtectedBranch) MergeBlockedByOutdatedBranch(pr *PullRequest) bool {
  182. return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0
  183. }
  184. // GetProtectedFilePatterns parses a semicolon separated list of protected file patterns and returns a glob.Glob slice
  185. func (protectBranch *ProtectedBranch) GetProtectedFilePatterns() []glob.Glob {
  186. extarr := make([]glob.Glob, 0, 10)
  187. for _, expr := range strings.Split(strings.ToLower(protectBranch.ProtectedFilePatterns), ";") {
  188. expr = strings.TrimSpace(expr)
  189. if expr != "" {
  190. if g, err := glob.Compile(expr, '.', '/'); err != nil {
  191. log.Info("Invalid glob expresion '%s' (skipped): %v", expr, err)
  192. } else {
  193. extarr = append(extarr, g)
  194. }
  195. }
  196. }
  197. return extarr
  198. }
  199. // MergeBlockedByProtectedFiles returns true if merge is blocked by protected files change
  200. func (protectBranch *ProtectedBranch) MergeBlockedByProtectedFiles(pr *PullRequest) bool {
  201. glob := protectBranch.GetProtectedFilePatterns()
  202. if len(glob) == 0 {
  203. return false
  204. }
  205. return len(pr.ChangedProtectedFiles) > 0
  206. }
  207. // IsProtectedFile return if path is protected
  208. func (protectBranch *ProtectedBranch) IsProtectedFile(patterns []glob.Glob, path string) bool {
  209. if len(patterns) == 0 {
  210. patterns = protectBranch.GetProtectedFilePatterns()
  211. if len(patterns) == 0 {
  212. return false
  213. }
  214. }
  215. lpath := strings.ToLower(strings.TrimSpace(path))
  216. r := false
  217. for _, pat := range patterns {
  218. if pat.Match(lpath) {
  219. r = true
  220. break
  221. }
  222. }
  223. return r
  224. }
  225. // GetProtectedBranchBy getting protected branch by ID/Name
  226. func GetProtectedBranchBy(repoID int64, branchName string) (*ProtectedBranch, error) {
  227. return getProtectedBranchBy(x, repoID, branchName)
  228. }
  229. func getProtectedBranchBy(e Engine, repoID int64, branchName string) (*ProtectedBranch, error) {
  230. rel := &ProtectedBranch{RepoID: repoID, BranchName: branchName}
  231. has, err := e.Get(rel)
  232. if err != nil {
  233. return nil, err
  234. }
  235. if !has {
  236. return nil, nil
  237. }
  238. return rel, nil
  239. }
  240. // WhitelistOptions represent all sorts of whitelists used for protected branches
  241. type WhitelistOptions struct {
  242. UserIDs []int64
  243. TeamIDs []int64
  244. MergeUserIDs []int64
  245. MergeTeamIDs []int64
  246. ApprovalsUserIDs []int64
  247. ApprovalsTeamIDs []int64
  248. }
  249. // UpdateProtectBranch saves branch protection options of repository.
  250. // If ID is 0, it creates a new record. Otherwise, updates existing record.
  251. // This function also performs check if whitelist user and team's IDs have been changed
  252. // to avoid unnecessary whitelist delete and regenerate.
  253. func UpdateProtectBranch(repo *Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) {
  254. if err = repo.GetOwner(); err != nil {
  255. return fmt.Errorf("GetOwner: %v", err)
  256. }
  257. whitelist, err := updateUserWhitelist(repo, protectBranch.WhitelistUserIDs, opts.UserIDs)
  258. if err != nil {
  259. return err
  260. }
  261. protectBranch.WhitelistUserIDs = whitelist
  262. whitelist, err = updateUserWhitelist(repo, protectBranch.MergeWhitelistUserIDs, opts.MergeUserIDs)
  263. if err != nil {
  264. return err
  265. }
  266. protectBranch.MergeWhitelistUserIDs = whitelist
  267. whitelist, err = updateApprovalWhitelist(repo, protectBranch.ApprovalsWhitelistUserIDs, opts.ApprovalsUserIDs)
  268. if err != nil {
  269. return err
  270. }
  271. protectBranch.ApprovalsWhitelistUserIDs = whitelist
  272. // if the repo is in an organization
  273. whitelist, err = updateTeamWhitelist(repo, protectBranch.WhitelistTeamIDs, opts.TeamIDs)
  274. if err != nil {
  275. return err
  276. }
  277. protectBranch.WhitelistTeamIDs = whitelist
  278. whitelist, err = updateTeamWhitelist(repo, protectBranch.MergeWhitelistTeamIDs, opts.MergeTeamIDs)
  279. if err != nil {
  280. return err
  281. }
  282. protectBranch.MergeWhitelistTeamIDs = whitelist
  283. whitelist, err = updateTeamWhitelist(repo, protectBranch.ApprovalsWhitelistTeamIDs, opts.ApprovalsTeamIDs)
  284. if err != nil {
  285. return err
  286. }
  287. protectBranch.ApprovalsWhitelistTeamIDs = whitelist
  288. // Make sure protectBranch.ID is not 0 for whitelists
  289. if protectBranch.ID == 0 {
  290. if _, err = x.Insert(protectBranch); err != nil {
  291. return fmt.Errorf("Insert: %v", err)
  292. }
  293. return nil
  294. }
  295. if _, err = x.ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
  296. return fmt.Errorf("Update: %v", err)
  297. }
  298. return nil
  299. }
  300. // GetProtectedBranches get all protected branches
  301. func (repo *Repository) GetProtectedBranches() ([]*ProtectedBranch, error) {
  302. protectedBranches := make([]*ProtectedBranch, 0)
  303. return protectedBranches, x.Find(&protectedBranches, &ProtectedBranch{RepoID: repo.ID})
  304. }
  305. // GetBranchProtection get the branch protection of a branch
  306. func (repo *Repository) GetBranchProtection(branchName string) (*ProtectedBranch, error) {
  307. return GetProtectedBranchBy(repo.ID, branchName)
  308. }
  309. // IsProtectedBranch checks if branch is protected
  310. func (repo *Repository) IsProtectedBranch(branchName string, doer *User) (bool, error) {
  311. if doer == nil {
  312. return true, nil
  313. }
  314. protectedBranch := &ProtectedBranch{
  315. RepoID: repo.ID,
  316. BranchName: branchName,
  317. }
  318. has, err := x.Exist(protectedBranch)
  319. if err != nil {
  320. return true, err
  321. }
  322. return has, nil
  323. }
  324. // IsProtectedBranchForPush checks if branch is protected for push
  325. func (repo *Repository) IsProtectedBranchForPush(branchName string, doer *User) (bool, error) {
  326. if doer == nil {
  327. return true, nil
  328. }
  329. protectedBranch := &ProtectedBranch{
  330. RepoID: repo.ID,
  331. BranchName: branchName,
  332. }
  333. has, err := x.Get(protectedBranch)
  334. if err != nil {
  335. return true, err
  336. } else if has {
  337. return !protectedBranch.CanUserPush(doer.ID), nil
  338. }
  339. return false, nil
  340. }
  341. // updateApprovalWhitelist checks whether the user whitelist changed and returns a whitelist with
  342. // the users from newWhitelist which have explicit read or write access to the repo.
  343. func updateApprovalWhitelist(repo *Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) {
  344. hasUsersChanged := !util.IsSliceInt64Eq(currentWhitelist, newWhitelist)
  345. if !hasUsersChanged {
  346. return currentWhitelist, nil
  347. }
  348. whitelist = make([]int64, 0, len(newWhitelist))
  349. for _, userID := range newWhitelist {
  350. if reader, err := repo.IsReader(userID); err != nil {
  351. return nil, err
  352. } else if !reader {
  353. continue
  354. }
  355. whitelist = append(whitelist, userID)
  356. }
  357. return
  358. }
  359. // updateUserWhitelist checks whether the user whitelist changed and returns a whitelist with
  360. // the users from newWhitelist which have write access to the repo.
  361. func updateUserWhitelist(repo *Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) {
  362. hasUsersChanged := !util.IsSliceInt64Eq(currentWhitelist, newWhitelist)
  363. if !hasUsersChanged {
  364. return currentWhitelist, nil
  365. }
  366. whitelist = make([]int64, 0, len(newWhitelist))
  367. for _, userID := range newWhitelist {
  368. user, err := GetUserByID(userID)
  369. if err != nil {
  370. return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
  371. }
  372. perm, err := GetUserRepoPermission(repo, user)
  373. if err != nil {
  374. return nil, fmt.Errorf("GetUserRepoPermission [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
  375. }
  376. if !perm.CanWrite(UnitTypeCode) {
  377. continue // Drop invalid user ID
  378. }
  379. whitelist = append(whitelist, userID)
  380. }
  381. return
  382. }
  383. // updateTeamWhitelist checks whether the team whitelist changed and returns a whitelist with
  384. // the teams from newWhitelist which have write access to the repo.
  385. func updateTeamWhitelist(repo *Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) {
  386. hasTeamsChanged := !util.IsSliceInt64Eq(currentWhitelist, newWhitelist)
  387. if !hasTeamsChanged {
  388. return currentWhitelist, nil
  389. }
  390. teams, err := GetTeamsWithAccessToRepo(repo.OwnerID, repo.ID, AccessModeRead)
  391. if err != nil {
  392. return nil, fmt.Errorf("GetTeamsWithAccessToRepo [org_id: %d, repo_id: %d]: %v", repo.OwnerID, repo.ID, err)
  393. }
  394. whitelist = make([]int64, 0, len(teams))
  395. for i := range teams {
  396. if util.IsInt64InSlice(teams[i].ID, newWhitelist) {
  397. whitelist = append(whitelist, teams[i].ID)
  398. }
  399. }
  400. return
  401. }
  402. // DeleteProtectedBranch removes ProtectedBranch relation between the user and repository.
  403. func (repo *Repository) DeleteProtectedBranch(id int64) (err error) {
  404. protectedBranch := &ProtectedBranch{
  405. RepoID: repo.ID,
  406. ID: id,
  407. }
  408. sess := x.NewSession()
  409. defer sess.Close()
  410. if err = sess.Begin(); err != nil {
  411. return err
  412. }
  413. if affected, err := sess.Delete(protectedBranch); err != nil {
  414. return err
  415. } else if affected != 1 {
  416. return fmt.Errorf("delete protected branch ID(%v) failed", id)
  417. }
  418. return sess.Commit()
  419. }
  420. // DeletedBranch struct
  421. type DeletedBranch struct {
  422. ID int64 `xorm:"pk autoincr"`
  423. RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
  424. Name string `xorm:"UNIQUE(s) NOT NULL"`
  425. Commit string `xorm:"UNIQUE(s) NOT NULL"`
  426. DeletedByID int64 `xorm:"INDEX"`
  427. DeletedBy *User `xorm:"-"`
  428. DeletedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  429. }
  430. // AddDeletedBranch adds a deleted branch to the database
  431. func (repo *Repository) AddDeletedBranch(branchName, commit string, deletedByID int64) error {
  432. deletedBranch := &DeletedBranch{
  433. RepoID: repo.ID,
  434. Name: branchName,
  435. Commit: commit,
  436. DeletedByID: deletedByID,
  437. }
  438. sess := x.NewSession()
  439. defer sess.Close()
  440. if err := sess.Begin(); err != nil {
  441. return err
  442. }
  443. if _, err := sess.InsertOne(deletedBranch); err != nil {
  444. return err
  445. }
  446. return sess.Commit()
  447. }
  448. // GetDeletedBranches returns all the deleted branches
  449. func (repo *Repository) GetDeletedBranches() ([]*DeletedBranch, error) {
  450. deletedBranches := make([]*DeletedBranch, 0)
  451. return deletedBranches, x.Where("repo_id = ?", repo.ID).Desc("deleted_unix").Find(&deletedBranches)
  452. }
  453. // GetDeletedBranchByID get a deleted branch by its ID
  454. func (repo *Repository) GetDeletedBranchByID(id int64) (*DeletedBranch, error) {
  455. deletedBranch := &DeletedBranch{}
  456. has, err := x.ID(id).Get(deletedBranch)
  457. if err != nil {
  458. return nil, err
  459. }
  460. if !has {
  461. return nil, nil
  462. }
  463. return deletedBranch, nil
  464. }
  465. // RemoveDeletedBranch removes a deleted branch from the database
  466. func (repo *Repository) RemoveDeletedBranch(id int64) (err error) {
  467. deletedBranch := &DeletedBranch{
  468. RepoID: repo.ID,
  469. ID: id,
  470. }
  471. sess := x.NewSession()
  472. defer sess.Close()
  473. if err = sess.Begin(); err != nil {
  474. return err
  475. }
  476. if affected, err := sess.Delete(deletedBranch); err != nil {
  477. return err
  478. } else if affected != 1 {
  479. return fmt.Errorf("remove deleted branch ID(%v) failed", id)
  480. }
  481. return sess.Commit()
  482. }
  483. // LoadUser loads the user that deleted the branch
  484. // When there's no user found it returns a NewGhostUser
  485. func (deletedBranch *DeletedBranch) LoadUser() {
  486. user, err := GetUserByID(deletedBranch.DeletedByID)
  487. if err != nil {
  488. user = NewGhostUser()
  489. }
  490. deletedBranch.DeletedBy = user
  491. }
  492. // RemoveDeletedBranch removes all deleted branches
  493. func RemoveDeletedBranch(repoID int64, branch string) error {
  494. _, err := x.Where("repo_id=? AND name=?", repoID, branch).Delete(new(DeletedBranch))
  495. return err
  496. }
  497. // RemoveOldDeletedBranches removes old deleted branches
  498. func RemoveOldDeletedBranches(ctx context.Context, olderThan time.Duration) {
  499. // Nothing to do for shutdown or terminate
  500. log.Trace("Doing: DeletedBranchesCleanup")
  501. deleteBefore := time.Now().Add(-olderThan)
  502. _, err := x.Where("deleted_unix < ?", deleteBefore.Unix()).Delete(new(DeletedBranch))
  503. if err != nil {
  504. log.Error("DeletedBranchesCleanup: %v", err)
  505. }
  506. }