Fixed up implementation for buildbot 3.0.0
This commit is contained in:
parent
ada48bc6e5
commit
8d8626b38c
|
@ -18,36 +18,46 @@ from buildbot.process.results import WARNINGS
|
||||||
from buildbot.reporters import http
|
from buildbot.reporters import http
|
||||||
from buildbot.util import httpclientservice
|
from buildbot.util import httpclientservice
|
||||||
from buildbot.warnings import warn_deprecated
|
from buildbot.warnings import warn_deprecated
|
||||||
|
from buildbot.reporters.generators.build import BuildStartEndStatusGenerator
|
||||||
|
from buildbot.reporters.message import MessageFormatterRenderable
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
class GiteaStatusPush(http.HttpStatusPushBase):
|
class GiteaStatusPush(http.ReporterBase):
|
||||||
name = "GiteaStatusPush"
|
name = "GiteaStatusPush"
|
||||||
ssh_url_match = re.compile(r"(ssh://)?[\w+\-\_]+@[\w\.\-\_]+:?(\d*/)?(?P<owner>[\w_\-\.]+)/(?P<repo_name>[\w_\-\.]+?)(\.git)?$")
|
ssh_url_match = re.compile(r"(ssh://)?[\w+\-\_]+@[\w\.\-\_]+:?(\d*/)?(?P<owner>[\w_\-\.]+)/(?P<repo_name>[\w_\-\.]+?)(\.git)?$")
|
||||||
|
|
||||||
def checkConfig(self, baseURL, token, startDescription=None, endDescription=None,
|
def checkConfig(self, token, context=None, baseURL=None, verbose=False,
|
||||||
context=None, verbose=False, wantProperties=True, **kwargs):
|
debug=None, verify=None, generators=None,
|
||||||
super().checkConfig(wantProperties=wantProperties,
|
**kwargs):
|
||||||
_has_old_arg_names={
|
|
||||||
'builders': False,
|
if generators is None:
|
||||||
'wantProperties': wantProperties is not True
|
generators = self._create_default_generators()
|
||||||
}, **kwargs)
|
|
||||||
|
super().checkConfig(generators=generators, **kwargs)
|
||||||
|
httpclientservice.HTTPClientService.checkAvailable(
|
||||||
|
self.__class__.__name__)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def reconfigService(self, baseURL, token,
|
def reconfigService(self, baseURL, token,
|
||||||
startDescription=None, endDescription=None,
|
context=None, context_pr=None, verbose=False,
|
||||||
context=None, context_pr=None, verbose=False, wantProperties=True,
|
debug=None, verify=None,
|
||||||
|
generators=None,
|
||||||
warningAsSuccess=False, **kwargs):
|
warningAsSuccess=False, **kwargs):
|
||||||
|
|
||||||
token = yield self.renderSecrets(token)
|
token = yield self.renderSecrets(token)
|
||||||
yield super().reconfigService(wantProperties=wantProperties, **kwargs)
|
self.debug = debug
|
||||||
|
self.verify = verify
|
||||||
|
self.verbose = verbose
|
||||||
|
if generators is None:
|
||||||
|
generators = self._create_default_generators()
|
||||||
|
|
||||||
|
yield super().reconfigService(generators=generators, **kwargs)
|
||||||
|
|
||||||
self.context = context or Interpolate('buildbot/%(prop:buildername)s')
|
self.context = context or Interpolate('buildbot/%(prop:buildername)s')
|
||||||
self.context_pr = context_pr or \
|
self.context_pr = context_pr or \
|
||||||
Interpolate('buildbot/pull_request/%(prop:buildername)s')
|
Interpolate('buildbot/pull_request/%(prop:buildername)s')
|
||||||
self.startDescription = startDescription or 'Build started.'
|
|
||||||
self.endDescription = endDescription or 'Build done.'
|
|
||||||
if baseURL.endswith('/'):
|
if baseURL.endswith('/'):
|
||||||
baseURL = baseURL[:-1]
|
baseURL = baseURL[:-1]
|
||||||
self.baseURL = baseURL
|
self.baseURL = baseURL
|
||||||
|
@ -59,6 +69,15 @@ class GiteaStatusPush(http.HttpStatusPushBase):
|
||||||
self.project_ids = {}
|
self.project_ids = {}
|
||||||
self.warningAsSuccess = warningAsSuccess
|
self.warningAsSuccess = warningAsSuccess
|
||||||
|
|
||||||
|
def _create_default_generators(self):
|
||||||
|
start_formatter = MessageFormatterRenderable('Build started.')
|
||||||
|
end_formatter = MessageFormatterRenderable('Build done.')
|
||||||
|
|
||||||
|
return [
|
||||||
|
BuildStartEndStatusGenerator(start_formatter=start_formatter,
|
||||||
|
end_formatter=end_formatter)
|
||||||
|
]
|
||||||
|
|
||||||
def createStatus(self,
|
def createStatus(self,
|
||||||
project_owner, repo_name, sha, state, target_url=None,
|
project_owner, repo_name, sha, state, target_url=None,
|
||||||
description=None, context=None):
|
description=None, context=None):
|
||||||
|
@ -106,13 +125,17 @@ class GiteaStatusPush(http.HttpStatusPushBase):
|
||||||
warn_deprecated('2.9.0', 'send() in reporters has been deprecated. Use sendMessage()')
|
warn_deprecated('2.9.0', 'send() in reporters has been deprecated. Use sendMessage()')
|
||||||
yield self.send(build)
|
yield self.send(build)
|
||||||
else:
|
else:
|
||||||
yield self._send_impl(build)
|
yield self._send_impl(reports)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _send_impl(self, build):
|
def _send_impl(self, reports):
|
||||||
|
report = reports[0]
|
||||||
|
build = report['builds'][0]
|
||||||
props = Properties.fromDict(build['properties'])
|
props = Properties.fromDict(build['properties'])
|
||||||
props.master = self.master
|
props.master = self.master
|
||||||
|
|
||||||
|
description = report.get('body', None)
|
||||||
|
|
||||||
if build['complete']:
|
if build['complete']:
|
||||||
state = {
|
state = {
|
||||||
SUCCESS: 'success',
|
SUCCESS: 'success',
|
||||||
|
@ -123,10 +146,8 @@ class GiteaStatusPush(http.HttpStatusPushBase):
|
||||||
RETRY: 'pending',
|
RETRY: 'pending',
|
||||||
CANCELLED: 'error'
|
CANCELLED: 'error'
|
||||||
}.get(build['results'], 'failure')
|
}.get(build['results'], 'failure')
|
||||||
description = yield props.render(self.endDescription)
|
|
||||||
else:
|
else:
|
||||||
state = 'pending'
|
state = 'pending'
|
||||||
description = yield props.render(self.startDescription)
|
|
||||||
|
|
||||||
if 'pr_id' in props:
|
if 'pr_id' in props:
|
||||||
context = yield props.render(self.context_pr)
|
context = yield props.render(self.context_pr)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user