def test_pull_request_commenters(self):
     pull_request = build(builder.pull_request().comments([
         builder.comment().author(builder.user().login("foo")),
         builder.comment().author(builder.user().login("bar")),
     ]))
     self.assertEqual(
         github_logic._pull_request_commenters(pull_request),
         ["bar", "foo"],  # sorted
     )
 def test_pull_request_comment_mentions(self):
     pull_request = build(builder.pull_request().comments([
         builder.comment(""),
         builder.comment("@one @two @three"),
         builder.comment("@four"),
     ]))
     self.assertEqual(
         github_logic._pull_request_comment_mentions(pull_request),
         ["one", "two", "three", "four"],
     )
 def test_pull_request_review_mentions(self):
     pull_request = build(builder.pull_request().reviews([
         builder.review("").comments([
             builder.comment("@one @two @three"),
             builder.comment("@four")
         ]),
         builder.review("@a @b @c").comments(
             [builder.comment(""),
              builder.comment("@five")]),
     ]))
     self.assertEqual(
         sorted(github_logic._pull_request_review_mentions(pull_request)),
         ["a", "b", "c", "five", "four", "one", "three", "two"],
     )
 def test_includes_asana_comment_author(self):
     github_comment = build(builder.comment().author(
         builder.user("github_test_user_login")))
     asana_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_comment)
     self.assertContainsStrings(asana_comment,
                                ["TEST_USER_ASANA_DOMAIN_USER_ID"])
 def test_includes_comment_text(self):
     github_comment = build(builder.comment().author(
         builder.user("github_unknown_user_login")).body(
             "GITHUB_COMMENT_TEXT"))
     asana_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_comment)
     self.assertContainsStrings(asana_comment, ["GITHUB_COMMENT_TEXT"])
Beispiel #6
0
 def test_individual_that_is_at_mentioned_in_comments_is_a_follower(self):
     pull_request = build(builder.pull_request().comments(
         [builder.comment().body("@github_test_user_login")]))
     task_fields = src.asana.helpers.extract_task_fields_from_pull_request(
         pull_request)
     self.assertIn("TEST_USER_ASANA_DOMAIN_USER_ID",
                   task_fields["followers"])
 def test_handles_at_sign_in_comment_gracefully(self):
     github_comment = build(builder.comment().author(
         builder.user("github_unknown_user_login")).body(
             "*****@*****.**"))
     asana_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_comment)
     self.assertContainsStrings(asana_comment, ["*****@*****.**"])
Beispiel #8
0
 def test_includes_link_to_comment(self):
     url = "https://github.com/Asana/SGTM/pull/31#issuecomment-626850667"
     github_review = build(builder.review().state(
         ReviewState.DEFAULT).comment(builder.comment().url(url)))
     asana_review_comment = src.asana.helpers.asana_comment_from_github_review(
         github_review)
     self.assertContainsStrings(asana_review_comment, [f'<A href="{url}">'])
 def test_handles_non_asana_comment_author_that_has_no_name_gracefully(
         self):
     github_comment = build(builder.comment().author(
         builder.user("github_unknown_user_login")))
     asana_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_comment)
     self.assertContainsStrings(asana_comment,
                                ["github_unknown_user_login"])
 def test_transforms_github_at_mentions_to_asana_at_mentions(self):
     github_comment = build(builder.comment().author(
         builder.user("github_unknown_user_login")).body(
             "@github_test_user_login"))
     asana_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_comment)
     self.assertContainsStrings(asana_comment,
                                ["TEST_USER_ASANA_DOMAIN_USER_ID"])
Beispiel #11
0
 def test_requested_reviewer_is_a_follower(self):
     pull_request = build(builder.pull_request().comments([
         builder.comment().published_at("2020-01-13T14:59:58Z").body(
             "LGTM!"),
     ]).requested_reviewers([builder.user("github_test_user_login")]))
     task_fields = src.asana.helpers.extract_task_fields_from_pull_request(
         pull_request)
     self.assertIn("TEST_USER_ASANA_DOMAIN_USER_ID",
                   task_fields["followers"])
 def test_transforms_urls_from_comment_tect(self):
     url = "https://www.foo.bar/?a=1&b=2"
     github_comment = build(builder.comment().author(
         builder.user("github_unknown_user_login")).body(
             "Can you refer to the documentation at {}".format(url)))
     asana_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_comment)
     self.assertContainsStrings(
         asana_comment, ['<a href="{}">{}</a>'.format(escape(url), url)])
 def test_handles_non_asana_comment_author_gracefully(self):
     github_comment = build(builder.comment().author(
         builder.user("github_unknown_user_login",
                      "GITHUB_UNKNOWN_USER_NAME")))
     asana_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_comment)
     self.assertContainsStrings(
         asana_comment,
         ["github_unknown_user_login", "GITHUB_UNKNOWN_USER_NAME"])
