hgpoll.py

Sun, 16 Aug 2015 23:30:11 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 16 Aug 2015 23:30:11 +0300
changeset 154
df862cca1773
parent 153
497b7290977d
child 158
f96730dee026
permissions
-rw-r--r--

Added ability to define an IRC command with a function decorator instead of a manifest entry

124
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
1 '''
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
2 Copyright 2014-2015 Teemu Piippo
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
3 All rights reserved.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
4
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
5 Redistribution and use in source and binary forms, with or without
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
6 modification, are permitted provided that the following conditions
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
7 are met:
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
8
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
9 1. Redistributions of source code must retain the above copyright
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
10 notice, this list of conditions and the following disclaimer.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
12 notice, this list of conditions and the following disclaimer in the
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
13 documentation and/or other materials provided with the distribution.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
14 3. The name of the author may not be used to endorse or promote products
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
15 derived from this software without specific prior written permission.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
16
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
27 '''
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
28
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
29 from __future__ import print_function
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
30 import time
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
31 import re
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
32 import bt as Bt
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
33 import irc as Irc
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
34 import os
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 from configfile import Config
120
9880bb697149 - added doomseeker support, fixed up mod_bridge, now shortens new commit links with bit.ly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 115
diff changeset
36 import utility
133
Teemu Piippo <crimsondusk64@gmail.com>
parents: 132
diff changeset
37 import random
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
38 from hgrepo import HgRepository
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
39 from hgdb import HgCommitsDatabase
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
40 import traceback
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
41 import sys
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
42
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
43 Repositories = []
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
44 RepositoriesByName = {}
110
b2770c43b752 - now in color!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
45
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
46 def prettify_bookmarks (bookmarks):
123
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
47 if bookmarks:
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
48 return "\0036 [\002%s\002]" % bookmarks
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
49 else:
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
50 return ''
111
44d9aea72947 - support bookmarks
Teemu Piippo <crimsondusk64@gmail.com>
parents: 110
diff changeset
51
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
52 def get_repo_by_name (name):
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
53 global Repositories, RepositoriesByName
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
54 name = name.lower()
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
55
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
56 if name not in RepositoriesByName:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
57 repo = HgRepository (name)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
58 Repositories.append (repo)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
59 RepositoriesByName[name] = repo
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
60 else:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
61 repo = RepositoriesByName[name]
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
62
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
63 return repo
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
65 def check_repo_exists (name):
153
497b7290977d More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 152
diff changeset
66 ' Ensures that the repository exists '
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
67 repo = get_repo_by_name (name)
153
497b7290977d More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 152
diff changeset
68 os.makedirs (repo.name, exist_ok = True)
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
69
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
70 if not repo.is_valid():
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
71 # If the repo does not exist, clone it.
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 try:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
73 repo.clone()
123
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
74
152
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
75 # We need to un-alias a few things in case they're aliased
123
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
76 comms=['log', 'incoming', 'pull', 'commit', 'push', 'outgoing', 'strip', 'transplant']
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
77 try:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
78 with open (os.path.join (repo.name, '.hg', 'hgrc'), 'a') as fp:
123
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
79 fp.write ('\n[alias]\n' + ''.join(['%s=%s\n' % (x, x) for x in comms]))
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
80 except Exception as e:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
81 print ('Warning: unable to alter hgrc of %s: %s' % repo.name, e)
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
82 print ('Cloning done.')
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 except Exception as e:
152
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
84 raise HgProcessError ('Unable to clone %s from %s: %s' % (repo.name, repo.clone_url, e))
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
86 if not repo.is_valid():
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
87 raise HgProcessError ('''%s is not a valid repository after cloning '''
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
88 '''(.hg is missing)''' % repo.name)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
89
88
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
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
96 def contains_published_repositories (repos):
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
97 for repo in repos:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
98 if repo.published:
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
99 return True
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
100
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
101 return False
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
102
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
103 def announce_ticket_resolved (ticket_id, cset, db):
91
Teemu Piippo <crimsondusk64@gmail.com>
parents: 90
diff changeset
104 ticket_id = int (ticket_id)
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
105 repos = db.get_commit_repos (cset)
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
106
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
107 for repo in repos:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
108 if repo.published:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
109 break
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
110 else:
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
111 raise HgProcessError ('Changeset %s is only committed to non-published repositories: %s' %
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
112 (cset, ', '.join (repos)))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
113
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
114 # Acquire additional data
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
115 commit = repo.get_commit_data (rev=cset,
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
116 author='author|person',
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
117 date='date(date, "%A %d %B %Y %H:%M:%S")',
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
118 email='author|email',
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
119 message='desc')
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
120
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
121 diffstat = repo.hg ('diff', '--change', cset, '--stat')
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
122
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
123 try:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
124 ticket_data = Bt.get_issue (ticket_id)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
125 except Exception as e:
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
126 raise HgProcessError ("error while processing %s: %s" % (cset, e))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
127
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
128 if len(diffstat) > 0:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
129 diffstat = 'Changes in files:\n[code]\n' + diffstat + '\n[/code]'
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
130 else:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
131 diffstat = 'No changes in files.'
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
132
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
133 # Compare the email addresses against known developer usernames
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
134 username = Config.find_developer_by_email (commit['email'])
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
135
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
136 if username:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
137 commit['author'] += ' [%s]' % username
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
138
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
139 commit['message'] = commit['message'].replace ("\n", " ")
115
2bb5c4578ee1 - more fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
140
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
141 message = 'Issue addressed by commit %s: [b][url=%s/commits/%s]%s[/url][/b]' \
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
142 % (cset, repo.url, cset, commit['message'])
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
143 message += "\nCommitted by %s on %s\n\n%s" \
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
144 % (commit['author'], commit['date'], diffstat)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
145
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
146 need_update = False
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 not already set, set handler
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
149 if username and not 'handler' in ticket_data:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
150 ticket_data['handler'] = {'name': username}
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
151 need_update = True
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
152
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
153 # Find out the status level of the ticket
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
154 needs_testing_level = 70
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
155
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
156 if ticket_data['status']['id'] < needs_testing_level:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
157 ticket_data.status['id'] = needs_testing_level
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
158 need_update = True
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 # Set target version if not set
151
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
161 if repo.version and not 'target_version' in ticket_data:
e24793fae424 Yet more fixes
Teemu Piippo <tsapii@utu.fi>
parents: 147
diff changeset
162 ticket_data['target_version'] = repo.version
87
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 # Announce on IRC
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
166 for irc_client in Irc.all_clients:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
167 for channel in irc_client.channels:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
168 if channel.get_value ('btannounce', default=True):
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
169 irc_client.privmsg (channel.get_value ('name'),
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
170 "\003%d%s\003: commit\0035 %s\003 addresses issue\002\0032 %d\002" % \
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
171 (repo.color, repo.name, cset, ticket_id))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
172 irc_client.privmsg (channel.get_value ('name'),
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
173 "Read all about it here: " + Bt.get_ticket_url (ticket_id))
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
174
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
175 if need_update:
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
176 # We need to remove the note data, otherwise the ticket notes
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
177 # will get unnecessary updates. WTF, MantisBT?
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
178 ticket_data.notes = []
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
179 Bt.update_issue (ticket_id, ticket_data)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
180
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
181 Bt.post_note (ticket_id, message)
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
182
123
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
183 def init():
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
184 global repocheck_timeout
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
185
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
186 for name in Config.get_node ('hg').get_value ('repos', {}).keys():
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
187 check_repo_exists (name)
123
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
188
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
189 # Let the database check if commits.db needs to be built
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
190 HgCommitsDatabase()
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
192 repocheck_timeout = time.time() + 15
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 def poll():
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
195 global repocheck_timeout
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
196
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 try:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
198 if time.time() < repocheck_timeout:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
199 return
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
200
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
201 hgns = Config.get_node ('hg')
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
202 repocheck_timeout = time.time() + hgns.get_value ('checkinterval', default=15) * 60
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
203 maxcommits = 15
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
204 numcommits = 0
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
205
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
206 for repo in Repositories:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
207 numcommits += poll_one_repo (repo, maxcommits=maxcommits - numcommits)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
208
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
209 if numcommits >= maxcommits:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
210 # There may be more coming so recheck sooner
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
211 print ('Processed %d commits, checking for new commits in 1 minute...' % numcommits)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
212 repocheck_timeout = time.time() + 60
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
213 return
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 except Exception as e:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
215 print (traceback.format_exception (*sys.exc_info()))
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
216 Irc.broadcast (str (e))
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
217
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
218 def poll_one_repo (repo, maxcommits):
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
219 if not Config.get_node ('hg').get_value ('track', default=True):
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 return
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
221
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
222 print ('Checking %s for updates' % repo.name)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
223 commits = repo.incoming (maxcommits=maxcommits, node='node|short', message='desc')
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
224 process_new_commits (repo, commits)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
225 return len(commits)
108
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
226
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
227 def process_new_commits (repo, commits):
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
228 if not commits:
108
8cf31b4d5fcb - we now need an explicit check against double-processing commits
Teemu Piippo <crimsondusk64@gmail.com>
parents: 101
diff changeset
229 return
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
230
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
231 print ('%d new commits on %s' % (len (commits), repo.name))
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
232 pull_args = ['pull']
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
233 messages = [[], [], []]
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
234
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
235 for commit in commits:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
236 pull_args.append ('-r');
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
237 pull_args.append (commit['node']);
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
238
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
239 print ('Pulling new commits...')
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
240 repo.hg (*pull_args)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
241 LENGTH_MINIMUM, LENGTH_SHORT, LENGTH_FULL = range (0, 3)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
242 db = HgCommitsDatabase()
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
243
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
244 for commit in commits:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
245 print ('Processing new commit %s...' % commit['node'])
121
ac07779f788d - reworked mercurial repository handling, removed hardcoded values
Teemu Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
246
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
247 existingrepos = db.get_commit_repos (commit['node'])
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
248 alreadyAdded = len (existingrepos) > 0
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
249
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
250 commit = dict (commit, **repo.get_commit_data (rev=commit['node'],
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
251 fullnode='node',
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
252 author='author|person',
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
253 bookmarks='bookmarks',
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
254 date='date|hgdate',
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
255 email='author|email'))
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
256 commit['bookmarks'] = prettify_bookmarks (commit['bookmarks'])
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
257 commit['time'] = int (commit['date'].split (' ')[0])
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
258 commit['url'] = '%s/commits/%s' % (repo.url, commit['node'])
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
259 isMergeFromSandbox = False
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
260
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
261 # If the commit was already in the commits database, it is not a new one and we should
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
262 # not react to it (unless a merge from sandbox). Still add it to the db though so that
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
263 # the new repo name is added.
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
264 db.add_commit (repo=repo, changeset=commit['fullnode'],
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
265 timestamp=commit['time'])
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
266
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
267 if alreadyAdded:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
268 if not contains_published_repositories (existingrepos) and repo.published:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
269 isMergeFromSandbox = True
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
270 print ('''%s appears to be a merge from sandbox (exists in %s)''' %
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
271 (commit['node'], existingrepos))
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
272 else:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
273 print ('''I already know of %s - they're in %s - not announcing.''' %
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
274 (commit['node'], existingrepos))
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
275 continue
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
276
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
277 username = Config.find_developer_by_email (commit['email'])
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
278 committer = username if username else commit['author']
152
1b734faab67a Port to Python 3
Teemu Piippo <crimsondusk64@gmail.com>
parents: 151
diff changeset
279 descriptor = """commit""" if random.randrange (100) != 0 else """KERMIT"""
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
280
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
281 if not isMergeFromSandbox:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
282 commitMessage = """\003%d%s\003: new %s\0035 %s%s\003 by\0032 %s\003: %s""" % \
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
283 (repo.color, repo.name, descriptor, commit['node'], commit['bookmarks'],
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
284 committer, utility.shorten_link (commit['url']))
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
285
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
286 for length in [LENGTH_MINIMUM, LENGTH_SHORT, LENGTH_FULL]:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
287 messages[length].append (commitMessage)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
288
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
289 messages[LENGTH_SHORT].append (' ' + commit['message'].splitlines()[0])
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
290
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
291 for line in commit['message'].splitlines()[:4]:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
292 messages[LENGTH_FULL].append (' ' + line)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
293 else:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
294 commitMessage = """\003%d%s\003: %s\0035 %s\003 by\0032 %s\003 was pulled: %s""" % \
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
295 (repo.color, repo.name, descriptor, commit['node'], committer,
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
296 utility.shorten_link (commit['url']))
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
297
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
298 for length in [LENGTH_MINIMUM, LENGTH_SHORT, LENGTH_FULL]:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
299 messages[length].append (commitMessage)
87
9e757b602586 - added .resolves
Teemu Piippo <crimsondusk64@gmail.com>
parents: 86
diff changeset
300
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
301 if repo.published:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
302 rex = re.compile (r'^.*(fixes|resolves|addresses|should fix) ([0-9]+).*$')
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
303
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
304 for line in commit['message'].splitlines():
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
305 match = rex.match (line)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
306
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
307 if match:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
308 announce_ticket_resolved (match.group (2), commit['node'], db)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
309 break
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
311 fullMessageLength = len (''.join (messages[2]))
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
312
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
313 if fullMessageLength > 3000:
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
314 messageSizeClass = LENGTH_MINIMUM
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
315 elif fullMessageLength > 768:
144
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
316 messageSizeClass = LENGTH_SHORT
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
317 else:
b3d1b356e544 - Remove hgapi dependence
Teemu Piippo <crimsondusk64@gmail.com>
parents: 143
diff changeset
318 messageSizeClass = LENGTH_FULL
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
319
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
320 # Post it all on IRC now
153
497b7290977d More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 152
diff changeset
321 for irc_client in Irc.all_clients:
497b7290977d More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 152
diff changeset
322 for channel in irc_client.channels:
497b7290977d More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 152
diff changeset
323 if not channel.get_value ('btannounce', False):
497b7290977d More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 152
diff changeset
324 continue
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
325
153
497b7290977d More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 152
diff changeset
326 if not repo.published and not channel.get_value ('allpublishing', False):
497b7290977d More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 152
diff changeset
327 continue
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
328
153
497b7290977d More Python 3 rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 152
diff changeset
329 for message in messages[messageSizeClass]:
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
330 irc_client.privmsg (channel.get_value ('name'), message)
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
331
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 145
diff changeset
332 db.commit()
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
333
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 def force_poll():
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
335 global repocheck_timeout
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 repocheck_timeout = 0
85
302e2bec51d8 - fixed bad find_developer_by_email call
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
337 poll()

mercurial