@@ -295,16 +295,14 @@ def html_url(self):
295295 return None
296296
297297 def get (self ):
298- if not self .id :
299- raise Exception ("'id' must be set to get a comment." )
298+ self ._require_id ()
300299 self ._comment_obj = retry_call (self ._pr_obj .get_issue_comment , fargs = [self .id ],
301300 exceptions = Exception , tries = 5 , delay = 1 , backoff = 2 , max_delay = 30 )
302301 if self ._comment_obj :
303302 self .body = self ._comment_obj .body
304303
305304 def create (self ):
306- if not self .body :
307- raise Exception ("'body' must be set to create a comment." )
305+ self ._require_body ()
308306 if self .id :
309307 # Safeguard: id should not be set when body is initialized, but guard
310308 # against accidental duplicate comments if id was set after initialization.
@@ -315,8 +313,7 @@ def create(self):
315313 self .id = self ._comment_obj .id
316314
317315 def edit (self , new_body ):
318- if not self .id :
319- raise Exception ("'id' must be set to edit a comment." )
316+ self ._require_id ()
320317 # Ensure comment object is present
321318 if not self ._comment_obj :
322319 self .get ()
@@ -325,8 +322,7 @@ def edit(self, new_body):
325322 tries = 5 , delay = 1 , backoff = 2 , max_delay = 30 )
326323
327324 def append (self , text_to_append ):
328- if not self .id :
329- raise Exception ("'id' must be set to append to a comment." )
325+ self ._require_id ()
330326 # Ensure comment object is present and up to date
331327 self .get ()
332328 self .edit (self .body + text_to_append )
@@ -350,14 +346,12 @@ def html_url(self):
350346 return None
351347
352348 def get (self ):
353- if not self .id :
354- raise Exception ("'id' must be set to get a comment." )
349+ self ._require_id ()
355350 self ._comment_obj = self ._pr_obj .notes .get (self .id )
356351 self .body = self ._comment_obj .body
357352
358353 def create (self ):
359- if not self .body :
360- raise Exception ("'body' must be set to create a comment." )
354+ self ._require_body ()
361355 if self .id :
362356 # Safeguard: id should not be set when body is initialized, but guard
363357 # against accidental duplicate comments if id was set after initialization.
@@ -367,8 +361,7 @@ def create(self):
367361 self .id = self ._comment_obj .id
368362
369363 def edit (self , new_body ):
370- if not self .id :
371- raise Exception ("'id' must be set to edit a comment." )
364+ self ._require_id ()
372365 # Ensure comment object is present
373366 if not self ._comment_obj :
374367 self .get ()
@@ -377,8 +370,7 @@ def edit(self, new_body):
377370 self ._comment_obj .save ()
378371
379372 def append (self , text_to_append ):
380- if not self .id :
381- raise Exception ("'id' must be set to append to a comment." )
373+ self ._require_id ()
382374 # Ensure comment object and body are present and up to date
383375 self .get ()
384376 self .edit (self .body + text_to_append )
0 commit comments