Add a central registry and hooks for custom condition choices.

Review Request #14280 — Created Jan. 1, 2025 and submitted

Information

Review Board
release-7.1.x

Reviewers

When we first wrote the support for condition choices for integrations,
we intended for the framework to be extensible, allowing extensions to
produce new condition choices that users could select from. However,
this didn't work in practice, since we lacked any kind of central
registry for condition choices that extensions could hook into.

This change introduces a new central review_request_condition_choices
registry, along with a new ReviewRequestConditionChoicesHook that
wraps it.

A central ReviewRequestConditionsField can be used whenever a
ConditionsField is meant to be used with review_request_condition_choices,
enabling custom condition choices from any extension. rbintegrations 4.1
will be updated to use this.

Documentation has been written to help extension authors make use of the
new hook. It only touches upon the basics of creating new choices, and
doesn't touch upon custom operators, but it should be enough to get
people going.

Unit tests passed.

Tested the new central registry with in-progress code in rbintegrations
and Power Pack.

Built the docs. Checked the example code against the unit tests, and
checked for bad links and other errors.

Summary ID
Add a central registry and hooks for custom condition choices.
When we first wrote the support for condition choices for integrations, we intended for the framework to be extensible, allowing extensions to produce new condition choices that users could select from. However, this didn't work in practice, since we lacked any kind of central registry for condition choices that extensions could hook into. This change introduces a new central `review_request_condition_choices` registry, along with a new `ReviewRequestConditionChoicesHook` that wraps it. With this, any extension can easily introduce one or more new condition choices, which will be picked up automatically when presenting a `ConditionsField` (when used along with the upcoming rbintegrations 4.1 release). Documentation has been written to help extension authors make use of the new hook. It only touches upon the basics of creating new choices, and doesn't touch upon custom operators, but it should be enough to get people going.
34336df74418e4338c3a8735fa4cd518dec3a4f4
Description From Last Updated

'reviewboard.extensions.base.Extension' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

Should we include type hints in this example?

daviddavid

In order to make some linters happier about the lack of docstrings, can we preface this with _?

daviddavid

Same here.

daviddavid

This needs to be alphabetized.

daviddavid

Doesn't this need a matching _integrations definition?

daviddavid

For this and the other choice_id below, I think it'd be good to prefix it like we recommend to do. …

maubinmaubin
There are no open issues
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
david
  1. 
      
  2. Show all issues

    Should we include type hints in this example?

    1. I've been leaving them out just to keep the examples simple. I figure most people who are doing development probably aren't going to be writing type hints (largely IT and such), and they should still be inheriting the types from the parent methods anyway.

  3. Show all issues

    In order to make some linters happier about the lack of docstrings, can we preface this with _?

    1. Which linters have this rule? I haven't seen this. We should standardize any linting tools we're using.

    2. I don't think this is something we should turn on globally (yet) but these trigger D100-D103 in pydocstyle/ruff

  4. Show all issues

    Same here.

  5. reviewboard/reviews/forms.py (Diff revision 2)
     
     
    Show all issues

    This needs to be alphabetized.

  6. 
      
chipx86
david
  1. 
      
  2. Show all issues

    Doesn't this need a matching _integrations definition?

  3. 
      
chipx86
david
  1. Ship It!
  2. 
      
maubin
  1. 
      
  2. Show all issues

    For this and the other choice_id below, I think it'd be good to prefix it like we recommend to do. Maybe sample-extension_my-category. That would help if someone for example copies and pastes this code to get started on their condition choice, and forgets to think about adding a prefix.

  3. 
      
chipx86
maubin
  1. Ship It!
  2. 
      
maubin
  1. Ship It!
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-7.1.x (11a4f1f)
Loading...