source: mergebot/trunk/mergebot/BranchActor.py @ 24

Last change on this file since 24 was 24, checked in by retracile, 15 years ago

Ticket #2: merge to trunk

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