245 except: |
245 except: |
246 return [False, ''] |
246 return [False, ''] |
247 #endtry |
247 #endtry |
248 #enddef |
248 #enddef |
249 |
249 |
|
250 def bbcodify(commit_diffstat): |
|
251 result='' |
|
252 for line in commit_diffstat.split('\n'): |
|
253 # Add green color-tags for the ++++++++++ stream |
|
254 rex = re.compile (r'^(.*)\|(.*) (\+*)(-*)(.*)$') |
|
255 match = rex.match (line) |
|
256 if match: |
|
257 line = '%s|%s [color=#5F7]%s[/color][color=#F53]%s[/color]%s\n' \ |
|
258 % (match.group (1), match.group (2), match.group (3), match.group (4), match.group (5)) |
|
259 |
|
260 # Tracker doesn't seem to like empty color tags |
|
261 line = line.replace ('[color=#5F7][/color]', '').replace ('[color=#F53][/color]', '') |
|
262 #else: |
|
263 #rex = re.compile (r'^(.*) ([0-9]+) insertions\(\+\), ([0-9]+) deletions\(\-\)$') |
|
264 #match = rex.match (line) |
|
265 #if match: |
|
266 #line = '%s [b][color=green]%s[/color][/b] insertions, [b][color=red]%s[/color][/b] deletions\n' \ |
|
267 #% (match.group (1), match.group (2), match.group (3)) |
|
268 |
|
269 result += line |
|
270 #done |
|
271 |
|
272 return result |
|
273 #enddef |
|
274 |
250 ' Retrieves and processes commits for zandronum repositories ' |
275 ' Retrieves and processes commits for zandronum repositories ' |
251 ' Ensure both repositories are OK before using this! ' |
276 ' Ensure both repositories are OK before using this! ' |
252 def process_zan_repo_updates (repo_name): |
277 def process_zan_repo_updates (repo_name): |
253 global repocheck_timeout |
278 global repocheck_timeout |
254 global suds_client |
279 global suds_client |
339 |
364 |
340 ticket_id = int (match.group (2)) |
365 ticket_id = int (match.group (2)) |
341 |
366 |
342 # Acquire additional data |
367 # Acquire additional data |
343 moredata = get_commit_data (zanrepo, commit_node, |
368 moredata = get_commit_data (zanrepo, commit_node, |
344 '{author|nonempty}\n{date(date, \'%A %d %B %Y %T\')}\n{diffstat|nonempty}').split('\n') |
369 '{author|nonempty}\n{date(date, \'%A %d %B %Y %T\')}').split('\n') |
345 |
370 |
346 if len (moredata) != 3: |
371 if len (moredata) != 2: |
347 chanlog ('error while processing %s: malformed hg data' % commit_node) |
372 chanlog ('error while processing %s: malformed hg data' % commit_node) |
348 continue |
373 continue |
349 #fi |
374 #fi |
350 |
375 |
351 commit_author = moredata[0] |
376 commit_author = moredata[0] |
352 commit_date = moredata[1] |
377 commit_date = moredata[1] |
353 commit_diffstat = moredata[2] |
|
354 commit_email = "" |
378 commit_email = "" |
355 |
379 |
356 try: |
380 try: |
357 ticket_data = suds_client.service.mc_issue_get (g_config['trackeruser'], |
381 ticket_data = suds_client.service.mc_issue_get (g_config['trackeruser'], |
358 g_config['trackerpassword'], ticket_id) |
382 g_config['trackerpassword'], ticket_id) |
367 if match: |
391 if match: |
368 commit_author = match.group (1) |
392 commit_author = match.group (1) |
369 commit_email = match.group (2) |
393 commit_email = match.group (2) |
370 #fi |
394 #fi |
371 |
395 |
372 # Try parse and prettify the diffstat |
396 commit_diffstat = zanrepo.hg_command ('diff', '--change', commit_node, '--stat') |
373 rex = re.compile (r'([0-9]+): \+([0-9]+)/-([0-9]+)') |
397 |
374 match = rex.match (commit_diffstat) |
398 if len(commit_diffstat) > 0: |
375 |
399 # commit_diffstat = 'Changes in files:\n[code]\n' + commit_diffstat + '\n[/code]' |
376 if match: |
400 commit_diffstat = 'Changes in files:\n' + bbcodify(commit_diffstat) |
377 modded = int (match.group (1)) |
401 else: |
378 added = int (match.group (2)) |
402 commit_diffstat = 'No changes in files.' |
379 deleted = int (match.group (3)) |
|
380 commit_diffstat = "%s file%s modified, %s line%s added, %s line%s removed" % \ |
|
381 (modded if modded != 0 else 'no', |
|
382 's' if modded != 1 else '', |
|
383 added if added != 0 else 'no', |
|
384 's' if added != 1 else '', |
|
385 deleted if deleted != 0 else 'no', |
|
386 's' if deleted != 1 else '') |
|
387 #fi |
|
388 |
|
389 files_added = filter (None, get_commit_data (zanrepo, commit_node, '{file_adds}').split (' ')) |
|
390 files_removed = filter (None, get_commit_data (zanrepo, commit_node, '{file_dels}').split (' ')) |
|
391 files_changed = filter (None, get_commit_data (zanrepo, commit_node, '{file_mods}').split (' ')) |
|
392 |
403 |
393 # Compare the email addresses against known developer usernames |
404 # Compare the email addresses against known developer usernames |
394 commit_trackeruser = '' |
405 commit_trackeruser = '' |
395 |
406 |
396 for developer, emails in g_config['developer_emails'].iteritems(): |
407 for developer, emails in g_config['developer_emails'].iteritems(): |
411 |
422 |
412 message = 'Issue addressed by commit %s: [b][url=%s/commits/%s]%s[/url][/b]' \ |
423 message = 'Issue addressed by commit %s: [b][url=%s/commits/%s]%s[/url][/b]' \ |
413 % (commit_node, repo_url, commit_node, commit_message) |
424 % (commit_node, repo_url, commit_node, commit_message) |
414 message += "\nCommitted by %s on %s\n\n%s" \ |
425 message += "\nCommitted by %s on %s\n\n%s" \ |
415 % (commit_author, commit_date, commit_diffstat) |
426 % (commit_author, commit_date, commit_diffstat) |
416 |
|
417 if len (files_added) > 0: |
|
418 message += "\nFiles added: %s" % ', '.join (files_added) |
|
419 #fi |
|
420 |
|
421 if len (files_removed) > 0: |
|
422 message += "\nFiles removed: %s" % ', '.join (files_removed) |
|
423 #fi |
|
424 |
|
425 if len (files_changed) > 0: |
|
426 message += "\nFiles changed: %s" % ', '.join (files_changed) |
|
427 #fi |
|
428 |
427 |
429 need_update = False |
428 need_update = False |
430 |
429 |
431 # If not already set, set handler |
430 # If not already set, set handler |
432 if not 'handler' in ticket_data: |
431 if not 'handler' in ticket_data: |