def new_github(request):
    if request.method == 'POST':
        gform = GITHUBForm(request.POST, instance=GITHUB_Conf())
        if gform.is_valid():
            try:
                api_key = gform.cleaned_data.get('api_key')
                g = Github(api_key)
                user = g.get_user()
                logger.debug('Using user ' + user.login)

                new_j = gform.save(commit=False)
                new_j.api_key = api_key
                new_j.save()
                messages.add_message(request,
                                     messages.SUCCESS,
                                     'Github Configuration Successfully Created.',
                                     extra_tags='alert-success')
                return HttpResponseRedirect(reverse('github', ))
            except Exception as info:
                logger.error(info)
                messages.add_message(request,
                                     messages.ERROR,
                                     'Unable to authenticate on github.',
                                     extra_tags='alert-danger')
                return HttpResponseRedirect(reverse('github', ))
    else:
        gform = GITHUBForm()
        add_breadcrumb(title="New Github Configuration", top_level=False, request=request)
        return render(request, 'dojo/new_github.html',
                    {'gform': gform})