-
Notifications
You must be signed in to change notification settings - Fork 0
fix: migrate project settings to SonarCloud correctly (#95) #143
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
Merged
joshua-quek-sonarsource
merged 1 commit into
main
from
fix/project-settings-migration-issue-95
May 6, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import test from 'ava'; | ||
| import sinon from 'sinon'; | ||
| import { buildSettingsParams, dispatchSettingToApi } from '../../src/shared/utils/settings-params.js'; | ||
|
|
||
| test.afterEach(() => sinon.restore()); | ||
|
|
||
| // ============================================================================ | ||
| // buildSettingsParams | ||
| // ============================================================================ | ||
|
|
||
| test('buildSettingsParams builds scalar value params', t => { | ||
| const params = buildSettingsParams({ key: 'sonar.cpd.enabled', component: 'proj', value: 'true' }); | ||
| t.is(params.get('key'), 'sonar.cpd.enabled'); | ||
| t.is(params.get('component'), 'proj'); | ||
| t.is(params.get('value'), 'true'); | ||
| t.deepEqual(params.getAll('values'), []); | ||
| t.deepEqual(params.getAll('fieldValues'), []); | ||
| }); | ||
|
|
||
| test('buildSettingsParams builds multi-value params with repeated values', t => { | ||
| const params = buildSettingsParams({ key: 'sonar.exclusions', component: 'proj', values: ['**/*.test.js', '**/*.spec.js'] }); | ||
| t.is(params.get('key'), 'sonar.exclusions'); | ||
| t.is(params.get('component'), 'proj'); | ||
| t.is(params.get('value'), null); | ||
| t.deepEqual(params.getAll('values'), ['**/*.test.js', '**/*.spec.js']); | ||
| }); | ||
|
|
||
| test('buildSettingsParams builds fieldValues params as JSON', t => { | ||
| const fvs = [{ resourceKey: '**/*.js', ruleKey: 'squid:S001' }]; | ||
| const params = buildSettingsParams({ key: 'sonar.issue.enforce.multicriteria', component: 'proj', fieldValues: fvs }); | ||
| t.is(params.get('key'), 'sonar.issue.enforce.multicriteria'); | ||
| const parsed = JSON.parse(params.getAll('fieldValues')[0]); | ||
| t.deepEqual(parsed, { resourceKey: '**/*.js', ruleKey: 'squid:S001' }); | ||
| }); | ||
|
|
||
| test('buildSettingsParams includes empty string value', t => { | ||
| const params = buildSettingsParams({ key: 'sonar.test.inclusions', component: 'proj', value: '' }); | ||
| t.is(params.get('value'), ''); | ||
| }); | ||
|
|
||
| test('buildSettingsParams omits undefined value', t => { | ||
| const params = buildSettingsParams({ key: 'sonar.exclusions', component: 'proj', value: undefined, values: ['a'] }); | ||
| t.is(params.get('value'), null); | ||
| t.deepEqual(params.getAll('values'), ['a']); | ||
| }); | ||
|
|
||
| test('buildSettingsParams omits null value', t => { | ||
| const params = buildSettingsParams({ key: 'sonar.exclusions', component: 'proj', value: null, values: ['a'] }); | ||
| t.is(params.get('value'), null); | ||
| }); | ||
|
|
||
| // ============================================================================ | ||
| // dispatchSettingToApi | ||
| // ============================================================================ | ||
|
|
||
| test('dispatchSettingToApi dispatches scalar value', async t => { | ||
| const client = { setProjectSetting: sinon.stub().resolves() }; | ||
| const result = await dispatchSettingToApi(client, { key: 'sonar.cpd.enabled', value: 'true' }, 'proj'); | ||
| t.true(result); | ||
| t.deepEqual(client.setProjectSetting.firstCall.args, ['sonar.cpd.enabled', { value: 'true' }, 'proj']); | ||
| }); | ||
|
|
||
| test('dispatchSettingToApi dispatches multi-value array', async t => { | ||
| const client = { setProjectSetting: sinon.stub().resolves() }; | ||
| const result = await dispatchSettingToApi(client, { key: 'sonar.exclusions', values: ['a', 'b'] }, 'proj'); | ||
| t.true(result); | ||
| t.deepEqual(client.setProjectSetting.firstCall.args, ['sonar.exclusions', { values: ['a', 'b'] }, 'proj']); | ||
| }); | ||
|
|
||
| test('dispatchSettingToApi dispatches fieldValues', async t => { | ||
| const client = { setProjectSetting: sinon.stub().resolves() }; | ||
| const fvs = [{ resourceKey: '**/*.js', ruleKey: 'squid:S001' }]; | ||
| const result = await dispatchSettingToApi(client, { key: 'sonar.multi', fieldValues: fvs }, 'proj'); | ||
| t.true(result); | ||
| t.deepEqual(client.setProjectSetting.firstCall.args, ['sonar.multi', { fieldValues: fvs }, 'proj']); | ||
| }); | ||
|
|
||
| test('dispatchSettingToApi dispatches empty string value (not skipped)', async t => { | ||
| const client = { setProjectSetting: sinon.stub().resolves() }; | ||
| const result = await dispatchSettingToApi(client, { key: 'sonar.test.inclusions', value: '' }, 'proj'); | ||
| t.true(result); | ||
| t.deepEqual(client.setProjectSetting.firstCall.args, ['sonar.test.inclusions', { value: '' }, 'proj']); | ||
| }); | ||
|
|
||
| test('dispatchSettingToApi prefers value over values', async t => { | ||
| const client = { setProjectSetting: sinon.stub().resolves() }; | ||
| const result = await dispatchSettingToApi(client, { key: 'k', value: 'scalar', values: ['a'] }, 'proj'); | ||
| t.true(result); | ||
| t.deepEqual(client.setProjectSetting.firstCall.args, ['k', { value: 'scalar' }, 'proj']); | ||
| }); | ||
|
|
||
| test('dispatchSettingToApi returns false for empty setting', async t => { | ||
| const client = { setProjectSetting: sinon.stub().resolves() }; | ||
| const result = await dispatchSettingToApi(client, { key: 'sonar.empty' }, 'proj'); | ||
| t.false(result); | ||
| t.is(client.setProjectSetting.callCount, 0); | ||
| }); | ||
|
|
||
| test('dispatchSettingToApi returns false for empty values array', async t => { | ||
| const client = { setProjectSetting: sinon.stub().resolves() }; | ||
| const result = await dispatchSettingToApi(client, { key: 'sonar.empty', values: [] }, 'proj'); | ||
| t.false(result); | ||
| t.is(client.setProjectSetting.callCount, 0); | ||
| }); | ||
|
|
||
| test('dispatchSettingToApi returns false for empty fieldValues array', async t => { | ||
| const client = { setProjectSetting: sinon.stub().resolves() }; | ||
| const result = await dispatchSettingToApi(client, { key: 'sonar.empty', fieldValues: [] }, 'proj'); | ||
| t.false(result); | ||
| t.is(client.setProjectSetting.callCount, 0); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic duplication:
pickreimplements the value-selection logic fromdispatchSettingToApiinsrc/shared/utils/settings-params.js, but with a silent divergence: it omitsfieldValues.dispatchSettingToApihandles all three shapes (value → values → fieldValues);pickonly handles two.Consequence: a setting that exists as
fieldValueson both sides will havepick()returnundefinedfor both, produce'""'on both sides, and always be reported as matching — even if the SC values are wrong. The only failure mode caught is if the setting is absent from SC entirely.Extract a shared
extractSettingValue(s)helper fromsettings-params.jsand use it here:Then
verify-settings.jssimply callsextractSettingValue(s)instead of the inlinepick.