Skip to content

fix regression in extension API to allow dynamic context key access

Warren Gifford requested to merge fix-codecov-ext-buttons into main

Created by: sqs

fix #14283 (closed)

The Codecov extension checks the context (which is just a big key-value map) for a key like codecov.coverageRatio.git://github.com/sourcegraph/sourcegraph?d947204f7b216004d94c9b504952a986e3685e46#cmd/frontend/registry/extensions.go to determine whether there is coverage data for a file, which in turn determines whether the Coverage: N% button is shown. The key--that big long key in the previous sentence--is dynamic, based on the current repository, commit SHA, and file. The full condition for showing the button is (from sourcegraph-codecov's package.json):

resource && !config.codecov.hideCoverageButton && get(context, codecov.coverageRatio.${resource.uri})

That means: show the button if all of the following are true:

  • there is a file being shown (resource)
  • the user hasn't decided to always hide the button (!config.codecov.hideCoverageButton, which is the negation of the codecov.hideCoverageButton user setting)
  • if there is a context key of the form codecov.coverageRatio.${resource.uri}, which is that big long key given above

In https://github.com/sourcegraph/sourcegraph/pull/14088 I simplified how the context was computed. But I broke support for get(context, some-dynamically-${interpolated}-string); I accidentally removed the ability to reference context and index into the whole map, and there was no test case for that.

The fix here is to treat context as a special global, like true and false. An alternative fix would be to make the context map itself contain a key named context that was self-referential, but that leads to a cyclic data structure, which sounds like a bad idea.

Merge request reports

Loading