Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Jul 30, 2019
1 parent 6b46066 commit 411fb46
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<bounty_id>.*)?', dashboard.views.change_bounty, name='change_bounty'),
re_path(r'^bounty/resync/(?P<bounty_id>.*)?', 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/
Expand Down
16 changes: 14 additions & 2 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [
{
Expand All @@ -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
Expand Down
33 changes: 32 additions & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 411fb46

Please sign in to comment.