Skip to content

Commit

Permalink
Merge pull request #4899 from PierrickGT/features/sync_issue_button
Browse files Browse the repository at this point in the history
Add button to sync Github issue
  • Loading branch information
octavioamu authored Aug 7, 2019
2 parents 456e64a + d8e37f7 commit e786817
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 34 deletions.
81 changes: 60 additions & 21 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,51 @@ var show_extend_deadline_modal = function() {
});
};

const appendGithubSyncButton = function(result) {
if (isBountyOwner(result) || currentProfile.isStaff) {
const title = gettext('Sync Issue');

$('#github_actions').append('<button sync-github-issue id="btn-white" type="button" class="btn btn-small">' + title + '</button>');

$('#github_actions [sync-github-issue]').on('click', function(e) {
const bountyId = result.pk;

e.preventDefault();

$.get(
'/sync/get_issue_details?url=' + encodeURIComponent(result['github_url']) + '&token=' + currentProfile.githubToken
).then(function(result) {
const payload = JSON.stringify({
issue_description: result.description
});

return $.post('/bounty/change/' + bountyId, payload).then(
function(result) {
result = sanitizeAPIResults(result);
_alert({ message: result.msg }, 'success');

if (result.url) {
setTimeout(function() {
document.location.href = result.url;
}, 1000);
}
}
).fail(
function(result) {
const alertMsg = result && result.responseJSON ? result.responseJSON.error : gettext('Failed to sync issue. Please reload the page and try again.');

_alert({ message: alertMsg }, 'error');
}
);
}).fail(function(result) {
const alertMsg = result && result.responseJSON ? result.responseJSON.error : gettext('Failed to sync issue. Please reload the page and try again.');

_alert({ message: alertMsg }, 'error');
});
});
}
};

var build_detail_page = function(result) {

// setup
Expand Down Expand Up @@ -937,6 +982,7 @@ var build_detail_page = function(result) {
});

$('#bounty_details #issue_description code').parent().addClass('code-snippet');
appendGithubSyncButton(result);
};

