@@ -29,7 +29,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
29
29
if count > 0 {
30
30
if autofix {
31
31
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 )
33
33
return err
34
34
}
35
35
logger .Info ("%d labels without existing repository/organisation deleted" , count )
@@ -47,7 +47,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
47
47
if count > 0 {
48
48
if autofix {
49
49
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 )
51
51
return err
52
52
}
53
53
logger .Info ("%d issue_labels without existing label deleted" , count )
@@ -65,7 +65,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
65
65
if count > 0 {
66
66
if autofix {
67
67
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 )
69
69
return err
70
70
}
71
71
logger .Info ("%d issues without existing repository deleted" , count )
@@ -83,7 +83,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
83
83
if count > 0 {
84
84
if autofix {
85
85
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 )
87
87
return err
88
88
}
89
89
logger .Info ("%d pull requests without existing issue deleted" , count )
@@ -101,7 +101,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
101
101
if count > 0 {
102
102
if autofix {
103
103
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 )
105
105
return err
106
106
}
107
107
logger .Info ("%d tracked times without existing issue deleted" , count )
@@ -120,7 +120,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
120
120
if autofix {
121
121
updatedCount , err := models .FixNullArchivedRepository ()
122
122
if err != nil {
123
- logger .Critical ("Error: %v whilst fixing null archived repositories" )
123
+ logger .Critical ("Error: %v whilst fixing null archived repositories" , err )
124
124
return err
125
125
}
126
126
logger .Info ("%d repositories with null is_archived updated" , updatedCount )
@@ -139,7 +139,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
139
139
if autofix {
140
140
updatedCount , err := models .FixCommentTypeLabelWithEmptyLabel ()
141
141
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 )
143
143
return err
144
144
}
145
145
logger .Info ("%d label comments with empty labels removed" , updatedCount )
@@ -197,7 +197,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
197
197
if autofix {
198
198
err := models .FixBadSequences ()
199
199
if err != nil {
200
- logger .Critical ("Error: %v whilst attempting to fix sequences" )
200
+ logger .Critical ("Error: %v whilst attempting to fix sequences" , err )
201
201
return err
202
202
}
203
203
logger .Info ("%d sequences updated" , count )
@@ -207,6 +207,24 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
207
207
}
208
208
}
209
209
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
+
210
228
return nil
211
229
}
212
230
0 commit comments