-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (38 loc) · 1.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
from flask import Flask
from flask import request
from common.GithubHelper import GithubHelper
from common.PullRequestLinkComment import PullRequestLinkComment
from resolvers.Appveyor import Appveyor
from resolvers.CircleCi import CircleCI
from settings import settings
app = Flask(__name__)
resolvers = [
Appveyor,
CircleCI
]
@app.route('/', methods=['POST'])
def main():
json_data = json.loads(request.data.decode('utf-8'))
if json_data.get('state', '') != 'success':
return "state is not success"
pull_request = GithubHelper(settings=settings.github).find_pr_from_commit(json_data['repository']['full_name'],
json_data['commit']['sha'])
if pull_request is None:
return "Could not find a pull request for this sha"
if GithubHelper.has_ignored_labels(settings.pull_request, pull_request):
return "Pull Request ignored (has a ignore label)"
resolver = None
url = json_data['target_url']
for resolver_cls in resolvers:
if resolver_cls.is_resolver_url(url):
resolver = resolver_cls(url=url)
break
if resolver is None:
return "Can't find resolver for {}".format(url)
build_result = resolver.create_build_result(settings.platforms)
if not build_result:
return "Could not find any artifact"
pr_comment = PullRequestLinkComment(settings)
pr_comment.update_or_create_links_comment(pull_request, build_result)
return 'Success'