Beispiel #1
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"]))
 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"])
Beispiel #3
0
    def test_does_not_add_warning_if_no_label(self, add_pr_comment_mock,
                                              edit_pr_title_mock):
        pull_request = build(builder.pull_request())

        github_logic.maybe_add_automerge_warning_comment(pull_request)

        add_pr_comment_mock.assert_not_called()
 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, ["*****@*****.**"])
 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_author_is_a_follower(self):
     pull_request = build(builder.pull_request().author(
         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"])
Beispiel #7
0
 def test_completed_is_false_if_pr_is_not_closed_but_still_merged(self):
     # this should be a totally illegal state that we received from GitHub, but it could theoretically exist due
     # to poorly implemented failure modes, concurrency issues, or data corruption due to errors
     pull_request = build(builder.pull_request().closed(False).merged(True))
     task_fields = src.asana.helpers.extract_task_fields_from_pull_request(
         pull_request)
     self.assertEqual(False, task_fields["completed"])
Beispiel #8
0
 def test_includes_asana_review_comment_author(self):
     github_review = build(builder.review().author(
         builder.user("github_test_user_login")).state(ReviewState.DEFAULT))
     asana_review_comment = src.asana.helpers.asana_comment_from_github_review(
         github_review)
     self.assertContainsStrings(asana_review_comment,
                                ["TEST_USER_ASANA_DOMAIN_USER_ID"])
Beispiel #9
0
 def test_html_body_assigns_to_first(self):
     pull_request = build(builder.pull_request().author(
         builder.user("github_test_user_login")).url(
             "https://foo.bar/baz").body("BODY").assignees([
                 builder.user("github_assignee_login_billy"),
                 builder.user("github_assignee_login_annie"),
             ]))
     task_fields = src.asana.helpers.extract_task_fields_from_pull_request(
         pull_request)
     actual = task_fields["html_notes"]
     expected_strings = [
         "<body>",
         "<em>",
         "This is a one-way sync from GitHub to Asana. Do not edit this task or comment on it!",
         "</em>",
         "\uD83D\uDD17",
         '<A href="https://foo.bar/baz">https://foo.bar/baz</A>',
         "✍",
         "TEST_USER_ASANA_DOMAIN_USER_ID",
         "first assignee alphabetically",
         "<strong>",
         "Description:",
         "</strong>",
         "BODY",
         "</body>",
     ]
     self.assertContainsStrings(actual, expected_strings)
Beispiel #10
0
 def test_individual_that_is_at_mentioned_in_pr_body_is_a_follower(self):
     pull_request = build(
         builder.pull_request().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"])
Beispiel #11
0
 def test_includes_link_to_review(self):
     url = "https://github.com/Asana/SGTM/pull/31#issuecomment-626850667"
     github_review = build(builder.review().state(
         ReviewState.DEFAULT).url(url))
     asana_review_comment = src.asana.helpers.asana_comment_from_github_review(
         github_review)
     self.assertContainsStrings(asana_review_comment, [f'<A href="{url}">'])
Beispiel #12
0
    def test_pull_request_with_label(self):
        label_name = "test label"
        pull_request = build(builder.pull_request().label(
            builder.label().name(label_name)))

        self.assertTrue(
            github_logic.pull_request_has_label(pull_request, label_name))
Beispiel #13
0
 def test_assignee_returns_author_when_assignees_are_empty(self):
     pull_request = build(builder.pull_request().author(
         builder.user("github_test_user_login")))
     task_fields = src.asana.helpers.extract_task_fields_from_pull_request(
         pull_request)
     self.assertEqual("TEST_USER_ASANA_DOMAIN_USER_ID",
                      task_fields["assignee"])
 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"])
Beispiel #15
0
 def test_assignee_returns_first_assignee_by_login_if_many(self):
     pull_request = build(builder.pull_request().assignees([
         builder.user("github_assignee_login_billy"),
         builder.user("github_assignee_login_annie"),
     ]))
     task_fields = src.asana.helpers.extract_task_fields_from_pull_request(
         pull_request)
     self.assertEqual("ANNIE_ASANA_DOMAIN_USER_ID", task_fields["assignee"])
 def test_is_pull_request_ready_for_automerge_after_tests_no_review(self):
     pull_request = build(builder.pull_request().commit(
         builder.commit().status(Commit.BUILD_SUCCESSFUL)
     ).title("blah blah [shipit]").mergeable(
         MergeableState.MERGEABLE).merged(False).label(builder.label().name(
             github_logic.AutomergeLabel.AFTER_TESTS_AND_APPROVAL.value)))
     self.assertFalse(
         github_logic._is_pull_request_ready_for_automerge(pull_request))
Beispiel #17
0
 def test_handles_at_sign_in_review_gracefully(self):
     github_review = build(builder.review().author(
         builder.user("github_unknown_user_login")).state(
             ReviewState.DEFAULT).body("*****@*****.**"))
     asana_review_comment = src.asana.helpers.asana_comment_from_github_review(
         github_review)
     self.assertContainsStrings(asana_review_comment,
                                ["*****@*****.**"])
Beispiel #18
0
 def test_transforms_github_at_mentions_to_asana_at_mentions(self):
     github_review = build(builder.review().author(
         builder.user("github_unknown_user_login")).state(
             ReviewState.DEFAULT).body("@github_test_user_login"))
     asana_review_comment = src.asana.helpers.asana_comment_from_github_review(
         github_review)
     self.assertContainsStrings(asana_review_comment,
                                ["TEST_USER_ASANA_DOMAIN_USER_ID"])
Beispiel #19
0
    def test_noop_if_feature_not_enabled(self, add_pr_comment_mock,
                                         edit_pr_title_mock):
        pull_request = build(builder.pull_request().label(builder.label().name(
            github_logic.AutomergeLabel.AFTER_TESTS_AND_APPROVAL.value)))

        github_logic.maybe_add_automerge_warning_comment(pull_request)

        add_pr_comment_mock.assert_not_called()
 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)])
