aboutsummaryrefslogtreecommitdiffstats
path: root/local/handler/PushHandler.py
blob: 903b1b6adcee2333ef7c785e0678c3d781fdb0e6 (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from ..utility import *

def handle(data, theme):
    commitno = len(data['commits'])
    ref = data['ref'].split('/',2)
    branch = ref[2]

    isTag = False
    isMerge = False

    branched = data['created'] or data['deleted'] or ref[1] == "tags" or ('base_ref' in data and data['base_ref'])
    branchFrom = ''
    tagFrom = ''

    onlyDeleted = data['deleted'] and not data['created']

    if branched:
        if ref[1] == 'tags':
            isTag = True

        urls = getShortURL(data['compare'])
        if 'base_ref' in data and data['base_ref'] is not None:
            base_ref = data['base_ref'].split('/',2)
            baseBranch = base_ref[2]
            branchFrom = baseBranch

        if (data['created'] and data['deleted']) or (not data['created'] and not data['deleted'] and data['forced']):
            if isTag:
                action = "re-tagged"
            else:
                action = "re-created"
        elif data['created']:
            if isTag:
                action = "tagged"
            else:
                action = "created"
        elif data['deleted']:
            if isTag:
                action = "deleted tag"
            else:
                action = "deleted"
            urls = ''
        else:
            action = "merged"
            mergedCommitCount = sum(not commit['distinct'] for commit in data['commits'])
            regularCommitCount = len(data['commits']) - mergedCommitCount
            isMerge = True

    visible = configValue("hidePush") == False or (configValue("alwaysShowForcedPushes") == True and data['forced'])

    if visible and not branched:
        theme.push(
            branch = branch,
            actor = data['pusher']['name'],
            url = getShortURL(data['compare']),
            count = commitno,
            forced = data['forced']
        )
    elif branched:
        action = "force %s" % (action,)

        if isTag:
            theme.tag(
                actor = data['pusher']['name'],
                action = action,
                base = branchFrom,
                to = branch,
                onlyDeleted = onlyDeleted,
                headMsg = data['head_commit']['message'],
                headId = data['head_commit']['id'],
                url = urls
            )
        elif isMerge:
            theme.merge(
                actor = data['pusher']['name'],
                action = action,
                mergeCount = mergedCommitCount,
                regularCount = regularCommitCount,
                base = branchFrom,
                to = branch,
                url = urls
            )
        else:
            theme.branch(
                actor = data['pusher']['name'],
                action = action,
                count = commitno,
                base = branchFrom,
                to = branch,
                url = urls
            )

    for commit in data['commits']:
        if 'username' in commit['author']:
            author = commit['author']['username']
        else:
            author = commit['author']['name']

        commitBranch = branch

        if not commit['distinct'] and not configValue('showMergedCommits'):
            continue

        if isMerge and not commit['distinct']:
            commitBranch = "%s -> %s" % ( baseBranch, branch )

        theme.commit(
            branch = commitBranch,
            author = author,
            id = commit['id'],
            message = commit['message'],
            url = getShortURL(commit['url'])
        )

© 2014-2024 Faster IT GmbH | imprint | privacy policy