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

adding support for GitHub v3 delete comment #2540

Merged
merged 3 commits into from Sep 12, 2020

Conversation

jyoo980
Copy link
Contributor

@jyoo980 jyoo980 commented Aug 31, 2020

Before submitting a pull-request to GitBucket I have first:

  • read the contribution guidelines
  • rebased my branch over master
  • verified that project is compiling
  • verified that tests are passing
  • squashed my commits as appropriate (keep several commits if it is relevant to understand the PR)
  • marked as closed using commit message all issue ID that this PR should correct

implicit context: Context,
s: Session
): Option[(Issue, Int)] = context.loginAccount.flatMap { _ =>
val deleteResult = deleteComment(comment.issueId, comment.commentId)
Copy link
Contributor Author

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)]

Copy link
Member

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

image

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?

Comment on lines 79 to 82
(for {
commentId <- params("id").toIntOpt
comment <- getComment(repository.owner, repository.name, commentId.toString)
issue <- getIssue(repository.owner, repository.name, comment.issueId.toString)
Copy link
Contributor Author

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?

Copy link
Member

@takezoe takezoe Sep 5, 2020

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).

@onukura onukura added the APIv3 GitHub compatible API label Sep 1, 2020
Copy link
Member

@SIkebe SIkebe left a 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 =>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
delete("/api/v3/repos/{owner}/{repo}/issues/comments/:id")(readableUsersOnly { repository =>
delete("/api/v3/repos/:owner/:repository/issues/comments/:id")(readableUsersOnly { repository =>

Copy link
Member

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)
Copy link
Member

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

image

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?

@SIkebe
Copy link
Member

SIkebe commented Sep 3, 2020

Closes #2539

@takezoe
Copy link
Member

takezoe commented Sep 5, 2020

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?

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.

@takezoe takezoe added this to the 4.35.0 milestone Sep 5, 2020
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)) {
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

@takezoe takezoe left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@takezoe
Copy link
Member

takezoe commented Sep 10, 2020

@jyoo980 Sorry, other pull requests which I merged before this conflicted with this pull request. Could you resolve the conflicts?

@jyoo980
Copy link
Contributor Author

jyoo980 commented Sep 10, 2020

@takezoe sure, I can take a look this weekend after my classes

@takezoe
Copy link
Member

takezoe commented Sep 12, 2020

Thanks!

@takezoe takezoe merged commit 0d20bc0 into gitbucket:master Sep 12, 2020
@takezoe
Copy link
Member

takezoe commented Sep 12, 2020

@jyoo980 Could you also add this endpoint to the wiki page?
https://github.com/gitbucket/gitbucket/wiki/API-WebHook

@jyoo980 jyoo980 deleted the jy/add-delete-comment-support branch September 12, 2020 06:05
@jyoo980
Copy link
Contributor Author

jyoo980 commented Sep 12, 2020

@takezoe I've added the endpoint to the wiki page. I think we can close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APIv3 GitHub compatible API
Development

Successfully merging this pull request may close these issues.

None yet

4 participants