Esempio n. 1
0
 def testParsePayload3(self):
     """No phabAction are (yet) generated with issue_comment"""
     self.assertEqual(
         fcts.parsePayload(payload=loads(
             openfile('payload13-issuecomment')),
                           event='issue_comment',
                           reponame='repo',
                           branch='branch'), [])
Esempio n. 2
0
 def testParsePayload2(self):
     """The good task id is returned"""
     self.assertEqual(
         fcts.parsePayload(payload=loads(
             openfile('payload2-commitfileedit')),
                           event='push',
                           reponame='repo',
                           branch='branch')[0]['taskid'], ['T1234'])
Esempio n. 3
0
 def testParsePayload1(self):
     """A phabAction is generated with this push"""
     self.assertEqual(
         len(
             fcts.parsePayload(payload=loads(
                 openfile('payload2-commitfileedit')),
                               event='push',
                               reponame='repo',
                               branch='branch')), 1)
Esempio n. 4
0
 def testParsePayload5(self):
     """Two phabActions are generated with this push"""
     self.assertEqual(
         len(
             fcts.parsePayload(payload=loads(
                 openfile('payload15-commit1pushed2commitsformcli')),
                               event='push',
                               reponame='repo',
                               branch='branch')), 2)
Esempio n. 5
0
 def testParsePayload4(self):
     """A phabAction is generated with pull_request merged"""
     self.assertEqual(
         len(
             fcts.parsePayload(payload=loads(
                 openfile('payload10-prclosedmerged1')),
                               event='pull_request',
                               reponame='repo',
                               branch='branch')), 1)
Esempio n. 6
0
def index():
    # if request.method != 'POST':
    #   abort(501)

    # Verify IP in Github ones whitelist
    assert request.remote_addr
    if not ipWhitelist.is_ok(request.remote_addr):
        abort(403)

    # If Github wants to verify that we exist
    event = request.headers.get('X-GitHub-Event', None)
    if not event:
        return dumps({'msg': 'Hello here'})

    # Get datas
    payload = loads(request.data)
    branch = fcts.getBranch(payload, event)
    reponame = fcts.getRepoName(payload)

    # Verify repository name in whitelist
    assert reponame
    if not repoWhitelist.is_ok(reponame):
        abort(403)

    # Analys datas
    phabActions = fcts.parsePayload(payload=payload,
                                    event=event,
                                    reponame=reponame,
                                    branch=branch)
    logging.info('PhabActions: %s: %s' %
                 (len(phabActions), ' ; '.join(phabActions)))

    # Ececute
    if not phabActions:
        return dumps({'msg': 'this action is out of scope'})
    for phabAction in phabActions:
        if not phabAction['taskid']:
            continue
        fcts.postComment(host=config.get('host', None),
                         token=config.get('token', None),
                         taskID=phabAction['taskid'],
                         comment=fcts.generateComment(phabAction),
                         patchForReview=phabAction['patchForReview'])

    return dumps({'msg': '%s actions done' % len(phabActions)})