com web/qa: implement setting labels: pulls/api.php pulls/index.php pulls/pullrequests.js
| From: | Anatol Belski | Date: | Fri, 11 Nov 2016 18:17:55 +0000 |
| Subject: | com web/qa: implement setting labels: pulls/api.php pulls/index.php pulls/pullrequests.js | ||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-67845@lists.php.net to get a copy of this message | ||
Commit: c665e91b8cf2d152e599ae4b1834aeb20046952e
Author: Anatol Belski <ab@php.net> Fri, 11 Nov 2016 19:17:55 +0100
Parents: 7e0c0ceed1d13766a2e47370495c9fc1a005b8b6
Branches: master
Link: http://git.php.net/?p=web/qa.git;a=commitdiff;h=c665e91b8cf2d152e599ae4b1834aeb20046952e
Log:
implement setting labels
Changed paths:
M pulls/api.php
M pulls/index.php
M pulls/pullrequests.js
Diff:
diff --git a/pulls/api.php b/pulls/api.php
index a23e166...1b11d50 100644
--- a/pulls/api.php
+++ b/pulls/api.php
@@ -116,6 +116,22 @@ function ghchangestate($pull, $state)
return (bool)do_http_request($pull->_links->self->href, $opts);
}
+function ghsetlabels($pull, $labels)
+{
+ if (!is_array($labels)) {
+ return true;
+ }
+
+ $opts = array(
+ 'method' => 'PUT',
+ 'content' => json_encode($labels),
+ );
+
+ $url = $pull->issue_url . "/labels";
+
+ return (bool)do_http_request($url, $opts);
+}
+
function login()
{
global $errors;
@@ -202,10 +218,12 @@ function ghupdate()
$comment = @get_magic_quotes_gpc() ? stripslashes($_POST['comment']) :
$_POST['comment'];
- if (!ghpostcomment($pull, $comment)) {
- header('500 Internal Server Error');
- $errors[] = "Failed to add comment on GitHub";
- die(json_encode(array('success' => false, 'errors' => $errors)));
+ if (!is_array($_POST['labels'])) {
+ if (!ghpostcomment($pull, $comment)) {
+ header('500 Internal Server Error');
+ $errors[] = "Failed to add comment on GitHub";
+ die(json_encode(array('success' => false, 'errors' => $errors)));
+ }
}
if (!empty($_POST['state'])) {
@@ -216,6 +234,14 @@ function ghupdate()
}
}
+ if (is_array($_POST['labels'])) {
+ if (!ghsetlabels($pull, $_POST['labels'])) {
+ header('500 Internal Server Error');
+ $errors[] = "Failed to set labels";
+ die(json_encode(array('success' => false, 'errors' => $errors)));
+ }
+ }
+
die(json_encode(array('success' => true)));
}
diff --git a/pulls/index.php b/pulls/index.php
index 4225748..6a5bef8 100644
--- a/pulls/index.php
+++ b/pulls/index.php
@@ -96,6 +96,7 @@ $ git push origin master # everything okay? good, let's push it
<button>OK</button>
</script>
<script id="updatePullRequestTemplate" type="text/x-jquery-tmpl">
+ Labels: <span></span>
State: <select id="newState">
<option>open</option>
<option>closed</option>
diff --git a/pulls/pullrequests.js b/pulls/pullrequests.js
index 7252a21..17c15a5 100644
--- a/pulls/pullrequests.js
+++ b/pulls/pullrequests.js
@@ -181,7 +181,7 @@ function loadRepo(repo, url) {
break;
}
}
- input_html += ' value="' + repo_labels.data[i].name + '"';
+ input_html += ' name="' + repo_labels.data[i].name + '"';
input_html += " />";
li_el.append(input_html + repo_labels.data[i].name);
}
@@ -197,6 +197,19 @@ function loadRepo(repo, url) {
var dia =
$('<div></div>').html($("#updatePullRequestTemplate").render({}))
.dialog({title: $(this).data("number")+':
'+$(this).data("title")+' ('+$(this).data("state")+')'
});
$("button", dia).click(function(r, n, dia) { return function(ev) {
updateRepo(r, n, dia); ev.preventDefault();}}(repo, $(this).data("number"), dia) );
+
+ var labels = $('[id^="pr-' + $(this).data("number") +
'-label"]');
+ console.log(labels);
+ if (0 == labels.length) {
+ $("span", dia).append("<span>Unchanged</span>");
+ } else {
+ labels.each(function(i, v) {
+ if (v.checked) {
+ $("span", dia).append(v.name + " ");
+ }
+ });
+ }
+ $("span", dia).append("<br />");
ev.preventDefault();
});
$("#repoPullList").accordion({ autoHeight: false });
@@ -213,13 +226,22 @@ function updateRepo(reponame, num, dia) {
login.showLoginForm();
return;
}
+
+ var labs_arg = null;
+ var labs = $('[id^="pr-' + num + '-label"]');
+ if (0 < labs.length) {
+ labs_arg = [];
+ labs.each(function(i, v){if(v.checked){labs_arg.push(v.name);}});
+ }
+
$("#loading").show();
$.ajax({ url: API_URL, type: "POST", data: {
action: 'ghupdate',
repo: reponame,
id: num,
state: $("select", dia).val(),
- comment: $("textarea", dia).val()
+ comment: $("textarea", dia).val(),
+ labels: labs_arg
}, success: function(d) {
if (d.success) {
loadRepo(reponame);