github: add ability to edit commit message from PR in Lando UI (bug 2003888)#1161
github: add ability to edit commit message from PR in Lando UI (bug 2003888)#1161Magnolia-Liu wants to merge 1 commit into
Conversation
|
View this pull request in Lando to land it once approved. |
zzzeid
left a comment
There was a problem hiding this comment.
Just a few drive-by comments
shtrom
left a comment
There was a problem hiding this comment.
Mostly stylistic comments, but this is looking good, and the overall logic makes sense.
| <td>{{ pull_request.title }}</td> | ||
| <td> | ||
| <textarea readonly id="commit-title" class="textarea">{{ pull_request.title }}</textarea> | ||
| <p class="help is-danger" id="commit-title-error"></p> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <th>Commit Body</th> | ||
| <td>{{ pull_request.body }}</td> | ||
| <td> | ||
| <textarea readonly id="commit-body" class="textarea">{{ pull_request.body }}</textarea> | ||
| <p class="help is-danger" id="commit-body-error"></p> | ||
| </td> | ||
| </tr> | ||
| </table> | ||
| <p> |
There was a problem hiding this comment.
It may make sense to have title, body and button as a div-like form in a single table row.
| <button id="post-landing-job" | ||
| class="button is-large is-loading post-landing-job has-text-white" |
There was a problem hiding this comment.
Having an id and a class named the same could be a bit of a footgun for our future selves.
Having an id is good, though. Perhaps we should just make sure that everything rely on it being an id, and remove the class altogether.
This would however force any page to only have a single landing button. I don't think we have it any differently at the moment, but maybe it's not something we want to commit to right here?
If anything, I'd look for ways to avoid needing to make this particular change, if possible.
There was a problem hiding this comment.
It may be a good time to reduce clutter here. If .post-landing-job is used elsewhere we could change it to #post-landing-job.
Having said that, not sure if having them have the same name is an issue. I suspect you added this to be able to easily use document.getElementById?.
There was a problem hiding this comment.
Having the same name is probably not a technical issue, but from a human differentiation perspective, it's probably best if they are different.
There was a problem hiding this comment.
If .post-landing-job is used elsewhere we could change it to #post-landing-job.
@zzzeid I think you meant “if it ISN'T used elsewhere”? (otherwise the ids will collide).
| json={"body": comment}, | ||
| ) | ||
|
|
||
| def update_pull_request_content( |
There was a problem hiding this comment.
| def update_pull_request_content( | |
| def update_pull_request_description( |
It may also make sense to make the title optional, so we can use it to only change the body.
There was a problem hiding this comment.
I think this method is more generic than just updating the description. It can be used to update any attribute on the PR.
| }); | ||
| }); | ||
|
|
||
| $("button.save-pr").on("click", function (e) { |
There was a problem hiding this comment.
I noticed in the UI demo that there is no feedback on the save button when it is clicked (unless I missed it?) This would be good for usability (e.g., disable the button temporarily, or change the text, etc...
| .getElementById("cancel-edit-pr") | ||
| .classList.add("is-hidden"); | ||
|
|
||
| window.location.reload(); |
There was a problem hiding this comment.
It would be good to file a bug under https://bugzilla.mozilla.org/show_bug.cgi?id=2000954 to update this to instead re-trigger the checks without a full refresh.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| document.getElementById("commit-title").setAttribute("readonly", true); | ||
| document.getElementById("commit-body").setAttribute("readonly", true); | ||
| document.getElementById("commit-title-error").textContent = ""; | ||
| document.getElementById("commit-body-error").textContent = ""; | ||
| document.getElementById("commit-title").classList.remove("is-danger"); | ||
| document.getElementById("commit-body").classList.remove("is-danger"); | ||
| document.getElementById("commit-title").value = | ||
| document.getElementById("commit-title").defaultValue; | ||
| document.getElementById("commit-body").value = | ||
| document.getElementById("commit-body").defaultValue; | ||
| document.getElementById("save-pr").dataset.mode = "edit"; | ||
| document.getElementById("save-pr").textContent = "Edit Commit Message"; | ||
| document.getElementById("cancel-edit-pr").classList.add("is-hidden"); | ||
| document.getElementById("post-landing-job").disabled = false; |
There was a problem hiding this comment.
nit: you can save the elements in variables and re-use them, instead of doing document.getElementById multiple times for each element.
| <button id="post-landing-job" | ||
| class="button is-large is-loading post-landing-job has-text-white" |
There was a problem hiding this comment.
It may be a good time to reduce clutter here. If .post-landing-job is used elsewhere we could change it to #post-landing-job.
Having said that, not sure if having them have the same name is an issue. I suspect you added this to be able to easily use document.getElementById?.
| <textarea readonly id="commit-title" class="textarea">{{ pull_request.title }}</textarea> | ||
| <p class="help is-danger" id="commit-title-error"></p> |
There was a problem hiding this comment.
This is a bit out of scope for this PR, I filed a bug to remove the use of a table here altogether.
| json={"body": comment}, | ||
| ) | ||
|
|
||
| def update_pull_request_content( |
There was a problem hiding this comment.
I think this method is more generic than just updating the description. It can be used to update any attribute on the PR.
There was a problem hiding this comment.
This is probably erroneously showing up here because of the merge. I would recommend squashing this entire PR at some point, before attempting to merge it, to clean up the commit history.
| if not self.target_repo.user_can_push(request.user): | ||
| return JsonResponse( | ||
| {"errors": ["You are not allowed to push to this repository."]}, | ||
| status=403, | ||
| ) |
There was a problem hiding this comment.
I wonder if we should make a little assertion util that would return a consistent error everywhere it's called.
There was a problem hiding this comment.
I already have this functionality partially implemented in #1160.
| <textarea readonly id="commit-title" class="textarea">{{ pull_request.title }}</textarea> | ||
| <p class="help is-danger" id="commit-title-error"></p> | ||
| <p id="commit-title">{{ pull_request.title }}</p> | ||
| <p id="commit-title-error" class="help is-danger"></p> |
There was a problem hiding this comment.
I wouldn't set the is-danger class on those, even if empty. It can be set as needed by the JS.
| $("#save-edit-pr").on("click", function (e) { | ||
| var save_edit_pr_button = $(this); | ||
|
|
||
| if (save_edit_pr_button.attr("data-mode") === "saved") { |
There was a problem hiding this comment.
Could we swap the logic of this method, so we do the case for saved by default, and the fetch only when we are sure we have data-mode===edit?
It may be worth splitting those two into separate methods, e.g.,
if (save_edit_pr_button.attr("data-mode") === "edit") {
return save_pr_description();
}
return edit_pr_description();| .getElementById("cancel-edit-pr") | ||
| .classList.add("is-hidden"); | ||
|
|
||
| window.location.reload(); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| const pTitle = document.createElement("p"); | ||
| const pBody = document.createElement("p"); | ||
| const textareaTitle = $("#commit-title")[0]; | ||
| const textareaBody = $("#commit-body")[0]; |
There was a problem hiding this comment.
Why do we use array indexing here? This seems odd, and we don't do it before in tho code, e.g., https://github.com/mozilla-conduit/lando/pull/1161/changes/8726f39b11c08695895b0a506e34cad6c652edd4..e6cbe4c36dfa3a2b52f622538df1f06eaa3bbc86#diff-4d791453e88ede62fd62f9e15ecccd2a546f9d0e6fe016091adb198d09a6ca67R272.
If it's not needed (which I'm not sure, tbh), then we should probably be consistent and use the same access type throughout the code.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| $("#commit-title-error").text(""); | ||
| $("#commit-body-error").text(""); | ||
| $("#commit-title").removeClass("is-danger"); | ||
| $("#commit-body").removeClass("is-danger"); | ||
| $("#commit-title").prop("disabled", true); | ||
| $("#commit-body").prop("disabled", true); | ||
| $("#cancel-edit-pr").addClass("is-hidden"); |
There was a problem hiding this comment.
Perhaps we should have utility functions to set/reset the errors, e.g., something like
function set_error_for(selector, error_text, error_class) {
$(selector + "-error").text(error_text);
$(selector).removeClass("is-hidden");
$(selector).removeClass("is-danger");
$(selector).addClass(error_class);
$(selector).prop("disabled", error_text === "");
}
zzzeid
left a comment
There was a problem hiding this comment.
Looking good, just a couple of questions/comments. Is it possible to see a new video with the latest UI implementation?
| if not self.target_repo.user_can_push(request.user): | ||
| return JsonResponse( | ||
| {"errors": ["You are not allowed to push to this repository."]}, | ||
| status=403, | ||
| ) |
There was a problem hiding this comment.
I already have this functionality partially implemented in #1160.
zzzeid
left a comment
There was a problem hiding this comment.
Looking good! Just a couple of small changes and I think this will be ready to go.
shtrom
left a comment
There was a problem hiding this comment.
A few nits, and one remaining thing regarding the handling of the status from the fetch to the API (return early on 200, and handle all 4xx).
This looks pretty good overall, though. Nice job!
|
|
||
| @pytest.fixture | ||
| def repo_github_api_client(repo_mc): | ||
| repo_mc(SCMType.GIT, name="git-repo") |
There was a problem hiding this comment.
nit: it may be safer to name the repo after the fixture it comes from, to avoid risks of collisions
124e4bb to
5d3e39f
Compare
5d3e39f to
2781bcf
Compare
2781bcf to
bce8475
Compare
bce8475 to
ee345d8
Compare
a4fd00b to
8af7584
Compare
Demo of UI:
Screen.Recording.2026-06-01.at.5.21.42.PM.mov