-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_commmit_check.py
59 lines (47 loc) · 2.16 KB
/
test_commmit_check.py
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
"""Test commit check validates Jira issues properly"""
from rhenvision_changelog.changelog import ProvisioningChangelog
from rhenvision_changelog.commit_check import check_commit
jira_project = "HMS"
commit_head = """a5bc1e0f00aed28102579d14d651a27d5dded4a4
John Doe
1669736056
John Doe
1669736056
HEAD -> branch, origin/branch
701eca9b345a940c8da0bab7fe601666ca9985b9
"""
class StubbedChangelog(ProvisioningChangelog):
def __init__(self, commit_message):
self.commit_message = commit_message
super().__init__('.', 'https://jira.test.com', jira_project)
def get_log(self) -> str:
"""Get stubbed `git log` output defined by stub passed to constructor.
Returns:
The stubbed `git log` in a particular format.
"""
return commit_head + self.commit_message + "\n\n"+self.MARKER+"\n"
def get_remote_url(self) -> str:
return "https://github.com/RHEnVision/provisioning"
def test_jira_issue_parsing() -> int:
changelog = StubbedChangelog("feat(HMS-123): Subject")
assert check_commit(changelog.commits[0], jira_project) == 0
changelog = StubbedChangelog("feat: Subject\nFixes: HMS-123")
assert check_commit(changelog.commits[0], jira_project) == 0
# allows different HMS projects - legacy reasons
changelog = StubbedChangelog("feat: Subject\nRefs: HMSJIRA-123")
assert check_commit(changelog.commits[0], jira_project) == 0
changelog = StubbedChangelog("feat(HMSJIRA-123): Subject")
assert check_commit(changelog.commits[0], jira_project) == 0
# allows link to ticket in the commit body
changelog = StubbedChangelog("feat: Subject\njira.test.com/browse/HMS-123")
assert check_commit(changelog.commits[0], jira_project) == 0
# no issue link necessary for other types
changelog = StubbedChangelog("build: Subject")
assert check_commit(changelog.commits[0], jira_project) == 0
# issue link needed for feat and fix
changelog = StubbedChangelog("feat: Subject")
assert check_commit(changelog.commits[0], jira_project) != 0
changelog = StubbedChangelog("fix: Subject")
assert check_commit(changelog.commits[0], jira_project) != 0