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
adding support for GitHub v3 delete comment #2540
adding support for GitHub v3 delete comment #2540
Conversation
implicit context: Context, | ||
s: Session | ||
): Option[(Issue, Int)] = context.loginAccount.flatMap { _ => | ||
val deleteResult = deleteComment(comment.issueId, comment.commentId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find any docs for deleteComment
here. It returns an Int
- am I safe to assume that the returned value is the number of records that were deleted in the DB?
If that's the case, then I think making sure it is equal to a non-zero number (or in this case, 1) would be a good idea. Otherwise I don't think there's any need for this deleteCommentByApi
function to return Option[(Issue, Int)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find any docs for deleteComment here. It returns an Int - am I safe to assume that the returned value is the number of records that were deleted in the DB?
I'm not familiar with these codes, but it seems to return from here eventually.
either (1) the row count for SQL Data Manipulation Language (DML) statements
or (2) 0 for SQL statements that return nothing
If that's the case, then I think making sure it is equal to a non-zero number (or in this case, 1) would be a good idea. Otherwise I don't think there's any need for this deleteCommentByApi function to return Option[(Issue, Int)]
What will happen if there is no issue to delete on GitHub?
(for { | ||
commentId <- params("id").toIntOpt | ||
comment <- getComment(repository.owner, repository.name, commentId.toString) | ||
issue <- getIssue(repository.owner, repository.name, comment.issueId.toString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of doing a permissions check here using isEditable
, is that a valid approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, checking whether the user is allowed to update the comment is necessary as same as the comment update API (#2538).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation allows to delete a comment whatever its action is.
e.g. You can delete an add_label
comment or a change_milestone
comment.
You can't delete those comments via Web UI in GitBucket. Does GitHub allow that?
*/ | ||
delete("/api/v3/repos/{owner}/{repo}/issues/comments/:id")(readableUsersOnly { repository => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete("/api/v3/repos/{owner}/{repo}/issues/comments/:id")(readableUsersOnly { repository => | |
delete("/api/v3/repos/:owner/:repository/issues/comments/:id")(readableUsersOnly { repository => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, how did you verify that this api work?
implicit context: Context, | ||
s: Session | ||
): Option[(Issue, Int)] = context.loginAccount.flatMap { _ => | ||
val deleteResult = deleteComment(comment.issueId, comment.commentId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find any docs for deleteComment here. It returns an Int - am I safe to assume that the returned value is the number of records that were deleted in the DB?
I'm not familiar with these codes, but it seems to return from here eventually.
either (1) the row count for SQL Data Manipulation Language (DML) statements
or (2) 0 for SQL statements that return nothing
If that's the case, then I think making sure it is equal to a non-zero number (or in this case, 1) would be a good idea. Otherwise I don't think there's any need for this deleteCommentByApi function to return Option[(Issue, Int)]
What will happen if there is no issue to delete on GitHub?
Closes #2539 |
Perhaps, GitHub doesn't treat these events as comments? Anyway, we must not allow to delete these event comments in GitBucket even via Web API. |
comment <- getComment(repository.owner, repository.name, commentId.toString) | ||
issue <- getIssue(repository.owner, repository.name, comment.issueId.toString) | ||
} yield { | ||
if (isEditable(repository.owner, repository.name, comment.commentedUserName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@jyoo980 Sorry, other pull requests which I merged before this conflicted with this pull request. Could you resolve the conflicts? |
@takezoe sure, I can take a look this weekend after my classes |
Thanks! |
@jyoo980 Could you also add this endpoint to the wiki page? |
@takezoe I've added the endpoint to the wiki page. I think we can close this. |
Before submitting a pull-request to GitBucket I have first: