@@ -29,7 +29,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
2929 if count > 0 {
3030 if autofix {
3131 if err = models .DeleteOrphanedLabels (); err != nil {
32- logger .Critical ("Error: %v whilst deleting orphaned labels" )
32+ logger .Critical ("Error: %v whilst deleting orphaned labels" , err )
3333 return err
3434 }
3535 logger .Info ("%d labels without existing repository/organisation deleted" , count )
@@ -47,7 +47,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
4747 if count > 0 {
4848 if autofix {
4949 if err = models .DeleteOrphanedIssueLabels (); err != nil {
50- logger .Critical ("Error: %v whilst deleting orphaned issue_labels" )
50+ logger .Critical ("Error: %v whilst deleting orphaned issue_labels" , err )
5151 return err
5252 }
5353 logger .Info ("%d issue_labels without existing label deleted" , count )
@@ -65,7 +65,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
6565 if count > 0 {
6666 if autofix {
6767 if err = models .DeleteOrphanedIssues (); err != nil {
68- logger .Critical ("Error: %v whilst deleting orphaned issues" )
68+ logger .Critical ("Error: %v whilst deleting orphaned issues" , err )
6969 return err
7070 }
7171 logger .Info ("%d issues without existing repository deleted" , count )
@@ -83,7 +83,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
8383 if count > 0 {
8484 if autofix {
8585 if err = models .DeleteOrphanedObjects ("pull_request" , "issue" , "pull_request.issue_id=issue.id" ); err != nil {
86- logger .Critical ("Error: %v whilst deleting orphaned objects" )
86+ logger .Critical ("Error: %v whilst deleting orphaned objects" , err )
8787 return err
8888 }
8989 logger .Info ("%d pull requests without existing issue deleted" , count )
@@ -101,7 +101,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
101101 if count > 0 {
102102 if autofix {
103103 if err = models .DeleteOrphanedObjects ("tracked_time" , "issue" , "tracked_time.issue_id=issue.id" ); err != nil {
104- logger .Critical ("Error: %v whilst deleting orphaned objects" )
104+ logger .Critical ("Error: %v whilst deleting orphaned objects" , err )
105105 return err
106106 }
107107 logger .Info ("%d tracked times without existing issue deleted" , count )
@@ -120,7 +120,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
120120 if autofix {
121121 updatedCount , err := models .FixNullArchivedRepository ()
122122 if err != nil {
123- logger .Critical ("Error: %v whilst fixing null archived repositories" )
123+ logger .Critical ("Error: %v whilst fixing null archived repositories" , err )
124124 return err
125125 }
126126 logger .Info ("%d repositories with null is_archived updated" , updatedCount )
@@ -139,7 +139,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
139139 if autofix {
140140 updatedCount , err := models .FixCommentTypeLabelWithEmptyLabel ()
141141 if err != nil {
142- logger .Critical ("Error: %v whilst removing label comments with empty labels" )
142+ logger .Critical ("Error: %v whilst removing label comments with empty labels" , err )
143143 return err
144144 }
145145 logger .Info ("%d label comments with empty labels removed" , updatedCount )
@@ -197,7 +197,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
197197 if autofix {
198198 err := models .FixBadSequences ()
199199 if err != nil {
200- logger .Critical ("Error: %v whilst attempting to fix sequences" )
200+ logger .Critical ("Error: %v whilst attempting to fix sequences" , err )
201201 return err
202202 }
203203 logger .Info ("%d sequences updated" , count )
@@ -207,6 +207,24 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
207207 }
208208 }
209209
210+ // find protected branches without existing repository
211+ count , err = models .CountOrphanedObjects ("protected_branch" , "repository" , "protected_branch.repo_id=repository.id" )
212+ if err != nil {
213+ logger .Critical ("Error: %v whilst counting orphaned objects" )
214+ return err
215+ }
216+ if count > 0 {
217+ if autofix {
218+ if err = models .DeleteOrphanedObjects ("protected_branch" , "repository" , "protected_branch.repo_id=repository.id" ); err != nil {
219+ logger .Critical ("Error: %v whilst deleting orphaned objects" , err )
220+ return err
221+ }
222+ logger .Info ("%d protected branches without existing repository deleted" , count )
223+ } else {
224+ logger .Warn ("%d protected branches without existing repository" , count )
225+ }
226+ }
227+
210228 return nil
211229}
212230
0 commit comments