hgpoll.py

Thu, 15 Jan 2015 20:48:57 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 15 Jan 2015 20:48:57 +0200
changeset 119
0f96e3157b7f
parent 115
2bb5c4578ee1
child 120
9880bb697149
permissions
-rw-r--r--

- meh

73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
1 import hgapi
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
2 import time
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
3 import re
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
4 import bt as Bt
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
5 import irc as Irc
86
6337540fb44b - fixed missing import os
Teemu Piippo <crimsondusk64@gmail.com>
parents: 85
diff changeset
6 import os
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
7 from datetime import datetime
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 from configfile import Config
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 g_needCommitsTxtRebuild = True
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10
110
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
11 def color_for_repo (repo_name):
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
12 if repo_name == 'zandronum':
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
13 color = 4
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
14 elif repo_name == 'zandronum-stable':
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
15 color = 2
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
16 elif repo_name == 'zandronum-sandbox':
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
17 color = 7
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
18 elif repo_name == 'zandronum-sandbox-stable':
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
19 color = 3
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
20 elif repo_name == 'zfc9000':
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
21 color = 6
110
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
22 else:
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
23 color = 0
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
24 return color
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
25
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
26 def prettify_bookmarks (bookmarks):
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
27 return "\0036 [\002%s\002]" % bookmarks
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
28
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 def make_commits_txt():
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 global g_needCommitsTxtRebuild
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
31
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 if g_needCommitsTxtRebuild == False:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 return
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
34
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 print 'Building commits.txt...'
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 # Update zandronum-everything
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 repo = hgapi.Repo ('zandronum-everything')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 repo.hg_command ('pull', '../zandronum-sandbox')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 repo.hg_command ('pull', '../zandronum-sandbox-stable')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 data = repo.hg_command ('log', '--template', '{node} {date|hgdate}\n')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 f = open ('commits.txt', 'w')
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
42
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 for line in data.split ('\n'):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 if line == '':
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 continue
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
46
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 words = line.split (' ')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 timestamp = int (words[1])
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
49 f.write ('%s %s\n' % (words[0], datetime.utcfromtimestamp (timestamp).strftime ('%y%m%d-%H%M')))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
50
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 f.close()
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 g_needCommitsTxtRebuild = False
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 ' Check if a repository exists '
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 def check_repo_exists (repo_name, repo_owner):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 print 'Checking that %s exists...' % repo_name
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 repo_url = 'https://bitbucket.org/%s/%s' % (repo_owner, repo_name)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 zanrepo = hgapi.Repo (repo_name)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
59
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 zanrepo.hg_command ('id', '.')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 except hgapi.hgapi.HgException:
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
63 # If the repo does not exist, clone it. zandronum-everything can be spawned
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
64 # off other repos though
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 if repo_name == 'zandronum-everything':
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 if not os.path.exists (repo_name):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 os.makedirs (repo_name)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
68
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 global g_needCommitsTxtRebuild
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 g_needCommitsTxtRebuild = True
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 print 'Init %s' % repo_name
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 zanrepo.hg_command ('init')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 print 'Cloning zandronum-sandbox into %s' % repo_name
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 zanrepo.hg_command ('pull', '../zandronum-sandbox')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 print 'Cloning zandronum-sandbox-stable into %s' % repo_name
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 zanrepo.hg_command ('pull', '../zandronum-sandbox-stable')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 print 'Done'
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 make_commits_txt()
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 return
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
80
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 print 'Cloning %s...' % repo_name
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 zanrepo.hg_clone (repo_url, repo_name)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 print 'Cloning done.'
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 except Exception as e:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 print 'Unable to clone %s from %s: %s' % (repo_name, repo_url, str (`e`))
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
87 quit (1)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
88
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
89
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
90 class HgProcessError (Exception):
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
91 def __init__ (self, value):
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
92 self.message = value
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
93 def __str__ (self):
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
94 return self.message
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
95
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
96 def announce_ticket_resolved (ticket_id, commit_node):
91
Teemu Piippo <crimsondusk64@gmail.com>
parents: 90
diff changeset
97 ticket_id = int (ticket_id)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 90
diff changeset
98
89
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
99 try:
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
100 repo_name = 'zandronum-stable'
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
101 zanrepo = hgapi.Repo (repo_name)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
102 zanrepo.hg_command ('log', '-r', commit_node)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
103 except hgapi.hgapi.HgException:
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
104 try:
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
105 repo_name = 'zandronum'
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
106 zanrepo = hgapi.Repo (repo_name)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
107 zanrepo.hg_command ('log', '-r', commit_node)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
108 except hgapi.hgapi.HgException:
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
109 raise HgProcessError ('unknown commit %s' % commit_node)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
110
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
111 repo_url = 'https://bitbucket.org/Torr_Samaho/%s' % repo_name
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
112
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
113 # Acquire additional data
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
114 moredata = get_commit_data (zanrepo, commit_node,
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
115 '{author|nonempty}\n{date(date, \'%A %d %B %Y %T\')}').split('\n')
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
116
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
117 if len (moredata) != 2:
88
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
118 raise HgProcessError ('malformed hg data while processing %s' % commit_node)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
119
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
120 commit_author = moredata[0]
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
121 commit_date = moredata[1]
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
122 commit_email = ""
90
Teemu Piippo <crimsondusk64@gmail.com>
parents: 89
diff changeset
123 commit_message = zanrepo.hg_command ('log', '-r', commit_node, '--template', '{desc}')
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
124
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
125 try:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
126 ticket_data = Bt.get_issue (ticket_id)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
127 except Exception as e:
88
Teemu Piippo <crimsondusk64@gmail.com>
parents: 87
diff changeset
128 raise HgProcessError ("error while processing %s: %s" % (commit_node, e))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
129
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
130 # Remove the email address from the author if possible
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
131 rex = re.compile (r'^(.+) <([^>]+)>$.*')
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
132 match = rex.match (commit_author)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
133 if match:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
134 commit_author = match.group (1)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
135 commit_email = match.group (2)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
136
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
137 commit_diffstat = zanrepo.hg_command ('diff', '--change', commit_node, '--stat')
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
138
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
139 if len(commit_diffstat) > 0:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
140 # commit_diffstat = 'Changes in files:\n[code]\n' + commit_diffstat + '\n[/code]'
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
141 commit_diffstat = 'Changes in files:\n' + bbcodify(commit_diffstat)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
142 else:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
143 commit_diffstat = 'No changes in files.'
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
144
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
145 # Compare the email addresses against known developer usernames
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
146 commit_trackeruser = Config.find_developer_by_email (commit_email)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
147
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
148 if commit_trackeruser != '':
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
149 commit_author += ' [%s]' % commit_trackeruser
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
150
115
2bb5c4578ee1 - more fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
151 commit_message = commit_message.replace ("\n", " ")
2bb5c4578ee1 - more fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
152
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
153 message = 'Issue addressed by commit %s: [b][url=%s/commits/%s]%s[/url][/b]' \
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
154 % (commit_node, repo_url, commit_node, commit_message)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
155 message += "\nCommitted by %s on %s\n\n%s" \
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
156 % (commit_author, commit_date, commit_diffstat)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
157
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
158 need_update = False
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
159
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
160 # If not already set, set handler
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
161 if not 'handler' in ticket_data:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
162 ticket_data['handler'] = {'name': commit_trackeruser}
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
163 need_update = True
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
164
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
165 # Find out the status level of the ticket
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
166 needs_testing_level = 70
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
167
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
168 if ticket_data['status']['id'] < needs_testing_level:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
169 ticket_data.status['id'] = needs_testing_level
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
170 need_update = True
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
171
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
172 # Set target version if not set
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
173 if not 'target_version' in ticket_data:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
174 ticket_data['target_version'] = '1.4' if repo_name == 'zandronum-stable' else '2.0'
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
175 need_update = True
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
176 elif (ticket_data['target_version'] == '2.0' or ticket_data['target_version'] == '2.0-beta') \
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
177 and repo_name == 'zandronum-stable':
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
178 # Target version was 2.0 but this was just committed to zandronum-stable, adjust
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
179 ticket_data['target_version'] = '1.4'
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
180 need_update = True
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
181 elif ticket_data['target_version'] == '2.0-beta':
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
182 # Fix target version from 2.0-beta to 2.0
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
183 ticket_data['target_version'] = '2.0'
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
184 need_update = True
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
185
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
186 # Announce on IRC
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
187 for irc_client in Irc.all_clients:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
188 for channel in irc_client.channels:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
189 if channel.get_value ('btannounce', default=True):
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
190 irc_client.privmsg (channel.get_value ('name'),
110
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
191 "\003%d%s\003: commit\0035 %s\003 addresses issue\002\0032 %d\002" % (color_for_repo (repo_name), repo_name, commit_node, ticket_id))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
192 irc_client.privmsg (channel.get_value ('name'),
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
193 "Read all about it here: " + Bt.get_ticket_url (ticket_id))
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
194
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
195 if need_update:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
196 # We need to remove the note data, otherwise the ticket notes
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
197 # will get unnecessary updates. WTF, MantisBT?
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
198 ticket_data.notes = []
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
199 Bt.update_issue (ticket_id, ticket_data)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
200
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
201 Bt.post_note (ticket_id, message)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
202
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
203 def init():
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
204 check_repo_exists ('zandronum', 'Torr_Samaho')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
205 check_repo_exists ('zandronum-stable', 'Torr_Samaho')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
206 check_repo_exists ('zandronum-sandbox', 'crimsondusk')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
207 check_repo_exists ('zandronum-sandbox-stable', 'crimsondusk')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
208 check_repo_exists ('zandronum-everything', '')
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
209 check_repo_exists ('zfc9000', 'crimsondusk')
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
210 global repocheck_timeout
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
211 repocheck_timeout = (time.time()) + 15
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 def get_commit_data (zanrepo, rev, template):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 return zanrepo.hg_command ('log', '-l', '1', '-r', rev, '--template', template)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 def decipher_hgapi_error (e):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 # Blah, hgapi, why must your error messages be so mangled?
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 rawmsg = e.message.replace('\n', '').replace('" +','').replace('\t','')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 errmsg = re.compile (r'.*: tErr: (.*)Out:.*').match (rawmsg).group (1)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 return [True, errmsg]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 except:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 return [False, '']
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
225 def bbcodify (commit_diffstat):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
226 result = ''
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
227
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 for line in commit_diffstat.split('\n'):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 rex = re.compile (r'^(.*)\|(.*) (\+*)(-*)(.*)$')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 match = rex.match (line)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 if match:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 line = '%s|%s [color=#5F7]%s[/color][color=#F53]%s[/color]%s\n' \
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
233 % (match.group (1), match.group (2), match.group (3),
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
234 match.group (4), match.group (5))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
235
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 # Tracker doesn't seem to like empty color tags
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 line = line.replace ('[color=#5F7][/color]', '').replace ('[color=#F53][/color]', '')
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
238
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 result += line
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
240
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 return result
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 def poll():
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
244 global repocheck_timeout
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
245 if time.time() < repocheck_timeout:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
246 return
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
247
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
248 for n in ['zandronum-stable', 'zandronum', 'zandronum-sandbox', 'zandronum-sandbox-stable', 'zfc9000']:
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
249 poll_one_repo (n)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
250
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
251 hgns = Config.get_node ('hg')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
252 repocheck_timeout = time.time() + hgns.get_value ('checkinterval', default=15) * 60
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
254 def poll_one_repo (repo_name):
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 global repocheck_timeout
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 hgns = Config.get_node ('hg')
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
257
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 if not hgns.get_value ('track', default=True):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 return
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
260
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable'
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
262 repo_owner = 'Torr_Samaho' if (not usesandbox and repo_name != 'zfc9000') else 'crimsondusk'
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 zanrepo = hgapi.Repo (repo_name)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 commit_data = []
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 delimeter = '@@@@@@@@@@'
109
87ad0c1b3405 - commit latest changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 108
diff changeset
266 # print 'Checking %s for updates' % repo_name
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
267
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 data = zanrepo.hg_command ('incoming', '--quiet', '--template',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 '{node|short} {desc}' + delimeter)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271 except hgapi.hgapi.HgException as e:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 deciphered = decipher_hgapi_error (e)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
273
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 if deciphered[0] and len(deciphered[1]) > 0:
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
275 Irc.broadcast ("error while using hg import on %s: %s" % (repo_name, deciphered[1]))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
276
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 return
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 except Exception as e:
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
279 Irc.broadcast ("%s" % `e`)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 return
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
281
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 for line in data.split (delimeter):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 if line == '':
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 continue
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
285
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 rex = re.compile (r'([^ ]+) (.+)')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 match = rex.match (line)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 failed = False
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290 if not match:
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
291 Irc.broadcast ('malformed hg data: %s' % line)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 continue
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
293
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294 commit_node = match.group (1)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 commit_message = match.group (2)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 commit_data.append ([commit_node, commit_message])
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
297
97
55d7d9aea160 - link rest to hg
Teemu Piippo <crimsondusk64@gmail.com>
parents: 91
diff changeset
298 process_new_commits (repo_name, commit_data)
55d7d9aea160 - link rest to hg
Teemu Piippo <crimsondusk64@gmail.com>
parents: 91
diff changeset
299
55d7d9aea160 - link rest to hg
Teemu Piippo <crimsondusk64@gmail.com>
parents: 91
diff changeset
300 def process_new_commits (repo_name, commit_data):
108
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
301 if len (commit_data) == 0:
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
302 return
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
303
98
4edbdf390bd1 - fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 97
diff changeset
304 usestable = repo_name == 'zandronum-stable'
4edbdf390bd1 - fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 97
diff changeset
305 usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable'
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
306 repo_owner = 'Torr_Samaho' if (not usesandbox and repo_name != 'zfc9000') else 'crimsondusk'
98
4edbdf390bd1 - fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 97
diff changeset
307 repo_url = 'https://bitbucket.org/%s/%s' % (repo_owner, repo_name)
4edbdf390bd1 - fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 97
diff changeset
308 num_commits = 0
4edbdf390bd1 - fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 97
diff changeset
309 zanrepo = hgapi.Repo (repo_name)
110
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
310 print '%d new commits on %s' % (len (commit_data), repo_name)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
311
108
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
312 # Drop commits that we already have
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
313 i = 0
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
314 while i < len (commit_data):
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
315 try:
109
87ad0c1b3405 - commit latest changes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 108
diff changeset
316 zanrepo.hg_command ('log', '-r', commit_data[i][0])
108
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
317 del commit_data[i]
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
318 except:
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
319 i += 1
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
320
108
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
321 pull_args = [];
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322
108
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
323 for commit in commit_data:
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
324 pull_args.append ('-r');
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
325 pull_args.append (commit[0]);
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
326
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
327 print 'Pulling new commits...'
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
328 try:
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
329 zanrepo.hg_command ('pull', *pull_args)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
330
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
331 if repo_name[0:9] == 'zandronum':
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
332 # Also pull these commits to the zandronum main repository
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
333 if usestable:
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
334 devrepo = hgapi.Repo ('zandronum')
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
335 devrepo.hg_command ('pull', '../zandronum-stable', *pull_args)
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
336 # Pull everything into sandboxes too
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
337 if not usesandbox:
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
338 devrepo = hgapi.Repo ('zandronum-sandbox')
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
339 devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args)
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
340
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
341 devrepo = hgapi.Repo ('zandronum-sandbox-stable')
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
342 devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args)
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
343
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
344 devrepo = hgapi.Repo ('zandronum-everything')
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
345 devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args)
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
346
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
347 global g_needCommitsTxtRebuild
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
348 g_needCommitsTxtRebuild = True
108
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
349
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
350 except Exception as e:
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
351 Irc.broadcast ('Warning: unable to pull: %s' % `e`)
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
352 return
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
353
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354 for commit in commit_data:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
355 commit_node = commit[0]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 commit_message = commit[1]
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
357 print 'Processing new commit %s...' % commit_node
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
358
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
359 try:
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
360 data = get_commit_data (zanrepo, commit_node, '{author}@@@@@@@@@@{bookmarks}').split ("@@@@@@@@@@")
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
361 commit_author = data[0]
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
362 commit_bookmarks = prettify_bookmarks (data[1])
100
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
363 commit_url = '%s/commits/%s' % (repo_url, commit_node)
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
364 commit_email = ''
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
365
100
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
366 # Remove the email address from the author if possible
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
367 rex = re.compile (r'^(.+) <([^>]+)>$.*')
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
368 match = rex.match (commit_author)
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
369 if match:
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
370 commit_author = match.group (1)
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
371 commit_email = match.group (2)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
372
100
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
373 commit_trackeruser = Config.find_developer_by_email (commit_email)
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
374 committer = commit_trackeruser if commit_trackeruser != '' else commit_author
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
375
100
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
376 for irc_client in Irc.all_clients:
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
377 for channel in irc_client.channels:
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
378 if not channel.get_value ('btannounce', False):
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
379 continue
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
380
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 111
diff changeset
381 if (not usesandbox and repo_name != 'zfc9000') or channel.get_value ('btprivate', False):
100
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
382 irc_client.privmsg (channel.get_value ('name'),
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
383 "\003%d%s\003: new commit\0035 %s%s\003 by\0032 %s\003: %s"
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
384 % (color_for_repo (repo_name), repo_name, commit_node, commit_bookmarks,
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
385 committer, commit_url))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
386
100
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
387 for line in commit_message.split ('\n'):
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
388 irc_client.privmsg (channel.get_value ('name'), line)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
389
100
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
390 if not usesandbox:
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
391 rex = re.compile (r'^.*(fixes|resolves|addresses|should fix) ([0-9]+).*$')
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
392 match = rex.match (commit_message)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
393
100
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
394 if match:
2a56ccf67782 - be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents: 98
diff changeset
395 announce_ticket_resolved (match.group (2), commit_node)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 num_commits += 1
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 except Exception as e:
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
399 Irc.broadcast ('Error while processing %s: %s' % (commit_node, e))
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 continue
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 def force_poll():
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
403 global repocheck_timeout
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404 repocheck_timeout = 0
85
302e2bec51d8 - fixed bad find_developer_by_email call
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
405 poll()

mercurial