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

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

Mergebot: redesigned implementation. Still has rough edges.

File size: 3.2 KB
Line 
1#!/usr/bin/env python
2"""Module for creating new branches for tickets"""
3
4import os
5import time
6
7from mergebot import SvnOps
8from mergebot.Actor import Actor
9
10class 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        if not SvnOps.get_branch_info(self.local_url(), logfile):
23            comment = 'Component %s does not exist in the repository.' \
24                % self.component
25            return results, comment, False
26        if not SvnOps.get_branch_info(self.local_url() + '/branches', logfile):
27            comment = 'No directory in which to create branches for component %s in the repository.' % self.component
28            return results, comment, False
29        if not SvnOps.get_branch_info(self.baseline_local_url(), logfile):
30            comment = 'Version %s for component %s does not exist in the repository.' % (self.version, self.component)
31            return results, comment, False
32
33        commit_header = 'Ticket #%s: %s' % (self.ticket, self.summary)
34
35        # Delete the branch if it already exists.  This can happen if the branch
36        # was merged, but we're still working on it.
37        if SvnOps.get_branch_info(self.branch_local_url(), logfile):
38            # This branch already exists.
39            commit_message = "\n".join([commit_header,
40                "    Delete old branch",
41            ])
42            new_rev = SvnOps.delete_branch(self.branch_local_url(),
43                                           commit_message, logfile)
44            if new_rev == -1:
45                results['mergebotstate'] = 'branchfailed'
46                comment = 'Deleting the existing branch failed.'
47                return results, comment, False
48
49        # Do the branch creationg
50        commit_message = "\n".join([commit_header,
51            "    Create branch from %s for %s." % (self.version,
52                                                   self.requestor),
53        ])
54        retval = SvnOps.create_branch(self.baseline_local_url(),
55            self.branch_local_url(), commit_message, logfile)
56        if retval:
57            # Failed for some reason.
58            results['mergebotstate'] = 'branchfailed'
59            comment = 'Failed to create branch.'
60            return results, comment, False
61        results['mergebotstate'] = 'branched'
62        comment = '\n'.join([
63            'Created branch from %s for %s.' % (self.version, self.requestor),
64            '',
65            'Browse branch [source:%s/branches/ticket-%s source code] and [log:%s/branches/ticket-%s commit log].' %
66                (self.component, self.ticket, self.component, self.ticket),
67            '',
68            'To checkout, run:',
69            '{{{',
70            'svn checkout %s %s-%s' % (self.branch_public_url(),
71                                       self.component, self.ticket),
72            '}}}',
73        ])
74        return results, comment, True
75
76# vim:foldcolumn=4 foldmethod=indent
77# vim:tabstop=4 shiftwidth=4 softtabstop=4 expandtab
Note: See TracBrowser for help on using the repository browser.