Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to sync Github issue #4899

Merged
merged 6 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 66 additions & 21 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,57 @@ 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) {
var alertMsg = result && result.responseJSON ? result.responseJSON.error : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we update this to let ?


if (alertMsg === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on making it as

let alertMsg = result && result.responseJSON ? result.responseJSON.error : gettext('Failed to sync issue. Please reload the page and try again.');

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ let


if (alertMsg === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let alertMsg = result && result.responseJSON ? result.responseJSON.error : gettext('Failed to sync issue. Please reload the page and try again.');

alertMsg = 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 @@ -933,6 +984,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 @@ -1028,7 +1080,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 @@ -1044,7 +1096,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 @@ -1067,7 +1119,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 @@ -1082,7 +1134,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 @@ -1097,7 +1149,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 @@ -1110,7 +1162,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 @@ -1123,7 +1175,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 @@ -1135,7 +1187,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 @@ -1148,16 +1200,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 @@ -1174,9 +1219,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 @@ -1192,7 +1237,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 @@ -2599,7 +2599,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 @@ -2626,18 +2626,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