trigger: custom git payload JSON schema
This commit is contained in:
parent
876d9c53f2
commit
bd57c6a8fb
1 changed files with 42 additions and 43 deletions
|
@ -8,6 +8,7 @@ import json
|
||||||
|
|
||||||
from github import Github, UnknownObjectException, GithubException
|
from github import Github, UnknownObjectException, GithubException
|
||||||
from tempfile import SpooledTemporaryFile
|
from tempfile import SpooledTemporaryFile
|
||||||
|
from jsonschema import validate
|
||||||
|
|
||||||
from app import app, userfiles as user_files, github_trigger
|
from app import app, userfiles as user_files, github_trigger
|
||||||
from util.tarfileappender import TarfileAppender
|
from util.tarfileappender import TarfileAppender
|
||||||
|
@ -547,6 +548,43 @@ class GithubBuildTrigger(BuildTrigger):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
class CustomBuildTrigger(BuildTrigger):
|
class CustomBuildTrigger(BuildTrigger):
|
||||||
|
payload_schema = {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'commits': {'type': 'string'},
|
||||||
|
'ref': {'type': 'string'},
|
||||||
|
'default_branch': {'type': 'string'},
|
||||||
|
'commit_info': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'url': {'type': 'string'},
|
||||||
|
'message': {'type': 'string'},
|
||||||
|
'date': {'type': 'string'},
|
||||||
|
'author': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'username': {'type': 'string'},
|
||||||
|
'url': {'type': 'string'},
|
||||||
|
'avatar_url': {'type': 'string'},
|
||||||
|
},
|
||||||
|
'required': ['username', 'url', 'avatar_url'],
|
||||||
|
},
|
||||||
|
'committer': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'username': {'type': 'string'},
|
||||||
|
'url': {'type': 'string'},
|
||||||
|
'avatar_url': {'type': 'string'},
|
||||||
|
},
|
||||||
|
'required': ['username', 'url', 'avatar_url'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'required': ['url', 'message', 'date'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'required': ['commits', 'ref', 'default_branch'],
|
||||||
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def service_name(cls):
|
def service_name(cls):
|
||||||
return 'custom'
|
return 'custom'
|
||||||
|
@ -554,51 +592,12 @@ class CustomBuildTrigger(BuildTrigger):
|
||||||
def is_active(self, config):
|
def is_active(self, config):
|
||||||
return 'public_key' in config
|
return 'public_key' in config
|
||||||
|
|
||||||
@staticmethod
|
def _metadata_from_payload(self, payload):
|
||||||
def _metadata_from_payload(payload):
|
|
||||||
try:
|
try:
|
||||||
metadata = {
|
validate(json.loads(payload), self.payload_schema)
|
||||||
'commit_sha': payload['commit'],
|
except:
|
||||||
'ref': payload['ref'],
|
|
||||||
'default_branch': payload.get('default_branch', 'master'),
|
|
||||||
}
|
|
||||||
except KeyError:
|
|
||||||
raise InvalidPayloadException()
|
raise InvalidPayloadException()
|
||||||
|
return payload
|
||||||
commit_info = payload['commit_info']
|
|
||||||
if commit_info is not None:
|
|
||||||
try:
|
|
||||||
metadata['commit_info'] = {
|
|
||||||
'url': commit_info['url'],
|
|
||||||
'message': commit_info['message'],
|
|
||||||
'date': commit_info['date'],
|
|
||||||
}
|
|
||||||
except KeyError:
|
|
||||||
raise InvalidPayloadException()
|
|
||||||
|
|
||||||
author = commit_info['author']
|
|
||||||
if author is not None:
|
|
||||||
try:
|
|
||||||
metadata['commit_info']['author'] = {
|
|
||||||
'username': author['username'],
|
|
||||||
'avatar_url': author['avatar_url'],
|
|
||||||
'url': author['url'],
|
|
||||||
}
|
|
||||||
except KeyError:
|
|
||||||
raise InvalidPayloadException()
|
|
||||||
|
|
||||||
committer = commit_info['committer']
|
|
||||||
if committer is not None:
|
|
||||||
try:
|
|
||||||
metadata['commit_info']['committer'] = {
|
|
||||||
'username': committer['username'],
|
|
||||||
'avatar_url': committer['avatar_url'],
|
|
||||||
'url': committer['url'],
|
|
||||||
}
|
|
||||||
except KeyError:
|
|
||||||
raise InvalidPayloadException()
|
|
||||||
|
|
||||||
return metadata
|
|
||||||
|
|
||||||
def handle_trigger_request(self, request, trigger):
|
def handle_trigger_request(self, request, trigger):
|
||||||
payload = request.get_json()
|
payload = request.get_json()
|
||||||
|
|
Reference in a new issue