Exemplo n.º 1
0
def handle_github_payload(request):
    if request.method == 'POST':
        payload = json.loads(request.POST.get('payload'))

        fb = FogBugz(settings.FOGBUGZ_URL)
        fb._token = None

        commits = payload['commits']

        if commits:
            for c in commits:
                user = FogBugzLogin.objects.filter(
                    email = c['author']['email'])
                if user:
                    user = user[0]

                    fb._token = user.fogbugz_token

                    message = c['message']
                    commit_hash = c['id']
                    case_ids, fb_message = parse_commit_message(message,
                                                                commit_hash)

                    try:
                        for case_id in case_ids:
                            post_message(fb, case_id, fb_message, commit_hash)
                    except FogBugzAPIError as e:
                        send_error_email(e.message)
                        break

        return HttpResponse('Thanks, GitHub!')

    # we don't want any GET requests on this page.  Only POST
    return HttpResponse('Move along. Nothing to see here.')
Exemplo n.º 2
0
    def testParseCommitMessage(self):
        case_ids, message = util.parse_commit_message(
            commits[0]['message'],
            commits[0]['id'])

        self.assertEqual(
            message,
            u'okay i give in\n\n-- Via GitHub\ncommit id: '
            u'41a212ee83ca127e3c8cf465891ab7216a705f59')
        self.assertEqual(
            case_ids,
            ['1234'])

        case_ids, message = util.parse_commit_message(
            commits[1]['message'],
            commits[1]['id'])

        self.assertEqual(
            message,
            u'update pricing a tad\n\n-- Via GitHub\ncommit id: '
            u'de8251ff97ee194a289832576287d6f8ad74e3d0')
        self.assertEqual(
            case_ids,
            ['5678'])