df89
10.10.21 c4d692c98f3e06d39cf80bf8fa2035c2e398646b
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
class CommitBody:
    commitTypes = ("build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test")
    def __init__(self, completeMessage):
        self.completeMessage = completeMessage
 
        self.setSubjectAndBody()
        self.setScope()
        self.setCommitType()
    
    def setSubjectAndBody(self):
        """set commit message subject and body (not in use yet)"""
        try: # find start point of commit message
            subStart = self.completeMessage.index(": ")+2
        except:
            try:
                subStart = self.completeMessage.index("\n")
            except:
                subStart = 0
        try: # find end point of commit message
            subEnd = self.completeMessage.index("\n")
        except:
            self.subject = self.completeMessage[subStart:]
            self.body = None
        else:
            self.subject = self.completeMessage[subStart:subEnd]
            self.body = self.completeMessage[subEnd:].strip()
    
    def setScope(self):
        """set commit scope if contained in message"""
        try:
            start = self.completeMessage.index("(")+1
            end = self.completeMessage.index("):")
        except:
            self.scope = None
        else:
            self.scope = self.completeMessage[start:end].strip().lower()
    
    def setCommitType(self):
        """set commit type according to type list from conventional commits"""
        for commitType in self.commitTypes:
            if (self.completeMessage.startswith((commitType + ": "))) or (self.completeMessage.startswith((commitType + "("))) or (self.completeMessage.startswith((commitType + " ("))):
                self.commitType = commitType
                break
            else:
                self.commitType = "nonconform"
    
    def getCommitMessageWithType(self):
        """get commit type and message subject as concatenated string"""
        return self.commitType + ": " + self.subject