Beispiel #14
0
 def test_includes_review_text(self):
     github_review = build(builder.review().author(
         builder.user("github_unknown_user_login")).state(
             ReviewState.DEFAULT).body("GITHUB_REVIEW_TEXT").comment(
                 builder.comment().body("GITHUB_REVIEW_COMMENT_TEXT")))
     asana_review_comment = src.asana.helpers.asana_comment_from_github_review(
         github_review)
     self.assertContainsStrings(
         asana_review_comment,
         ["GITHUB_REVIEW_TEXT", "GITHUB_REVIEW_COMMENT_TEXT"])
 def test_pull_request_approved_after_merging_review_that_had_approval(
         self):
     merged_at = datetime.now()
     reviewed_at = merged_at + timedelta(days=1)
     commented_at = merged_at + timedelta(days=2)
     pull_request = build(builder.pull_request().merged_at(
         datetime.now()).reviews([
             builder.review("This looks OK").submitted_at(reviewed_at)
         ]).comments([builder.comment("SGTM!").published_at(commented_at)]))
     self.assertTrue(
         github_logic.pull_request_approved_after_merging(pull_request))
 def test_considers_double_quotes_safe_in_comment_text(self):
     github_author = builder.user("github_unknown_user_login")
     placeholder = "💣"
     github_placeholder_comment = build(
         builder.comment().body(placeholder).author(github_author))
     asana_placeholder_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_placeholder_comment)
     safe_characters = ['"', "'"]
     for safe_character in safe_characters:
         github_comment = build(
             builder.comment().body(safe_character).author(github_author))
         asana_comment = src.asana.helpers.asana_comment_from_github_comment(
             github_comment)
         expected = asana_placeholder_comment.replace(
             placeholder, safe_character)
         self.assertEqual(
             asana_comment,
             expected,
             f"Did not expected the {safe_character} character to be escaped",
         )
 def test_does_not_inject_unsafe_html(self):
     placeholder = "💣"
     github_placeholder_comment = build(builder.comment().author(
         builder.user("github_unknown_user_login")).body(placeholder))
     asana_placeholder_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_placeholder_comment)
     unsafe_characters = ["&", "<", ">"]
     for unsafe_character in unsafe_characters:
         github_comment = build(builder.comment().author(
             builder.user("github_unknown_user_login")).body(
                 unsafe_character))
         asana_comment = src.asana.helpers.asana_comment_from_github_comment(
             github_comment)
         unexpected = asana_placeholder_comment.replace(
             placeholder, unsafe_character)
         self.assertNotEqual(
             asana_comment,
             unexpected,
             f"Expected the {unsafe_character} character to be escaped",
         )
Beispiel #18
0
    def test_does_not_add_warning_if_has_label_and_already_has_warning_in_comments(
            self, add_pr_comment_mock, edit_pr_title_mock):
        pull_request = build(builder.pull_request().comments([
            builder.comment().author(
                builder.user("github_unknown_user_login")).body(
                    github_logic.AUTOMERGE_COMMENT_WARNING)
        ]).label(builder.label().name(
            github_logic.AutomergeLabel.AFTER_TESTS_AND_APPROVAL.value)))

        github_logic.maybe_add_automerge_warning_comment(pull_request)

        edit_pr_title_mock.assert_not_called()
        add_pr_comment_mock.assert_not_called()
Beispiel #19
0
 def test_completed_is_false_if_pr_was_merged_and_changes_requested_and_commented_lgtm_on_the_pr_before_merge(
     self, ):
     pull_request = build(builder.pull_request().closed(True).merged(
         True).merged_at("2020-01-13T14:59:59Z").reviews([
             builder.review().submitted_at("2020-01-13T14:59:57Z").state(
                 ReviewState.CHANGES_REQUESTED)
         ]).comments([
             builder.comment().published_at("2020-01-13T14:59:58Z").body(
                 "LGTM!")
         ]))
     task_fields = src.asana.helpers.extract_task_fields_from_pull_request(
         pull_request)
     self.assertEqual(False, task_fields["completed"])
