2 # -*- coding: utf-8 -*-
7 Copyright (c) 2014 Frédéric Massart - FMCorz.net
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 http://github.com/FMCorz/mdk
27 from .. import tools
, jira
28 from ..ci
import CI
, CIException
29 from ..command
import Command
32 class PrecheckCommand(Command
):
39 'help': 'the branch to pre-check. Defaults to the current branch.'
45 'action': 'store_true',
46 'help': 'if set, the branch will be pushed to your default remote.'
53 'help': 'name of the instance',
59 _description
= 'Pre-checks a branch on the CI server'
64 M
= self
.Wp
.resolve(args
.name
)
66 raise Exception('This is not a Moodle instance')
68 against
= M
.get('stablebranch')
69 branch
= args
.branch
or M
.currentBranch()
71 raise Exception('Cannot pre-check the HEAD branch')
72 elif branch
== against
:
73 raise Exception('Cannot pre-check the stable branch')
75 parsedbranch
= tools
.parseBranch(branch
)
77 raise Exception('Could not parse the branch')
79 issue
= parsedbranch
['issue']
83 if J
.isSecurityIssue('MDL-%s' %
(issue
)):
84 raise Exception('Security issues cannot be pre-checked')
86 remote
= self
.C
.get('myRemote')
87 logging
.info('Pushing branch \'%s\' to remote \'%s\'', branch
, remote
)
88 result
= M
.git().push(remote
, branch
)
90 raise Exception('Could not push the branch:\n %s' % result
[2])
94 # TODO Remove that ugly hack to get the read-only remote.
95 logging
.info('Invoking the build on the CI server...')
96 build
= ci
.precheckRemoteBranch(self
.C
.get('repositoryUrl'), branch
, against
, 'MDL-%s' % issue
)
97 except CIException
as e
:
100 logging
.info('Waiting for the build to complete, please wait...')
101 build
.block_until_complete(3)
104 logging
.info('Precheck passed, good work!')
107 logging
.warning('Precheck failed, refer to:\n %s', build
.baseurl
)
108 sys
.exit(self
.FAILED
)