const is_current_user_interested = function(result) {
Expand Down Expand Up @@ -1032,7 +1078,7 @@ var do_actions = function(result) {
enabled: enabled,
href: result['action_urls']['fulfill'],
text: gettext('Submit Work'),
parent: 'right_actions',
parent: 'bounty_actions',
title: gettext('Submit work for the funder to review'),
work_started: is_interested,
id: 'submit'
Expand All @@ -1048,7 +1094,7 @@ var do_actions = function(result) {
enabled: enabled,
href: '#',
text: gettext('Send Payment Reminder'),
parent: 'right_actions',
parent: 'bounty_actions',
title: gettext('Send Payment Reminder'),
id: 'notifyFunder',
clickhandler: show_modal_handler(url),
Expand All @@ -1071,7 +1117,7 @@ var do_actions = function(result) {
enabled: enabled,
href: is_interested ? '/uninterested' : '/interested',
text: text,
parent: 'right_actions',
parent: 'bounty_actions',
title: is_interested ? gettext('Notify the funder that you will not be working on this project') : gettext('Notify the funder that you would like to take on this project'),
color: is_interested ? '' : '',
id: 'interest'
Expand All @@ -1086,7 +1132,7 @@ var do_actions = function(result) {
enabled: enabled,
href: result['action_urls']['cancel'],
text: gettext('Cancel Bounty'),
parent: 'right_actions',
parent: 'bounty_actions',
title: gettext('Cancel bounty and reclaim funds for this issue'),
buttonclass: 'button--warning'
};
Expand All @@ -1101,7 +1147,7 @@ var do_actions = function(result) {
href: result['action_urls']['payout'],
text: gettext('Payout Bounty'),
title: gettext('Payout the bounty to one or more submitters.'),
parent: 'right_actions'
parent: 'bounty_actions'
};

actions.push(_entry);
Expand All @@ -1114,7 +1160,7 @@ var do_actions = function(result) {
enabled: enabled,
href: result['action_urls']['contribute'],
text: gettext('Contribute'),
parent: 'right_actions',
parent: 'bounty_actions',
title: gettext('Help by funding or promoting this issue')
};

Expand All @@ -1127,7 +1173,7 @@ var do_actions = function(result) {
enabled: enabled,
href: '/extend-deadlines',
text: gettext('Extend Expiration'),
parent: 'right_actions',
parent: 'bounty_actions',
title: gettext('Extend deadline of an issue')
};

Expand All @@ -1139,7 +1185,7 @@ var do_actions = function(result) {
enabled: true,
href: result['action_urls']['invoice'],
text: gettext('Show Invoice'),
parent: 'right_actions',
parent: 'bounty_actions',
title: gettext('View an Invoice for this Issue')
};

Expand All @@ -1152,16 +1198,9 @@ var do_actions = function(result) {
enabled: true,
href: '/bounty/change/' + result['pk'],
text: gettext('Edit Issue Details'),
parent: 'right_actions',
parent: 'bounty_actions',
title: gettext('Update your Bounty Settings to get the right Crowd')
}// ,
// {
// enabled: true,
// href: '/issue/refund_request?pk=' + result['pk'],
// text: gettext('Request Fee Refund'),
// parent: 'right_actions',
// title: gettext('Raise a request if you believe you need your fee refunded')
// }
}
];

actions.push(..._entry);
Expand All @@ -1178,9 +1217,9 @@ var do_actions = function(result) {
enabled: true,
href: github_url,
text: (result['repo_type'] === 'private' ? '<i class="fas fa-lock"></i> ' +
gettext('Private Repo') : gettext('View On Github')) +
(result['is_issue_closed'] ? gettext(' (Issue is closed)') : ''),
parent: 'right_actions',
gettext('Private Repo') : gettext('View On Github')) +
(result['is_issue_closed'] ? gettext(' (Issue is closed)') : ''),
parent: 'github_actions',
title: gettext('View issue details and comments on Github'),
comments: result['github_comments'],
color: 'white'
Expand All @@ -1196,7 +1235,7 @@ var do_actions = function(result) {
enabled: true,
href: job_url,
text: gettext('View Attached Job Description'),
parent: 'right_actions',
parent: 'bounty_actions',
title: gettext('This bounty funder is hiring for a full time, part time, or contract role and has attached that to this bounty.'),
color: 'white'
};
Expand Down
2 changes: 2 additions & 0 deletions app/dashboard/templates/bounty/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ <h4 id="title" class="font-title"></h4>
<button type="button" class="modal-link button button--primary float-right" data-toggle="modal" data-target=".share-modal">
<span class="font-caption"><i class="fas fa-share-alt mr-2"></i> Share</span>
</button>
<div id="bounty_actions" class="d-inline-block"></div>
<div id="github_actions" class="d-inline-block"></div>
</div>
</div>
</div>
Expand Down
27 changes: 14 additions & 13 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,7 @@ def change_bounty(request, bounty_id):
else:
raise Http404

keys = ['experience_level', 'project_length', 'bounty_type', 'featuring_date', 'bounty_categories',
keys = ['experience_level', 'project_length', 'bounty_type', 'featuring_date', 'bounty_categories', 'issue_description',
'permission_type', 'project_type', 'reserved_for_user_handle', 'is_featured', 'admin_override_suspend_auto_approval']

if request.body:
Expand All @@ -2625,18 +2625,19 @@ def change_bounty(request, bounty_id):
new_reservation = False
for key in keys:
value = params.get(key, 0)
if key == 'featuring_date':
value = timezone.make_aware(
timezone.datetime.fromtimestamp(int(value)),
timezone=UTC)
if key == 'bounty_categories':
value = value.split(',')
old_value = getattr(bounty, key)
if value != old_value:
setattr(bounty, key, value)
bounty_changed = True
if key == 'reserved_for_user_handle' and value:
new_reservation = True
if value != 0:
if key == 'featuring_date':
value = timezone.make_aware(
timezone.datetime.fromtimestamp(int(value)),
timezone=UTC)
if key == 'bounty_categories':
value = value.split(',')
old_value = getattr(bounty, key)
if value != old_value:
setattr(bounty, key, value)
bounty_changed = True
if key == 'reserved_for_user_handle' and value:
new_reservation = True

if not bounty_changed:
return JsonResponse({
Expand Down

0 comments on commit e786817

Please sign in to comment.