@@ -30,9 +30,9 @@ class Branch(models.Model):
30
30
pr_body = fields .Char ('Pr Body' )
31
31
pr_author = fields .Char ('Pr Author' )
32
32
33
- pull_head_name = fields .Char (compute = '_compute_branch_infos' , string = 'PR HEAD name' , readonly = True , store = True )
34
- pull_head_remote_id = fields .Many2one ('runbot.remote' , 'Pull head repository' , compute = '_compute_branch_infos' , store = True , index = True )
35
- target_branch_name = fields .Char (compute = '_compute_branch_infos' , string = 'PR target branch' , store = True )
33
+ pull_head_name = fields .Char (string = 'PR HEAD name' , readonly = True , store = True )
34
+ pull_head_remote_id = fields .Many2one ('runbot.remote' , 'Pull head repository' , store = True , index = True )
35
+ target_branch_name = fields .Char ( string = 'PR target branch' , store = True )
36
36
reviewers = fields .Char ('Reviewers' )
37
37
38
38
reflog_ids = fields .One2many ('runbot.ref.log' , 'branch_id' )
@@ -41,7 +41,7 @@ class Branch(models.Model):
41
41
dname = fields .Char ('Display name' , compute = '_compute_dname' , search = '_search_dname' )
42
42
43
43
alive = fields .Boolean ('Alive' , default = True )
44
- draft = fields .Boolean ('Draft' , compute = '_compute_branch_infos' , store = True )
44
+ draft = fields .Boolean ('Draft' , store = True )
45
45
46
46
@api .depends ('name' , 'remote_id.short_name' )
47
47
def _compute_dname (self ):
@@ -64,7 +64,7 @@ def _compute_reference_name(self):
64
64
- pull_head_name (organisation:branch_name) for external pr
65
65
"""
66
66
for branch in self :
67
- if branch .is_pr :
67
+ if branch .is_pr and branch . pull_head_name :
68
68
_ , name = branch .pull_head_name .split (':' )
69
69
if branch .pull_head_remote_id :
70
70
reference_name = name
@@ -79,8 +79,7 @@ def _compute_reference_name(self):
79
79
reference_name = f'{ forced_version .name } ---{ reference_name } '
80
80
branch .reference_name = reference_name
81
81
82
- @api .depends ('name' )
83
- def _compute_branch_infos (self , pull_info = None ):
82
+ def _update_branch_infos (self , pull_info = None ):
84
83
"""compute branch_url, pull_head_name and target_branch_name based on name"""
85
84
name_to_remote = {}
86
85
prs = self .filtered (lambda branch : branch .is_pr )
@@ -140,18 +139,15 @@ def _compute_branch_url(self):
140
139
else :
141
140
branch .branch_url = ''
142
141
143
- @api .depends ('reference_name' , 'remote_id.repo_id.project_id' )
144
- def _compute_bundle_id (self ):
142
+ def _update_bundle_id (self ):
145
143
for branch in self :
146
144
dummy = branch .remote_id .repo_id .project_id .dummy_bundle_id
147
- if branch .bundle_id == dummy :
148
- continue
149
145
name = branch .reference_name
150
146
project = branch .remote_id .repo_id .project_id or self .env .ref ('runbot.main_project' )
151
147
project .ensure_one ()
152
148
bundle = self .env ['runbot.bundle' ].search ([('name' , '=' , name ), ('project_id' , '=' , project .id )])
153
- need_new_base = not bundle and branch ._match_is_base (name )
154
- if ( bundle . is_base or need_new_base ) and branch .remote_id != branch .remote_id .repo_id .main_remote_id :
149
+ is_base = bundle . is_base if bundle else branch ._match_is_base (name )
150
+ if is_base and branch .remote_id != branch .remote_id .repo_id .main_remote_id :
155
151
_logger .warning ('Trying to add a dev branch to base bundle, falling back on dummy bundle' )
156
152
bundle = dummy
157
153
elif name and branch .remote_id and branch .remote_id .repo_id ._is_branch_forbidden (name ):
@@ -165,7 +161,7 @@ def _compute_bundle_id(self):
165
161
'name' : name ,
166
162
'project_id' : project .id ,
167
163
}
168
- if need_new_base :
164
+ if is_base :
169
165
values ['is_base' ] = True
170
166
171
167
if branch .is_pr and branch .target_branch_name : # most likely external_pr, use target as version
@@ -183,6 +179,8 @@ def _compute_bundle_id(self):
183
179
@api .model_create_multi
184
180
def create (self , value_list ):
185
181
branches = super ().create (value_list )
182
+ branches ._update_branch_infos ()
183
+ branches ._update_bundle_id ()
186
184
for branch in branches :
187
185
if branch .head :
188
186
self .env ['runbot.ref.log' ].create ({'commit_id' : branch .head .id , 'branch_id' : branch .id })
@@ -214,8 +212,9 @@ def _recompute_infos(self, payload=None):
214
212
was_draft = self .draft
215
213
was_alive = self .alive
216
214
init_target_branch_name = self .target_branch_name
217
- self ._compute_branch_infos (payload )
215
+ self ._update_branch_infos (payload )
218
216
if self .target_branch_name != init_target_branch_name :
217
+ #retarget
219
218
_logger .info ('retargeting %s to %s' , self .name , self .target_branch_name )
220
219
base = self .env ['runbot.bundle' ].search ([
221
220
('name' , '=' , self .target_branch_name ),
@@ -230,6 +229,10 @@ def _recompute_infos(self, payload=None):
230
229
if self .draft :
231
230
self .reviewers = '' # reset reviewers on draft
232
231
232
+ if not self .bundle_id :
233
+ self ._update_bundle_id ()
234
+ return
235
+
233
236
if was_alive and not self .alive and self .bundle_id .for_next_freeze :
234
237
if not any (branch .alive and branch .is_pr for branch in self .bundle_id .branch_ids ):
235
238
self .bundle_id .for_next_freeze = False
@@ -246,10 +249,13 @@ def _match_is_base(self, name):
246
249
regex = icp .get_param ('runbot.runbot_is_base_regex' , False )
247
250
if regex :
248
251
return re .match (regex , name )
249
-
252
+
250
253
def action_recompute_infos (self ):
251
254
return self ._recompute_infos ()
252
255
256
+ def action_update_bundle_id (self ):
257
+ return self ._update_bundle_ids ()
258
+
253
259
254
260
class RefLog (models .Model ):
255
261
_name = 'runbot.ref.log'
0 commit comments