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

Fix issue comment unfurl #929

Merged
merged 2 commits into from
Aug 30, 2019
Merged

Fix issue comment unfurl #929

merged 2 commits into from
Aug 30, 2019

Conversation

dennissivia
Copy link
Contributor

@dennissivia dennissivia commented Aug 30, 2019

Closes #928

Problem

This commit fixes unfurling of private and public issue comments.
When the octokit/rest.js changed their routing arguments from id to <resource>_id, unfurling issue comments stopped working.

Solution

This PR adjusts the argument name and thus fixes the problem.

Example (from linked issue)

URL: https://github.com/rust-lang/rust/issues/63997#issuecomment-526118914
Error:

8:56:48.513Z ERROR http: Empty value for parameter 'comment_id': undefined (id=86b1ba8d-141f-40e9-9eef-ebc87e5f0be3)
  HttpError: Empty value for parameter 'comment_id': undefined
      at values.forEach (/Users/.../slack/node_modules/@octokit/rest/plugins/validate/validate.js:66:15)
      at Array.forEach (<anonymous>)
      at Object.keys.forEach.parameterName (/Users/.../slack/node_modules/@octokit/rest/plugins/validate/validate.js:38:12)
      at Array.forEach (<anonymous>)
      at validate (/Users/...s/slack/node_modules/@octokit/rest/plugins/validate/validate.js:15:23)
      at process._tickCallback (internal/process/next_tick.js:68:7)

Offending code:
We are passing id: id (shorthand version) instead of comment_id: id.

const comment = (await github.issues.getComment({
owner,
repo,
id,
headers: { accept: 'application/vnd.github.html+json' },
})).data;

Additional fixtures

In addition, I added new fixtures to allow tests that have less context.
This should make it clear, that for public unfurls, the user of the repo
and the comment does not matter and it decouples the fixture and
subscription setup.
This was mainly helpful to me to make sure the tests only require, what they should require.

ℹ️ These fixtures are very similar to the existing ones and can be ignored during the review if that helps.

Closes #928

This commmit fixes unfurling of private and public issue comments.
When the `octokit/rest.js` changed [their rounting
arguments](octokit/rest.js@c62b2bc)
from `id` to `<resource>_id`, unfurling issue comments stopped working.

This PR adjusts the argument name and thus fixes the problem.

In addition I added new fixtures to allow tests that have less context.
This should make it clear, that for public unfurls, the user of the repo
and the comment does not matter and it decouples the fixture and
subscription setup.
This was mainly helpful to myself to make sure the tests only require,
what they should require.
@dennissivia dennissivia added type:bug A user-facing issue topic:unfurl Unfurl related issue labels Aug 30, 2019
@dennissivia dennissivia requested a review from a team August 30, 2019 10:53
@codecov
Copy link

codecov bot commented Aug 30, 2019

Codecov Report

Merging #929 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #929      +/-   ##
==========================================
+ Coverage   97.04%   97.04%   +<.01%     
==========================================
  Files         157      157              
  Lines        2639     2640       +1     
  Branches      361      361              
==========================================
+ Hits         2561     2562       +1     
  Misses         74       74              
  Partials        4        4

1 similar comment
@codecov
Copy link

codecov bot commented Aug 30, 2019

Codecov Report

Merging #929 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #929      +/-   ##
==========================================
+ Coverage   97.04%   97.04%   +<.01%     
==========================================
  Files         157      157              
  Lines        2639     2640       +1     
  Branches      361      361              
==========================================
+ Hits         2561     2562       +1     
  Misses         74       74              
  Partials        4        4

Copy link
Contributor

@wilhelmklopp wilhelmklopp left a comment

Choose a reason for hiding this comment

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

Great work ✨

I wonder how we can spot something like this earlier when we next upgrade Probot or Octokit. Should Octokit have thrown errors/warnings when passing old arguments that no longer work? cc @gr2m

lib/unfurls/index.js Outdated Show resolved Hide resolved
Instead of logging with `warn`, I decided to make sure we are not
creating lots of noise at our log provider and instead use `debug` which
is excluded by default. We can adjust the level via ENV vars to analyse
the data in a short time window.
Copy link
Contributor Author

@dennissivia dennissivia left a comment

Choose a reason for hiding this comment

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

@wilhelmklopp thanks for your review ❤️ 🙏

I wonder how we can spot something like this earlier when we next upgrade Probot or Octokit. Should Octokit have thrown errors/warnings when passing old arguments that no longer work?

Better error detection

I am not sure how to prevent this except than by adding a regression test as I did.
I made sure the unfurl test causes the exact same error we are seeing in production before fixing it.
Other than that, I have no idea.
We might also need to improve our logging/alerting because this error was visible in production and we did not notice it for quite some time. I will create and issue for that.

Better update management

With regards to the Update itself. The linked commit is part of this major version bump to 8.0. The big problem here is, that we might have just jumped over all the versions that had deprecation warnings if there were any.
I am also unsure about how to avoid this issue in the future. I hope @gr2m has an idea.

@dennissivia dennissivia merged commit fab198c into master Aug 30, 2019
@dennissivia dennissivia deleted the fix-comment-unfurls branch August 30, 2019 12:39
@gr2m
Copy link
Contributor

gr2m commented Aug 30, 2019

I wonder how we can spot something like this earlier when we next upgrade Probot or Octokit. Should Octokit have thrown errors/warnings when passing old arguments that no longer work? cc @gr2m

Ocotkit is logging warnings. The commit you linked shows that the previous URL parameter :id was deprecated and was aliased to e.g. :thread_id, you should have seen a deprecation warnings in your logs if you still used id instead of thread_id.

For breaking versions I usually try to only remove previously deprecated changes. So make sure to update to the latest version of the previous major version, run your tests, address all deprecations, then upgrading should be simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:unfurl Unfurl related issue type:bug A user-facing issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unfurl issue comments
4 participants