Beispiel #20
0
 def test_considers_double_quotes_safe_in_review_text(self):
     placeholder = "💣"
     github_placeholder_review = build(builder.review().author(
         builder.user("github_unknown_user_login")).state(
             ReviewState.DEFAULT).body(placeholder).comment(
                 builder.comment().body(placeholder)))
     asana_placeholder_review = src.asana.helpers.asana_comment_from_github_review(
         github_placeholder_review)
     safe_characters = ['"', "'"]
     for safe_character in safe_characters:
         github_review = build(builder.review().author(
             builder.user("github_unknown_user_login")).state(
                 ReviewState.DEFAULT).body(safe_character).comment(
                     builder.comment().body(safe_character)))
         asana_review_comment = src.asana.helpers.asana_comment_from_github_review(
             github_review)
         expected = asana_placeholder_review.replace(
             placeholder, safe_character)
         self.assertEqual(
             asana_review_comment,
             expected,
             f"Did not expected the {safe_character} character to be escaped",
         )
Beispiel #21
0
 def test_converts_urls_to_links(self):
     github_review = build(builder.review().author(
         builder.user("github_unknown_user_login")).state(
             ReviewState.DEFAULT).body("https://www.asana.com").comment(
                 builder.comment().body("http://www.foo.com")))
     asana_review_comment = src.asana.helpers.asana_comment_from_github_review(
         github_review)
     self.assertContainsStrings(
         asana_review_comment,
         [
             '<a href="{}">{}</a>'.format(url, url)
             for url in ["https://www.asana.com", "http://www.foo.com"]
         ],
     )
Beispiel #22
0
 def test_non_asana_user_is_not_a_follower(self):
     unknown_github_user = build(
         builder.user("github_unknown_user_login",
                      "GITHUB_UNKNOWN_USER_NAME"))
     pull_request = build(
         builder.pull_request().body("@github_unknown_user_login").
         author(unknown_github_user).assignee(unknown_github_user).review(
             builder.review().body("@github_unknown_user_login").author(
                 unknown_github_user)).comment(
                     builder.comment().body("@github_unknown_user_login").
                     author(unknown_github_user)).requested_reviewer(
                         unknown_github_user))
     task_fields = src.asana.helpers.extract_task_fields_from_pull_request(
         pull_request)
     self.assertEqual(0, len(task_fields["followers"]))
Beispiel #23
0
    def test_upsert_comment_when_task_id_already_found_in_dynamodb(
            self, add_comment_mock, update_task_mock):
        # If the task id is found in dynamodb, then we just update (don't
        # attempt to create)
        pull_request = builder.pull_request().build()
        comment = builder.comment().build()

        # Insert the mapping first
        existing_task_id = uuid4().hex
        dynamodb_client.insert_github_node_to_asana_id_mapping(
            pull_request.id(), existing_task_id)

        github_controller.upsert_comment(pull_request, comment)

        add_comment_mock.assert_called_with(comment, existing_task_id)
        update_task_mock.assert_called_with(pull_request, existing_task_id)
    def test_pull_request_approved_after_merging_reviews_and_comments_no_approvals(
        self, ):
        # The PR has reviews and comments, but neither have approval messages

        merged_at = datetime.now()
        reviewed_at = merged_at + timedelta(days=1)
        commented_at = merged_at + timedelta(days=2)
        pull_request = build(builder.pull_request().merged_at(
            datetime.now()).reviews([
                builder.review("This looks OK").submitted_at(reviewed_at)
            ]).comments([
                builder.comment("v cool use of emojis").published_at(
                    commented_at)
            ]))
        self.assertFalse(
            github_logic.pull_request_approved_after_merging(pull_request))
Beispiel #25
0
 def test_handles_no_review_text(self):
     github_review = build(builder.review().author(
         builder.user("github_unknown_user_login")).state(
             ReviewState.APPROVED).body("").comment(
                 builder.comment().body("GITHUB_REVIEW_COMMENT_TEXT")))
     asana_review_comment = src.asana.helpers.asana_comment_from_github_review(
         github_review)
     self.assertContainsStrings(
         asana_review_comment,
         [
             "GitHub user 'github_unknown_user_login'",
             "approved",
             "and left inline comments:",
             "GITHUB_REVIEW_COMMENT_TEXT",
         ],
     )
 def test_includes_url_in_comment(self):
     url = "https://github.com/Asana/SGTM/pull/31#issuecomment-626850667"
     github_comment = build(builder.comment().url(url))
     asana_comment = src.asana.helpers.asana_comment_from_github_comment(
         github_comment)
     self.assertContainsStrings(asana_comment, [f'<A href="{url}">'])
Beispiel #27
0
    def test_upsert_comment_when_task_id_not_found_in_dynamodb(
            self, add_comment_mock, update_task_mock):
        pull_request = builder.pull_request().build()
        comment = builder.comment().build()

        github_controller.upsert_comment(pull_request, comment)