Ejemplo n.º 1
0
def issue_details(request):
    """Determine the Github issue keywords of the specified Github issue or PR URL.

    Todo:
        * Modify the view to only use the Github API (remove BeautifulSoup).
        * Simplify the view logic.

    Returns:
        JsonResponse: A JSON response containing the Github issue or PR keywords.

    """
    from dashboard.utils import clean_bounty_url
    response = {}
    token = request.GET.get('token', None)
    url = request.GET.get('url')
    url_val = URLValidator()
    hackathon_slug = request.GET.get('hackathon_slug')
    duplicates = request.GET.get('duplicates', False)
    network = request.GET.get('network', 'mainnet')


    if hackathon_slug:
        sponsor_profiles = HackathonEvent.objects.filter(slug__iexact=hackathon_slug).prefetch_related('sponsor_profiles').values_list('sponsor_profiles__handle', flat=True)
        org_issue = org_name(url).lower()

        if org_issue not in sponsor_profiles:
            message = 'This issue is not under any sponsor repository'
            return JsonResponse({'status':'false','message':message}, status=404)

    if duplicates:
        if Bounty.objects.filter(github_url=url, network=network).exists():
            message = 'Bounty already exists for this github issue'
            response = {
                'status': 422,
                'message': message
            }
            return JsonResponse(response, status=422)

    try:
        url_val(url)
    except ValidationError:
        response['message'] = 'invalid arguments'
        return JsonResponse(response)

    if url.lower()[:19] != 'https://github.com/':
        response['message'] = 'invalid arguments'
        return JsonResponse(response)

    url_dict = get_url_dict(clean_bounty_url(url))

    try:
        if url_dict:
            response = get_gh_issue_details(token=token, **url_dict)
        else:
            response['message'] = 'could not parse Github url'
    except Exception as e:
        logger.warning(e)
        message = 'could not pull back remote response'
        return JsonResponse({'status':'false','message':message}, status=404)
    return JsonResponse(response)
Ejemplo n.º 2
0
def issue_details(request):
    """Determine theissue keywords of the specified issue or PR URL.

    Todo:
        * Modify the view to only use the Github API (remove BeautifulSoup).
        * Simplify the view logic.

    Returns:
        JsonResponse: A JSON response containing the issue or PR keywords.

    """
    from dashboard.utils import clean_bounty_url
    response = {}
    token = request.GET.get('token', None)
    url = request.GET.get('url')
    url_val = URLValidator()

    try:
        url_val(url)
    except ValidationError:
        response['message'] = 'invalid arguments'
        return JsonResponse(response)

    if url.lower()[:19] != 'https://github.com/' and url.lower(
    )[:19] != 'https://gitlab.com/':
        response['message'] = 'invalid arguments'
        return JsonResponse(response)

    try:
        url_dict = get_url_dict(clean_bounty_url(url))
        if url_dict:
            logger.info(url_dict)
            response = get_issue_details(token=token, **url_dict)
        else:
            response['message'] = 'could not parse url'
    except Exception as e:
        logger.warning(e)
        response['message'] = 'could not pull back remote response'
    return JsonResponse(response)
Ejemplo n.º 3
0
 def test_clean_bounty_url():
     """Test the cleaning of a bounty-esque URL of # sections."""
     assert clean_bounty_url(
         'https://github.com/gitcoinco/web/issues/9999#issuecomment-999999999'
     ) == 'https://github.com/gitcoinco/web/issues/9999'