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

Avoid deleting a comment that was just created before and prevent creating empty comments #5

Merged
merged 1 commit into from
Jun 30, 2023

Conversation

thyandrecardoso
Copy link
Contributor

Hi!

This PR tentatively changes the behavior of delete so that we only delete the comments that were there previously and then stop, instead of creating a comment and deleting it. Also, it avoids creating a comment with an empty body.

I was looking into using this action and noticed that, if delete = true the action tries to delete all comments found including the one that might have been created just before:

if (newCommentId) {
await octokit.issues.deleteComment({
owner,
repo,
comment_id: newCommentId,
});
}

Shouldn't we be ignoring the new comment here, or is there a use case for creating and immediately deleting the comment?

Related to this is also the behavior of an empty body. According to the readme: When has 1 comment, and no body input will delete this filter comment. From this and from what I sense is the overall intent of this action, I would assume that an empty body would never trigger a comment, but:

if (comments.length === 0) {
const commentBody = `${body}\n${bodyInclude}`;
const { data } = await octokit.issues.createComment({
owner,
repo,
issue_number: number,
body: commentBody,
});

In my specific case, what I am looking for is something that always comments on the same "comment" according to a given input. And, when that input is empty, I want the comment to disappear.

I can achieve that behavior with this action by, for example, conditionally setting delete according to the length of the body. However, that creates a flow of create a comment with an empty body -> delete previously created comment. One annoying thing about this is that GitHub may send you a notification about a new comment which, when you click on the notification, does not exist.

Do these changes make sense?

@xrkffgg xrkffgg merged commit edf9dcb into actions-cool:main Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants