ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Comment-or-update-comment

Open JasonEtco opened this issue 7 years ago • 7 comments

Not really an app idea, but I think a lot of apps will want to post a comment on a PR/issue then update that comment on subsequent events (rather than posting a new comment). As an example, Codecov has this behavior; it's kind of a pain to write all of that manually, since its very boilerplate-y. It could use the APP_ID and metadata to mark a comment as belonging to the app.

JasonEtco avatar Feb 13 '18 15:02 JasonEtco

maybe probot/friction would be a better place to discuss this?

gr2m avatar Feb 13 '18 20:02 gr2m

Would love this — my initial idea (not knowing about metadata) was to append a <!-- probot comment[<id>] --> marker to the comment, then (on update) paginate comments until a comment with that marker (including id) was found

grrowl avatar Mar 14 '18 02:03 grrowl

@grrowl sounds like a good plan to me :)

gr2m avatar Mar 14 '18 23:03 gr2m

@grrowl that'd likely be the right implementation - I think the challenge is around designing a good looking API. I don't think it should be part of Probot, but would make a nice third-party lib (or even an Octokit plugin, what do you think @gr2m?)

Something like:

context.github.createOrUpdateComment({
  owner, repo, issue,
  body: '...', // First body, when comment is created
  transform: oldComment => oldComment + 'New content', // Transform the original comment if it needs to update
  marker: 'probot:APP_ID' // resolve to <!-- probot:APP_ID -->
})

JasonEtco avatar Mar 14 '18 23:03 JasonEtco

sounds like a great plan to me :) @octokit/rest plugins API is still work-in-progress but they already work. See https://github.com/octokit/rest.js/tree/master/lib/plugins for some info and reference plugin implementation. You could create a repository/npm package for the plugin and then load it like this

octokit.plugin(require('octokit-plugin-create-or-update-comment'))

I’m not yet sure how you’d load the plugin in Probot though? @JasonEtco is robot.github set so it could be done in the Probot app’s entry point function?

GitHub
rest.js - GitHub REST API client for Node.js

gr2m avatar Mar 14 '18 23:03 gr2m

I’m not yet sure how you’d load the plugin in Probot though? @JasonEtco is robot.github set so it could be done in the Probot app’s entry point function?

That's a good point. We'd need to load the plugin in the handler itself I guess? We don't currently expose the GitHub client until its created in robot.auth (as part of robot.on). An interesting conversation though, as Octokit plugins become more mature we'll definitely want to help folks out in that area.

JasonEtco avatar Mar 14 '18 23:03 JasonEtco

Either way I think @grrowl you can start creating the plugin, we will figure out how to get it into probot later :)

gr2m avatar Mar 14 '18 23:03 gr2m