summaryrefslogtreecommitdiff
path: root/buildscripts/tests/test_validate_commit_message.py
blob: 3f51bcff0f51747e10d92f534291087ecbf196b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Unit tests for the evergreen_task_timeout script."""

import unittest
from git import Commit, Repo

from buildscripts.validate_commit_message import is_valid_commit


class ValidateCommitMessageTest(unittest.TestCase):
    def test_valid(self):
        fake_repo = Repo()
        messages = [
            Commit(repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message="SERVER-44338"),
            Commit(repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message='Revert "SERVER-60'),
            Commit(
                repo=fake_repo,
                binsha=b"deadbeefdeadbeefdead",
                message="Import wiredtiger: 58115abb6fbb3c1cc7bfd087d41a47347bce9a69 from branch mongodb-4.4",
            ),
            Commit(
                repo=fake_repo,
                binsha=b"deadbeefdeadbeefdead",
                message='Revert "Import wiredtiger: 58115abb6fbb3c1cc7bfd087d41a47347bce9a69 from branch mongodb-4.4"',
            ),
            Commit(
                repo=fake_repo,
                binsha=b"deadbeefdeadbeefdead",
                message="SERVER-44338 blablablalbabla\nmultiline message\nasdfasdf",
            ),
        ]

        self.assertTrue(all(is_valid_commit(message) == True for message in messages))

    def test_invalid(self):
        fake_repo = Repo()
        messages = [
            Commit(
                repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message="SERVER-"
            ),  # missing number
            Commit(
                repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message="Revert SERVER-60"
            ),  # missing quote before SERVER
            Commit(repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message=""),  # empty value
            Commit(
                repo=fake_repo, binsha=b"deadbeefdeadbeefdead", message="nonsense"
            ),  # nonsense value
            Commit(
                repo=fake_repo,
                binsha=b"deadbeefdeadbeefdead",
                message="SERVER-123 asdf\nhttps://spruce.mongodb.com",
            ),  # Contains some banned strings
            Commit(
                repo=fake_repo,
                binsha=b"deadbeefdeadbeefdead",
                message="SERVER-123 asdf\nhttps://evergreen.mongodb.com",
            ),  # Contains some banned strings
            Commit(
                repo=fake_repo,
                binsha=b"deadbeefdeadbeefdead",
                message="SERVER-123 asdf\nAnything in this description will be included in the commit message. Replace or delete this text before merging. Add links to testing in the comments of the PR.",
            ),  # Contains some banned strings
            Commit(
                repo=fake_repo,
                binsha=b"deadbeefdeadbeefdead",
                message="SERVER-123 asdf\nAnything\n\n in this description will be included in the commit message.\nReplace or delete this text before merging. Add links to testing in the\ncomments of the PR.",
            ),  # Contains some banned strings with extra newlines
        ]

        self.assertTrue(all(is_valid_commit(message) == False for message in messages))