Skip to content

Commit 92e4af3

Browse files
committed
Add support for posting the closure reason #349
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 41328aa commit 92e4af3

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

workflow/models.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,16 @@ class AbstractRequestEvent(HistoryDateFieldsMixin, DataspacedModel):
633633
class Meta:
634634
abstract = True
635635

636+
def save(self, *args, **kwargs):
637+
"""Call the handle_integrations method on save, only for addition."""
638+
is_addition = not self.pk
639+
super().save(*args, **kwargs)
640+
if is_addition:
641+
self.handle_integrations()
642+
643+
def handle_integrations(self):
644+
pass
645+
636646

637647
class RequestEvent(AbstractRequestEvent):
638648
request = models.ForeignKey(
@@ -662,6 +672,21 @@ class Meta:
662672
def __str__(self):
663673
return f"{self.get_event_type_display()} by {self.user.username}"
664674

675+
def handle_integrations(self):
676+
external_issue = self.request.external_issue
677+
if not external_issue:
678+
return
679+
680+
if not self.event_type == self.CLOSED:
681+
return
682+
683+
if external_issue.platform == ExternalIssueLink.Platform.GITHUB:
684+
GitHubIntegration(dataspace=self.dataspace).post_comment(
685+
repo_id=external_issue.repo,
686+
issue_id=external_issue.issue_id,
687+
comment_body=self.text,
688+
)
689+
665690

666691
class RequestComment(AbstractRequestEvent):
667692
request = models.ForeignKey(
@@ -677,13 +702,6 @@ class Meta:
677702
def __str__(self):
678703
return f"{self.user.username}: {self.text[:50]}..."
679704

680-
def save(self, *args, **kwargs):
681-
"""Call the handle_integrations method on save, only for addition."""
682-
is_addition = not self.pk
683-
super().save(*args, **kwargs)
684-
if is_addition:
685-
self.handle_integrations()
686-
687705
def has_delete_permission(self, user):
688706
"""
689707
Only the Commenter or an administrator with the proper permissions

0 commit comments

Comments
 (0)