1 | #!/usr/bin/env python |
---|
2 | """Module for creating new branches for tickets""" |
---|
3 | |
---|
4 | import time |
---|
5 | |
---|
6 | from mergebot.svn import SvnLib |
---|
7 | SvnOps = SvnLib() |
---|
8 | from mergebot.Actor import Actor |
---|
9 | |
---|
10 | class BranchActor(Actor): |
---|
11 | """This class handles creating a new branch for a ticket.""" |
---|
12 | def execute(self): |
---|
13 | """Create the branch for the given ticket. |
---|
14 | """ |
---|
15 | results = {} |
---|
16 | # Setup logging |
---|
17 | logfile = self.logfilename() |
---|
18 | open(logfile, "a").write("%s: branching ticket %s\n" % (time.asctime(), |
---|
19 | self.ticket)) |
---|
20 | |
---|
21 | # Make sure the various urls we require do exist |
---|
22 | problems = self.check_required_directories() |
---|
23 | if problems: |
---|
24 | return results, problems, False |
---|
25 | |
---|
26 | commit_header = 'Ticket #%s: %s' % (self.ticket, self.summary) |
---|
27 | |
---|
28 | # Delete the branch if it already exists. This can happen if the branch |
---|
29 | # was merged, but we're still working on it. |
---|
30 | if SvnOps.does_url_exist(self.branch_local_url()): |
---|
31 | # This branch already exists. |
---|
32 | commit_message = "\n".join([commit_header, |
---|
33 | " Delete old branch", |
---|
34 | ]) |
---|
35 | new_rev = SvnOps.delete_branch(self.branch_local_url(), |
---|
36 | commit_message, logfile) |
---|
37 | if new_rev == -1: |
---|
38 | results['mergebotstate'] = 'branchfailed' |
---|
39 | comment = 'Deleting the existing branch failed.' |
---|
40 | return results, comment, False |
---|
41 | |
---|
42 | # Do the branch creationg |
---|
43 | commit_message = "\n".join([commit_header, |
---|
44 | " Create branch from %s for %s." % (self.version, |
---|
45 | self.requestor), |
---|
46 | ]) |
---|
47 | retval = SvnOps.create_branch(self.baseline_local_url(), |
---|
48 | self.branch_local_url(), commit_message, logfile) |
---|
49 | if retval: |
---|
50 | # Failed for some reason. |
---|
51 | results['mergebotstate'] = 'branchfailed' |
---|
52 | comment = 'Failed to create branch.' |
---|
53 | return results, comment, False |
---|
54 | |
---|
55 | results['mergebotstate'] = 'branched' |
---|
56 | comment = '\n'.join([ |
---|
57 | 'Created branch from %s for %s.' % (self.version, self.requestor), |
---|
58 | '', |
---|
59 | 'Browse branch [source:%s/branches/ticket-%s source code] and ' \ |
---|
60 | '[log:%s/branches/ticket-%s commit log].' % |
---|
61 | (self.component, self.ticket, self.component, self.ticket), |
---|
62 | '', |
---|
63 | 'To checkout, run:', |
---|
64 | '{{{', |
---|
65 | 'svn checkout %s %s-%s' % (self.branch_public_url(), |
---|
66 | self.component, self.ticket), |
---|
67 | '}}}', |
---|
68 | ]) |
---|
69 | return results, comment, True |
---|
70 | |
---|
71 | # vim:foldcolumn=4 foldmethod=indent |
---|
72 | # vim:tabstop=4 shiftwidth=4 softtabstop=4 expandtab |
---|