Exemple #1
0
    def test_close_keep_open_label(self):

        # Time is beyond close deadline, and there is no comment yet but there
        # is a keep-open label so don't do anything.

        self.open_pull_requests.return_value = ['123']
        self.last_commit_date.return_value = now() - 241
        self.last_comment_date.return_value = None
        self.find_comments.return_value = []
        self.labels.return_value = ['keep-open']

        process_pull_requests('repo',
                              'installation',
                              warn_seconds=220,
                              close_seconds=20)

        assert self.submit_comment.call_count == 0
Exemple #2
0
    def test_keep_open(self):

        # Time is before warn deadline so don't do anything.

        self.open_pull_requests.return_value = ['123']
        self.last_commit_date.return_value = now() - 210
        self.last_comment_date.return_value = None
        self.find_comments.return_value = []

        process_pull_requests('repo',
                              'installation',
                              warn_seconds=220,
                              close_seconds=20)

        assert self.find_comments.call_count == 0
        assert self.submit_comment.call_count == 0
        assert self.close.call_count == 0
        assert self.set_labels.call_count == 0
Exemple #3
0
    def test_warn_comment_exists(self):

        # Time is beyond warn deadline but within close deadline. There is
        # already a warning, so don't do anything.

        self.open_pull_requests.return_value = ['123']
        self.last_commit_date.return_value = now() - 241
        self.last_comment_date.return_value = now() - 18
        self.find_comments.return_value = ['1']

        process_pull_requests('repo',
                              'installation',
                              warn_seconds=220,
                              close_seconds=20)

        assert self.submit_comment.call_count == 0
        assert self.close.call_count == 0
        assert self.set_labels.call_count == 0
Exemple #4
0
    def test_close_noclose(self):

        # Time is beyond close deadline, and there is no comment yet but the
        # YAML says don't autoclose.

        self.autoclose_stale.return_value = False
        self.open_pull_requests.return_value = ['123']
        self.last_commit_date.return_value = now() - 241
        self.last_comment_date.return_value = now() - 21
        self.find_comments.return_value = [222]

        process_pull_requests('repo',
                              'installation',
                              warn_seconds=220,
                              close_seconds=20)

        assert self.submit_comment.call_count == 0
        assert self.close.call_count == 0
        assert self.set_labels.call_count == 0
Exemple #5
0
    def test_close_comment_exists(self):

        # Time is beyond close deadline, and there is already a comment. In this
        # case no new comment should be posted and the issue should be kept open
        # since this likely indicates the issue was open again manually.

        self.open_pull_requests.return_value = ['123']
        self.last_commit_date.return_value = now() - 241
        self.last_comment_date.return_value = now() - 241
        self.find_comments.return_value = ['1']
        self.labels.return_value = ['io.fits', 'Bug']

        process_pull_requests('repo',
                              'installation',
                              warn_seconds=220,
                              close_seconds=20)

        assert self.submit_comment.call_count == 0
        assert self.close.call_count == 0
        assert self.set_labels.call_count == 0
Exemple #6
0
    def test_warn_before_commit(self):

        # If a commit is more recent than the latest warning, ignore the latest
        # warning and warn again.

        self.open_pull_requests.return_value = ['123']
        self.last_commit_date.return_value = now() - 221
        self.last_comment_date.return_value = now() - 300
        self.find_comments.return_value = [122331]

        process_pull_requests('repo',
                              'installation',
                              warn_seconds=220,
                              close_seconds=20)

        assert self.submit_comment.call_count == 1
        expected = PULL_REQUESTS_CLOSE_WARNING.format(pasttime='3 minutes',
                                                      futuretime='20 seconds')
        self.submit_comment.assert_called_with(expected)
        assert self.close.call_count == 0
        assert self.set_labels.call_count == 0
Exemple #7
0
    def test_warn_even_if_long_time(self):

        # Time is way beyond warn deadline. There isn't a comment yet, so a
        # warning comment should be posted.

        self.open_pull_requests.return_value = ['123']
        self.last_commit_date.return_value = now() - 2000
        self.last_comment_date.return_value = None
        self.find_comments.return_value = []

        process_pull_requests('repo',
                              'installation',
                              warn_seconds=220,
                              close_seconds=20)

        assert self.submit_comment.call_count == 1
        expected = PULL_REQUESTS_CLOSE_WARNING.format(pasttime='33 minutes',
                                                      futuretime='20 seconds')
        self.submit_comment.assert_called_with(expected)
        assert self.close.call_count == 0
        assert self.set_labels.call_count == 0
Exemple #8
0
    def test_close(self):

        # Time is beyond close deadline, and there is no closing comment yet so
        # the closing comment can be posted and the issue closed. In this case
        # there is already also a warning comment posted already.

        self.open_pull_requests.return_value = ['123']
        self.last_commit_date.return_value = now() - 241
        self.last_comment_date.return_value = now() - 21
        self.find_comments.return_value = []

        process_pull_requests('repo',
                              'installation',
                              warn_seconds=220,
                              close_seconds=20)

        assert self.submit_comment.call_count == 1
        expected = PULL_REQUESTS_CLOSE_EPILOGUE
        self.submit_comment.assert_called_with(expected)
        assert self.close.call_count == 1
        assert self.set_labels.call_count == 1