Beispiel #21
0
 def test_handles_non_asana_review_comment_author_that_has_no_name_gracefully(
         self):
     github_review = build(builder.review().author(
         builder.user("github_unknown_user_login")).state(
             ReviewState.DEFAULT))
     asana_review_comment_comment = src.asana.helpers.asana_comment_from_github_review(
         github_review)
     self.assertContainsStrings(asana_review_comment_comment,
                                ["github_unknown_user_login"])
 def test_is_pull_request_ready_for_automerge_no_automerge_label(self):
     pull_request = build(builder.pull_request().commit(
         builder.commit().status(Commit.BUILD_SUCCESSFUL)).review(
             builder.review().submitted_at("2020-01-13T14:59:58Z").state(
                 ReviewState.APPROVED)).mergeable(
                     MergeableState.MERGEABLE).merged(False).label(
                         builder.label().name("random label")))
     self.assertFalse(
         github_logic._is_pull_request_ready_for_automerge(pull_request))
Beispiel #23
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_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_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 #26
0
    def test_does_not_add_warning_comment_if_label_does_not_require_approval(
            self, add_pr_comment_mock, edit_pr_title_mock):
        pull_request = build(builder.pull_request().title(
            self.SAMPLE_PR_TITLE).label(builder.label().name(
                github_logic.AutomergeLabel.AFTER_TESTS.value)))

        github_logic.maybe_add_automerge_warning_comment(pull_request)

        add_pr_comment_mock.assert_not_called()
Beispiel #27
0
 def test_noop_if_no_task_ids_to_complete(
     self,
     should_autocomplete_tasks_on_merge_mock,
     get_linked_task_ids_mock,
     complete_task_mock,
 ):
     get_linked_task_ids_mock.return_value = []
     pull_request = build(builder.pull_request().merged(True))
     controller.maybe_complete_tasks_on_merge(pull_request)
     complete_task_mock.assert_not_called()
 def test_is_pull_request_ready_for_automerge_immediately_conflicting(self):
     pull_request = build(builder.pull_request().commit(
         builder.commit().status(Commit.BUILD_FAILED)).review(
             builder.review().submitted_at("2020-01-13T14:59:58Z").state(
                 ReviewState.CHANGES_REQUESTED)).mergeable(
                     MergeableState.CONFLICTING).merged(False).label(
                         builder.label().name(github_logic.AutomergeLabel.
                                              IMMEDIATELY.value)))
     self.assertFalse(
         github_logic._is_pull_request_ready_for_automerge(pull_request))
Beispiel #29
0
 def test_completed_handles_gracefully_if_pr_is_closed_and_pr_was_approved_before_merging_with_merged_glitch(
     self, ):
     pull_request = build(builder.pull_request().closed(True).merged(
         False).merged_at("2020-01-13T14:59:58Z").reviews([
             builder.review().submitted_at("2020-01-13T14:59:59Z").state(
                 ReviewState.APPROVED)
         ]))
     task_fields = src.asana.helpers.extract_task_fields_from_pull_request(
         pull_request)
     self.assertEqual(True, task_fields["completed"])
Beispiel #30
0
 def test_reviewer_is_a_follower(self):
     pull_request = build(builder.pull_request().reviews([
         builder.review().submitted_at("2020-02-13T14:59:57Z").state(
             ReviewState.CHANGES_REQUESTED).body("LGTM!").author(
                 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"])