This document describes the implementation for handling scenarios when OPENCOLLECTIVE_HANDLE is set to a falsey value.
Created the following template files that exclude Open Collective references:
.github/FUNDING.yml.no-osc.example- FUNDING.yml without theopen_collectivelineREADME.md.no-osc.example- Already existed (created by user)FUNDING.md.no-osc.example- Already existed (created by user)
Added three new helper methods:
Returns true when OPENCOLLECTIVE_HANDLE or FUNDING_ORG environment variables are explicitly set to falsey values (false, no, or 0).
def opencollective_disabled?
oc_handle = ENV["OPENCOLLECTIVE_HANDLE"]
funding_org = ENV["FUNDING_ORG"]
# Check if either variable is explicitly set to false
[oc_handle, funding_org].any? do |val|
val && val.to_s.strip.match(Kettle::Dev::ENV_FALSE_RE)
end
endNote: This method is used centrally by both TemplateHelpers and GemSpecReader to ensure consistent behavior across the codebase.
Extends the existing prefer_example method to check for .no-osc.example variants when Open Collective is disabled.
- When
opencollective_disabled?returnstrue, it first looks for a.no-osc.examplevariant - Falls back to the standard
prefer_examplebehavior if no.no-osc.examplefile exists
Determines if a file should be skipped during the template process when Open Collective is disabled.
Returns true for these files when opencollective_disabled? is true:
.opencollective.yml.github/workflows/opencollective.yml
Updated the template task to use the new helpers:
-
In the
.githubfiles section:- Replaced
helpers.prefer_example(orig_src)withhelpers.prefer_example_with_osc_check(orig_src) - Added check to skip opencollective-specific workflow files
- Replaced
-
In the root files section:
- Replaced
helpers.prefer_example(...)withhelpers.prefer_example_with_osc_check(...) - Added check at the start of
files_to_copy.eachloop to skip opencollective files
- Replaced
Updated the funding_org detection logic to use the centralized TemplateHelpers.opencollective_disabled? method:
- Removed the inline check for
ENV["FUNDING_ORG"] == "false" - Replaced with a call to
TemplateHelpers.opencollective_disabled?at the beginning of the funding_org detection block - This ensures consistent behavior: when Open Collective is disabled via any supported method (
OPENCOLLECTIVE_HANDLE=false,FUNDING_ORG=false, etc.), thefunding_orgwill be set tonil
Precedence for funding_org detection:
- If
TemplateHelpers.opencollective_disabled?returnstrue→funding_org = nil - Otherwise, if
ENV["FUNDING_ORG"]is set and non-empty → use that value - Otherwise, attempt to read from
.opencollective.ymlviaOpenCollectiveConfig.handle - If all above fail →
funding_org = nilwith a warning
Set one of these environment variables to a falsey value:
# Option 1: Using OPENCOLLECTIVE_HANDLE
OPENCOLLECTIVE_HANDLE=false bundle exec rake kettle:dev:template
# Option 2: Using FUNDING_ORG
FUNDING_ORG=false bundle exec rake kettle:dev:template
# Other accepted falsey values: no, 0 (case-insensitive)
OPENCOLLECTIVE_HANDLE=no bundle exec rake kettle:dev:template
OPENCOLLECTIVE_HANDLE=0 bundle exec rake kettle:dev:templateWhen Open Collective is disabled, the template process will:
-
Skip copying
.opencollective.yml -
Skip copying
.github/workflows/opencollective.yml -
Use
.no-osc.examplevariants for:README.md→ UsesREADME.md.no-osc.exampleFUNDING.md→ UsesFUNDING.md.no-osc.example.github/FUNDING.yml→ Uses.github/FUNDING.yml.no-osc.example
-
Display skip messages like:
Skipping .opencollective.yml (Open Collective disabled) Skipping .github/workflows/opencollective.yml (Open Collective disabled)
For any file being templated, the system now follows this precedence:
-
If
opencollective_disabled?istrue:- First, check for
filename.no-osc.example - If not found, fall through to normal logic
- First, check for
-
Normal logic (when OC not disabled or no
.no-osc.exampleexists):- Check for
filename.example - Fall back to
filename
- Check for
To test the implementation:
-
Test with Open Collective enabled (default behavior):
bundle exec rake kettle:dev:templateShould use regular
.examplefiles and copy all opencollective files. -
Test with Open Collective disabled:
OPENCOLLECTIVE_HANDLE=false bundle exec rake kettle:dev:templateShould skip opencollective files and use
.no-osc.examplevariants. -
Verify file content:
- Check that
.github/FUNDING.ymlhas noopen_collective:line when disabled - Check that
README.mdhas no opencollective badges/links when disabled - Check that
FUNDING.mdhas no opencollective references when disabled
- Check that
A comprehensive test suite has been added in spec/kettle/dev/opencollective_disable_spec.rb that covers:
-
opencollective_disabled?method:- Tests all falsey values:
false,False,FALSE,no,NO,0 - Tests both
OPENCOLLECTIVE_HANDLEandFUNDING_ORGenvironment variables - Tests behavior when variables are unset, empty, or set to valid org names
- Verifies that either variable being falsey triggers the disabled state
- Tests all falsey values:
-
skip_for_disabled_opencollective?method:- Verifies that
.opencollective.ymlis skipped when disabled - Verifies that
.github/workflows/opencollective.ymlis skipped when disabled - Ensures other files (README.md, FUNDING.md, etc.) are not skipped
- Tests behavior when Open Collective is enabled
- Verifies that
-
prefer_example_with_osc_checkmethod:- Tests preference for
.no-osc.examplefiles when OC is disabled - Tests fallback to
.examplewhen.no-osc.exampledoesn't exist - Tests fallback to original file when neither variant exists
- Handles paths that already end with
.example - Tests normal behavior (prefers
.example) when OC is enabled
- Tests preference for
-
funding_orgdetection with OPENCOLLECTIVE_HANDLE=false:- Verifies
funding_orgis set tonilwhen disabled - Tests all falsey values:
false,no,0 - Tests both
OPENCOLLECTIVE_HANDLEandFUNDING_ORGvariables - Ensures
.opencollective.ymlis ignored when OC is disabled
- Verifies
-
funding_orgdetection with OPENCOLLECTIVE_HANDLE enabled:- Tests using
OPENCOLLECTIVE_HANDLEvalue when set - Tests using
FUNDING_ORGvalue when set - Tests reading from
.opencollective.ymlwhen env vars are unset
- Tests using
Run the Open Collective disable tests:
bundle exec rspec spec/kettle/dev/opencollective_disable_spec.rbRun all tests:
bundle exec rspecRun with documentation format for detailed output:
bundle exec rspec spec/kettle/dev/opencollective_disable_spec.rb --format documentation