From 411fb46601b911f0737f92f7bdd523b6b76403e7 Mon Sep 17 00:00:00 2001 From: acolytec3 <17355484+acolytec3@users.noreply.github.com> Date: Tue, 30 Jul 2019 07:47:39 -0400 Subject: [PATCH] Fixes #4870 --- app/app/urls.py | 1 + app/assets/v2/js/pages/bounty_details.js | 16 ++++++++++-- app/dashboard/views.py | 33 +++++++++++++++++++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/app/app/urls.py b/app/app/urls.py index be74a42d439..e018ffd5ee9 100644 --- a/app/app/urls.py +++ b/app/app/urls.py @@ -155,6 +155,7 @@ re_path(r'^bounty/quickstart/?', dashboard.views.quickstart, name='quickstart'), url(r'^bounty/new/?', dashboard.views.new_bounty, name='new_bounty'), re_path(r'^bounty/change/(?P.*)?', dashboard.views.change_bounty, name='change_bounty'), + re_path(r'^bounty/resync/(?P.*)?', dashboard.views.sync_bounty_with_github, name='sync_bounty_with_github'), url(r'^funding/new/?', dashboard.views.new_bounty, name='new_funding'), # TODO: Remove url(r'^new/?', dashboard.views.new_bounty, name='new_funding_short'), # TODO: Remove # TODO: Rename below to bounty/ diff --git a/app/assets/v2/js/pages/bounty_details.js b/app/assets/v2/js/pages/bounty_details.js index 694c923952a..760f6bf9e0b 100644 --- a/app/assets/v2/js/pages/bounty_details.js +++ b/app/assets/v2/js/pages/bounty_details.js @@ -1003,7 +1003,7 @@ var do_actions = function(result) { let show_extend_deadline = isBountyOwner(result) && !is_status_expired && !is_status_done; let show_invoice = isBountyOwner(result); let show_notify_funder = is_open && has_fulfilled; - + let show_sync_bounty = isBountyOwner(result) && is_open && result['repo_type'] == 'public'; const show_suspend_auto_approval = currentProfile.isStaff && result['permission_type'] == 'approval' && !result['admin_override_suspend_auto_approval']; const show_admin_methods = currentProfile.isStaff; @@ -1140,7 +1140,17 @@ var do_actions = function(result) { actions.push(_entry); } - + if (show_sync_bounty) { + const _entry = { + enabled: true, + href: '/bounty/resync/' + result['pk'], + text: gettext('Resync Description'), + parent: 'right_actions', + title: gettext('Sync Bounty Description with Github') + }; + + actions.push(_entry); + } if (show_change_bounty) { const _entry = [ { @@ -1159,9 +1169,11 @@ var do_actions = function(result) { // } ]; + actions.push(..._entry); } + if (show_github_link) { let github_url = result['github_url']; // hack to get around the renamed repo for piper's work. can't change the data layer since blockchain is immutable diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 9f53d4ca923..95338ea3960 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -53,7 +53,7 @@ from economy.utils import convert_token_to_usdt from eth_utils import to_checksum_address, to_normalized_address from gas.utils import recommend_min_gas_price_to_confirm_in_time -from git.utils import get_auth_url, get_github_user_data, is_github_token_valid, search_users +from git.utils import get_auth_url, get_gh_issue_details, get_github_user_data, is_github_token_valid, search_users from kudos.models import KudosTransfer, Token, Wallet from kudos.utils import humanize_name from marketing.mails import admin_contact_funder, bounty_uninterested @@ -2663,6 +2663,37 @@ def change_bounty(request, bounty_id): } return TemplateResponse(request, 'bounty/change.html', params) +@csrf_exempt +@ratelimit(key='ip', rate='5/m', method=ratelimit.UNSAFE, block=True) +def sync_bounty_with_github(request, bounty_id): + user = request.user if request.user.is_authenticated else None + + if not user: + if request.body: + return JsonResponse( + {'error': _('You must be authenticated via github to use this feature!')}, + status=401) + else: + return redirect('/login/github?next=' + request.get_full_path()) + + try: + bounty_id = int(bounty_id) + bounty = Bounty.objects.get(pk=bounty_id) + except: + if request.body: + return JsonResponse({'error': _('Bounty doesn\'t exist!')}, status=404) + else: + raise Http404 + logger.info(settings.GITHUB_API_TOKEN) + args = bounty.github_url.split('/') + github_details = get_gh_issue_details(bounty.bounty_owner_github_username, args[4], int(args[6]), settings.GITHUB_API_TOKEN) + logger.info(github_details) + bounty.github_issue_details = github_details + bounty.issue_description = github_details['description'] + bounty.title = github_details['title'] + bounty.save() + + return redirect(f'/issue/{args[3]}/{args[4]}/{args[6]}/{bounty.standard_bounties_id}') def get_users(request): token = request.GET.get('token', None)