octokit.net
octokit.net copied to clipboard
How to delete a reaction from an issue?
I have been trying to create and delete reactions on an issue. Creating works great, but I'm having issues deleting the issue. It throws an exception with "Not found". I'm guessing it does not find the reaction_id I'm providing.
var user = client.User.Current().Result;
var reactions = client.Reaction.Issue.GetAll("myorg", "myrepo", args.RowData.Number).Result;
if (reactions.Any(i => i.User.Login == user.Login))
{
var reaction = reactions.First(i => i.User.Login == user.Login);
client.Reaction.Delete(reaction.Id).Wait();
}
else
{
client.Reaction.Issue.Create("myorg", "myrepo", args.RowData.Number, new NewReaction(ReactionType.Heart)).Wait();
}
What confuses me is that it seems that the API needs the issue Id
DELETE /repos/{owner}/{repo}/issues/{issue_number}/reactions/{reaction_id} https://docs.github.com/en/rest/reference/reactions#delete-an-issue-reaction
But the if I understand the actual code correctly, this is operating without the issue
/// <summary>
/// Delete a reaction.
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#delete-a-reaction</remarks>
/// <param name="number">The reaction id</param>
/// <returns></returns>
[Preview("squirrel-girl")]
[ManualRoute("DELETE", "/reactions/{reaction_id}")]
public Task Delete(int number)
{
return ApiConnection.Delete(ApiUrls.Reactions(number), new object(), AcceptHeaders.ReactionsPreview);
}
/// <summary>
/// Returns the <see cref="Uri"/> for deleting a reaction.
/// </summary>
/// <param name="number">The reaction number</param>
/// <returns>The <see cref="Uri"/> that lists the watched repositories for the authenticated user.</returns>
public static Uri Reactions(int number)
{
return "reactions/{0}".FormatUri(number);
}
How can I delete the reaction?
Hi @tschissler. I've not been here long enough to comment precisely, but I believe that either this is how it used to work, or this was an attempt to standardise deletions for the Observable side.
Code wise, I would say that the below clients need updating to include delete routes, as they are all slightly different:
- ICommitCommentReactionsClient
- IIssueReactionsClient
- IIssueCommentReactionsClient
- IPullRequestReviewCommentReactionsClient
@nickfloyd would you agree?
In fact I just stumbled across this, confirming that this was the old way of doing things. https://github.blog/changelog/2022-02-11-legacy-delete-reactions-rest-api-removed/
@JonruAlveus Agreed! I think you're right on this and sadly the SDK doesn't support the current way of deleting reactions. What do you think of creating a follow-up issue to fix this?
@timrogers will do.
See #2490
Thank you for adding the issue for this @JonruAlveus! ❤️
@tschissler The fix should now be available, please could you let us know if it’s working for you? 😄
@JonruAlveus, thanks for implementing this. I will look into this in the next couple of days.
Thank you @JonruAlveus I just tested it and it works now as expected. Great work!.
I have created a LinqPad sample and can create a PR for this if you think this is helpful.
async Task Main(string[] args)
{
var userName = "tschissler";
var org = "tschissler";
var repo = "TestIntegration";
GitHubClient client = new GitHubClient(new Octokit.ProductHeaderValue("Octokit.Samples"));
client.Credentials = new Credentials(Util.GetPassword("github"));
IIssuesClient issuesclient = client.Issue;
var allissues = await issuesclient.GetAllForRepository(org, repo);
allissues.Select(a => new { a.Number, a.Title, a.Body, a.Reactions}).Dump();
client.Reaction.Issue.Create(org, repo, allissues[0].Number, new NewReaction(ReactionType.Heart)).Wait();
allissues = await issuesclient.GetAllForRepository(org, repo);
allissues.Select(a => new { a.Number, a.Title, a.Body, a.Reactions}).Dump();
var reactions = client.Reaction.Issue.GetAll(org, repo, allissues[0].Number).Result;
var reaction = reactions.Last(i => i.User.Login == userName);
await client.Reaction.Issue.Delete(org, repo, allissues[0].Number,reaction.Id);
allissues = await issuesclient.GetAllForRepository(org, repo);
allissues.Select(a => new { a.Number, a.Title, a.Body, a.Reactions}).Dump();
}
Hi @tschissler, glad it working for you! We’re always happy to receive a PR for improvements, especially to the documentation side if you have time!