Esempio n. 1
0
 def test_comment_no_bridged_email(self):
     """Assert if no merge request is recorded as bridged, we email nothing."""
     gitlab2email.email_comment(
         self.gitlab,
         self.forge.forge_id,
         self.comment_on_mr_payload["user"],
         self.comment_on_mr_payload["object_attributes"],
         1,
     )
     self.assertEqual(0, len(mail.outbox))
Esempio n. 2
0
    def test_inline_code_comment_email(self):
        """Assert comments bridged MRs are emailed."""
        submission = pw_models.Submission.objects.first()
        models.BridgedSubmission.objects.create(git_forge=self.forge,
                                                merge_request=42,
                                                submission=submission)
        expected_body = (
            "From: Administrator on gitlab\n"
            "https://gitlab/root/patchlab_test/merge_requests/1#note_3\n\n"
            "This change in particular, I don't like it.\n")

        gitlab2email.email_comment(
            self.gitlab,
            self.forge.forge_id,
            self.inline_code_comment_payload["user"],
            self.inline_code_comment_payload["object_attributes"],
            42,
        )

        self.assertEqual(1, len(mail.outbox))
        self.assertEqual(expected_body, mail.outbox[0].body)
Esempio n. 3
0
    def test_comment_on_mr_email(self):
        """Assert comments bridged MRs are emailed."""
        submission = pw_models.Submission.objects.first()
        models.BridgedSubmission.objects.create(git_forge=self.forge,
                                                merge_request=42,
                                                submission=submission)
        expected_body = (
            "From: Administrator on gitlab\n"
            "https://gitlab/root/patchlab_test/merge_requests/1#note_2\n\n"
            "Not great, not terrible.\n")

        gitlab2email.email_comment(
            self.gitlab,
            self.forge.forge_id,
            self.comment_on_mr_payload["user"],
            self.comment_on_mr_payload["object_attributes"],
            42,
        )

        self.assertEqual(1, len(mail.outbox))
        self.assertEqual(expected_body, mail.outbox[0].body)
Esempio n. 4
0
def email_comment(
    gitlab_host: str,
    project_id: int,
    comment_author,
    comment,
    merge_id=None,
):
    try:
        gitlab = gitlab_module.Gitlab.from_config(gitlab_host)
    except gitlab_module.config.ConfigError:
        _log.error("Missing Gitlab configuration for %s", gitlab_host)
        return
    try:
        gitlab.auth()
        if gitlab.user.username != comment_author["username"]:
            gitlab2email.email_comment(gitlab, project_id, comment_author,
                                       comment, merge_id)
        else:
            _log.info("Ignoring comment posted by the bridge user.")
    except Exception as e:
        _log.warning("Failed to send gitlab comment as email, retrying...")
        raise merge_request_hook.retry(exc=e, throw=False, countdown=60)
Esempio n. 5
0
    def test_comment_on_commit_email(self):
        """Assert comments bridged MRs are emailed."""
        submission = pw_models.Submission.objects.first()
        models.BridgedSubmission.objects.create(
            git_forge=self.forge,
            merge_request=42,
            submission=submission,
            commit="2311157d92dc85e012342cd07c503ee397af2f1e",
        )
        expected_body = ("From: Administrator on gitlab\n"
                         "https://gitlab/root/patchlab_test/commit/"
                         "2311157d92dc85e012342cd07c503ee397af2f1e#note_4\n\n"
                         "Here's a comment on a commit\n")

        gitlab2email.email_comment(
            self.gitlab,
            self.forge.forge_id,
            self.comment_on_commit_payload["user"],
            self.comment_on_commit_payload["object_attributes"],
            42,
        )

        self.assertEqual(1, len(mail.outbox))
        self.assertEqual(expected_body, mail.outbox[0].body)