Skip to content

Commit 411fb46

Browse files
committed
1 parent 6b46066 commit 411fb46

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

app/app/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
re_path(r'^bounty/quickstart/?', dashboard.views.quickstart, name='quickstart'),
156156
url(r'^bounty/new/?', dashboard.views.new_bounty, name='new_bounty'),
157157
re_path(r'^bounty/change/(?P<bounty_id>.*)?', dashboard.views.change_bounty, name='change_bounty'),
158+
re_path(r'^bounty/resync/(?P<bounty_id>.*)?', dashboard.views.sync_bounty_with_github, name='sync_bounty_with_github'),
158159
url(r'^funding/new/?', dashboard.views.new_bounty, name='new_funding'), # TODO: Remove
159160
url(r'^new/?', dashboard.views.new_bounty, name='new_funding_short'), # TODO: Remove
160161
# TODO: Rename below to bounty/

app/assets/v2/js/pages/bounty_details.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ var do_actions = function(result) {
10031003
let show_extend_deadline = isBountyOwner(result) && !is_status_expired && !is_status_done;
10041004
let show_invoice = isBountyOwner(result);
10051005
let show_notify_funder = is_open && has_fulfilled;
1006-
1006+
let show_sync_bounty = isBountyOwner(result) && is_open && result['repo_type'] == 'public';
10071007

10081008
const show_suspend_auto_approval = currentProfile.isStaff && result['permission_type'] == 'approval' && !result['admin_override_suspend_auto_approval'];
10091009
const show_admin_methods = currentProfile.isStaff;
@@ -1140,7 +1140,17 @@ var do_actions = function(result) {
11401140

11411141
actions.push(_entry);
11421142
}
1143-
1143+
if (show_sync_bounty) {
1144+
const _entry = {
1145+
enabled: true,
1146+
href: '/bounty/resync/' + result['pk'],
1147+
text: gettext('Resync Description'),
1148+
parent: 'right_actions',
1149+
title: gettext('Sync Bounty Description with Github')
1150+
};
1151+
1152+
actions.push(_entry);
1153+
}
11441154
if (show_change_bounty) {
11451155
const _entry = [
11461156
{
@@ -1159,9 +1169,11 @@ var do_actions = function(result) {
11591169
// }
11601170
];
11611171

1172+
11621173
actions.push(..._entry);
11631174
}
11641175

1176+
11651177
if (show_github_link) {
11661178
let github_url = result['github_url'];
11671179
// hack to get around the renamed repo for piper's work. can't change the data layer since blockchain is immutable

app/dashboard/views.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from economy.utils import convert_token_to_usdt
5454
from eth_utils import to_checksum_address, to_normalized_address
5555
from gas.utils import recommend_min_gas_price_to_confirm_in_time
56-
from git.utils import get_auth_url, get_github_user_data, is_github_token_valid, search_users
56+
from git.utils import get_auth_url, get_gh_issue_details, get_github_user_data, is_github_token_valid, search_users
5757
from kudos.models import KudosTransfer, Token, Wallet
5858
from kudos.utils import humanize_name
5959
from marketing.mails import admin_contact_funder, bounty_uninterested
@@ -2663,6 +2663,37 @@ def change_bounty(request, bounty_id):
26632663
}
26642664
return TemplateResponse(request, 'bounty/change.html', params)
26652665

2666+
@csrf_exempt
2667+
@ratelimit(key='ip', rate='5/m', method=ratelimit.UNSAFE, block=True)
2668+
def sync_bounty_with_github(request, bounty_id):
2669+
user = request.user if request.user.is_authenticated else None
2670+
2671+
if not user:
2672+
if request.body:
2673+
return JsonResponse(
2674+
{'error': _('You must be authenticated via github to use this feature!')},
2675+
status=401)
2676+
else:
2677+
return redirect('/login/github?next=' + request.get_full_path())
2678+
2679+
try:
2680+
bounty_id = int(bounty_id)
2681+
bounty = Bounty.objects.get(pk=bounty_id)
2682+
except:
2683+
if request.body:
2684+
return JsonResponse({'error': _('Bounty doesn\'t exist!')}, status=404)
2685+
else:
2686+
raise Http404
2687+
logger.info(settings.GITHUB_API_TOKEN)
2688+
args = bounty.github_url.split('/')
2689+
github_details = get_gh_issue_details(bounty.bounty_owner_github_username, args[4], int(args[6]), settings.GITHUB_API_TOKEN)
2690+
logger.info(github_details)
2691+
bounty.github_issue_details = github_details
2692+
bounty.issue_description = github_details['description']
2693+
bounty.title = github_details['title']
2694+
bounty.save()
2695+
2696+
return redirect(f'/issue/{args[3]}/{args[4]}/{args[6]}/{bounty.standard_bounties_id}')
26662697

26672698
def get_users(request):
26682699
token = request.GET.get('token', None)

0 commit comments

Comments
 (0)