github.com/whamcloud/lemur@v0.0.0-20190827193804-4655df8a52af/packaging/ci/lambda/lemur_ci/commit_status.py (about) 1 import json 2 import re 3 4 5 class Message: 6 def __init__(self, repoUrl, sha, state, statusUrl=None, context=None, description=None): 7 self.repoUrl = repoUrl 8 self.sha = sha 9 self.state = state 10 self.statusUrl = statusUrl 11 self.context = context 12 self.description = description 13 14 (self.repoScheme, self.repoHost, self.repoOrgOrUser, self.repo) = re.match(r'^(https?://)([^/]+)/([^/]+)/([^/]+)$', self.repoUrl).groups() 15 16 @property 17 def api_url(self): 18 return self.repoScheme+'api.'+self.repoHost 19 20 @property 21 def json(self): 22 return json.dumps(self.as_kwargs()) 23 24 def as_kwargs(self): 25 return dict((k,v) for k,v in dict( 26 repoUrl=self.repoUrl, 27 sha=self.sha, 28 state=self.state, 29 statusUrl=self.statusUrl, 30 context=self.context, 31 description=self.description 32 ).iteritems() if v is not None) 33 34 def as_status(self): 35 status = self.as_kwargs() 36 if 'statusUrl' in status: 37 status['target_url'] = status['statusUrl'] 38 del status['statusUrl'] 39 del status['repoUrl'] 40 del status['sha'] 41 return status