[16] | 1 | #!/usr/bin/env python |
---|
| 2 | """Module for creating new branches for tickets""" |
---|
| 3 | |
---|
| 4 | import time |
---|
| 5 | |
---|
[17] | 6 | from mergebot import SvnOps |
---|
| 7 | from mergebot.Actor import Actor |
---|
[16] | 8 | |
---|
[17] | 9 | class 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)) |
---|
[16] | 19 | |
---|
[17] | 20 | # Make sure the various urls we require do exist |
---|
[24] | 21 | problems = self.check_required_directories() |
---|
| 22 | if problems: |
---|
| 23 | return results, problems, False |
---|
[16] | 24 | |
---|
[17] | 25 | commit_header = 'Ticket #%s: %s' % (self.ticket, self.summary) |
---|
[16] | 26 | |
---|
[17] | 27 | # Delete the branch if it already exists. This can happen if the branch |
---|
| 28 | # was merged, but we're still working on it. |
---|
[24] | 29 | if SvnOps.does_url_exist(self.branch_local_url()): |
---|
[17] | 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 |
---|
[16] | 40 | |
---|
[17] | 41 | # Do the branch creationg |
---|
[16] | 42 | commit_message = "\n".join([commit_header, |
---|
[17] | 43 | " Create branch from %s for %s." % (self.version, |
---|
| 44 | self.requestor), |
---|
[16] | 45 | ]) |
---|
[17] | 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 |
---|
[29] | 53 | |
---|
[17] | 54 | results['mergebotstate'] = 'branched' |
---|
| 55 | comment = '\n'.join([ |
---|
| 56 | 'Created branch from %s for %s.' % (self.version, self.requestor), |
---|
| 57 | '', |
---|
[24] | 58 | 'Browse branch [source:%s/branches/ticket-%s source code] and ' \ |
---|
| 59 | '[log:%s/branches/ticket-%s commit log].' % |
---|
[17] | 60 | (self.component, self.ticket, self.component, self.ticket), |
---|
| 61 | '', |
---|
| 62 | 'To checkout, run:', |
---|
| 63 | '{{{', |
---|
| 64 | 'svn checkout %s %s-%s' % (self.branch_public_url(), |
---|
| 65 | self.component, self.ticket), |
---|
| 66 | '}}}', |
---|
[16] | 67 | ]) |
---|
[17] | 68 | return results, comment, True |
---|
[16] | 69 | |
---|
| 70 | # vim:foldcolumn=4 foldmethod=indent |
---|
| 71 | # vim:tabstop=4 shiftwidth=4 softtabstop=4 expandtab |
---|