~nigelbabu/ubuntu-qa-tools/patch-review-script

330 by Brian Murray
based on popular demand adding in patch-subscriber.py which subscribes the ubuntu-reviewers team to some bugs with patches and tags the bugs patch
1
#!/usr/bin/env python
2
#
3
# Copyright 2009 Canonical, Ltd
4
# Author: Brian Murray <brian@ubuntu.com>
5
# License: GPLv2
6
# 
7
# 2009-01-28 
8
# This searches for Ubuntu bug reports, that are not needs-packaging bugs,
9
# with patches attached to them.  It then checks to see if the bug report is 
10
# part of a workflow and if so skips it.  If it isn't and the patch is recent,
11
# date added > 2009-12-15, subscribe the ubuntu-reviewers team and add the tag patch.
12
13
from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT, STAGING_SERVICE_ROOT
14
from launchpadlib.errors import HTTPError
15
from launchpadlib.credentials import Credentials
16
17
import os, sys
18
19
cachedir = os.path.expanduser("~/.launchpadlib/cache/")
20
21
if not os.path.exists(cachedir):
22
    os.makedirs(cachedir,0700)
23
24
script_name = sys.argv[0].split("/")[-1].split('.')[0]
25
26
credfile = os.path.expanduser('~/.launchpadlib/%s.cred' % script_name)
27
28
try:
29
    credentials = Credentials()
30
    credentials.load(open(credfile))
31
    launchpad = Launchpad(credentials, EDGE_SERVICE_ROOT, cachedir)
32
except:
33
    launchpad = Launchpad.get_token_and_login(script_name, EDGE_SERVICE_ROOT, cachedir)
34
    launchpad.credentials.save(open(credfile,"w",0600)) 
35
    
36
def save_entry(entry):
37
    try:
38
        entry.lp_save()
39
    except HTTPError, error:
40
        print error.content
41
42
# commonly used things
43
ubuntu = launchpad.distributions['ubuntu']
44
45
# excluding needs-packaging since that has a separate process - revu
46
tasks = ubuntu.searchTasks(order_by='-date_last_updated',tags='-needs-packaging',has_patch=True)
47
48
reviewers = launchpad.people['ubuntu-reviewers']
49
jfo = launchpad.people['jeremyfoshee']
50
# teams that process bugs with patches
337 by Nigel Babu
Keep the old workflow teams too, in case someone subscribes them wrongly
51
workflow_teams = [ 'ubuntu-universe-sponsors', 'ubuntu-main-sponsors', 'ubuntu-sru', \
52
                   'ubuntu-mir', 'ubuntu-release', 'ubuntu-reviewers', 'motu-sru', \
53
                   'ubuntu-security-sponsors', 'ubuntu-sponsors' ]
330 by Brian Murray
based on popular demand adding in patch-subscriber.py which subscribes the ubuntu-reviewers team to some bugs with patches and tags the bugs patch
54
# tags that indicate a review has happened
333 by Nigel Babu
Changed reviewed_tags
55
reviewed_tags = [ 'patch-needswork', 'patch-forwarded-upstream', 'patch-forwarded-debian', \
56
                  'indicator-application', 'patch-accepted-upstream', 'patch-accepted-debian', \
57
                  'patch-rejected-upstream', 'patch-rejected-debian', 'patch-rejected']
330 by Brian Murray
based on popular demand adding in patch-subscriber.py which subscribes the ubuntu-reviewers team to some bugs with patches and tags the bugs patch
58
59
stop = False
60
61
for task in tasks:
62
    if stop:
63
        print 'found a bug with an old patch so stopping'
64
        break
65
    bug = launchpad.bugs[task.bug.id]
66
    # these bugs have been reviewed and require something
67
    if set(reviewed_tags).intersection(bug.tags):
68
        continue
69
    subscribers = []
70
    for subscriber in bug.subscriptions:
71
        subscribers.append(subscriber.person.name)
72
    # don't act on sync requests with the archive admin team subscribed
73
    if 'sync' in bug.title.lower() and 'ubuntu-archive' in subscribers:
74
        continue
75
    # don't act on bugs that already have a sponsor's team subscribed
76
    if set(workflow_teams).intersection(subscribers):
77
        continue
78
    try:
79
        for attachment in bug.attachments:
80
            if attachment.type == 'Patch':
81
                # depending on the queue's throughput we'll want to start adding historical bugs too
82
                if attachment.message.date_created.strftime('%Y-%m-%d') > '2009-12-24':
83
                    print "LP: #%s had patch %s added to it" % ( bug.id, attachment.title )
84
                        # subscribe the team and add the tag patch to the bug report
85
                        # the kernel's workflow is special just subscribe jfo
336 by Nigel Babu
linux-ti-omap package added to JFo's bucket
86
                    if task.bug_target_name in ['linux (Ubuntu)', 'linux-fsl-imx51 (Ubuntu)', 'ubuntu-imx (Ubuntu)', 'linux-backports-modules-2.6.32 (Ubuntu)', 'linux-ti-omap (Ubuntu)']:
330 by Brian Murray
based on popular demand adding in patch-subscriber.py which subscribes the ubuntu-reviewers team to some bugs with patches and tags the bugs patch
87
                        bug.subscribe(person=jfo)
88
                    # skip this package altogether
335 by Nigel Babu
one more package to ignore
89
                    elif task.bug_target_name in ['ubuntu-docs (Ubuntu)', 'xserver-xorg-video-openchrome (Ubuntu)'] :
330 by Brian Murray
based on popular demand adding in patch-subscriber.py which subscribes the ubuntu-reviewers team to some bugs with patches and tags the bugs patch
90
                        continue
91
                    bug.subscribe(person=reviewers)
92
                    if 'patch' not in bug.tags:
93
                        bug = launchpad.bugs[bug.id]# fresh bug object, LP: #336866 workaround
94
                        bug.tags = bug.tags + ['patch']# LP: #254901 workaround
95
                        save_entry(bug)
96
                    stop = False
97
                else:
98
                    # we want to check every attachment to see if one of them is newer than our target
99
                    # date - so don't break out here and above set stop = False if one is newer
100
                    stop = True
101
    except HTTPError, error:
102
        print "Launchpad hates me and LP: #%s" % ( bug.id )