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

Project level new code setting won't save #272

Closed
thefang12 opened this issue Nov 12, 2020 · 17 comments
Closed

Project level new code setting won't save #272

thefang12 opened this issue Nov 12, 2020 · 17 comments
Labels
bug Something isn't working

Comments

@thefang12
Copy link

thefang12 commented Nov 12, 2020

Describe the bug
Setting new_code_period at the project level doesn't work at all.
To Reproduce
Steps to reproduce the behavior:

  1. create a project
  2. go to Project Settings > New Code
  3. set the Define a specific setting for this project setting to any other than global default
  4. click save
  5. UI will show saved but reloading the page shows the project new_code_period doesn't change

Expected behavior
Project new_code_period is persisted once changed from the global default.

Screenshots
If applicable, add screenshots to help explain your problem.
Setting new_code_period:
Screen Shot 2020-11-12 at 14 07 35
After reload:
Screen Shot 2020-11-12 at 14 08 12

Software Versions

  • SonarQube Versions: 8.4.1, 8.4.0,8.4.2
  • Plugin Version: 1.5.0

Additional Comments
The feature works correctly at global and branch levels.
Tried setting it using the UI and the web API and both return a 200 without persisitiing the new_code_period change. The only workaround I've found is to insert the new_code_period record in the new_code_periods table manually 😞 .

@thefang12 thefang12 added the bug Something isn't working label Nov 12, 2020
@anand-ispg
Copy link

@thefang12 I also had this issue but If you notice while making changes, it says this setting will apply after your next scan. So after making the change and running another analysis it worked.

@powerdefy
Copy link

I also have the issue.

@thefang12
Copy link
Author

@anand-ispg when you change the setting in the UI it retroactively changes any branch that has already been scanned to the new_code_period that why it works on next scan, the issue is for any new branches it still uses the global new_code_period not the one set at a project level.
@powerdefy it's not a nice workaround, but the only thing that got this working was to manually access the DB and insert a new_code_period record with the project uuid and branch name column null in the new_code_periods table. Hope it helps.

@powerdefy
Copy link

@thefang12 Thank you, I insert a new row manually and it works.

@Dr-Dream
Copy link

Dr-Dream commented Nov 26, 2020

@thefang12. Thanks for workaround.
Same for me.
When setting reference branch for project it fills new_code_period.branch_uuid with project_uuid.
UI shows this setting as for master branch.
if update branch_uuid null it works.
After update you should update master branch settings at branch level.

@mc1arke
Copy link
Owner

mc1arke commented Nov 27, 2020

@Dr-Dream can you confirm the exact steps your taking here? I presume this is updates to values in the database you're making, so it would be useful to know which tables and columns you're altering, and example of their pre and post change values are

@Dr-Dream
Copy link

Dr-Dream commented Nov 27, 2020

@mc1arke ,

As it works for me.

As i understood, according to what i saw during changes in new_code_periods through UI - project_uuid and branch_uuid have same value.

So when you change project settings from default in UI - new record in new_code_periods record filled project_uuid and branch_uuid with same uuid value.

So if branch_uuid is set, setting reffers to master branch only.

Actually, currently, there is no way to change this settings at project level through UI.
Branch-level settings only.

If barnch_uuid is null, it counted as project settings.
i discovered it updating record for master branch, by 'update new_code_periods set branch_uuid=null where .....' directly in postgres.

After that, i've changed through UI settings exactly for master branch, because it should differs from project one (should not reffer itself).

After that all new analisys for new branches done against master.

I hope it will helps.

One more note. There is no unique constraints on table, so accidentally you could make two or more settings at project level. That will be followed by errors and you'll be not able to get project level settings of new code in UI at all.
Experienced myself.

@Dr-Dream
Copy link

Dr-Dream commented Nov 27, 2020

Exact steps to reproduce and fix for 1 project, not a simpliest one. :)
For multiple projects at once i don't have solution..

  1. Newly created project

image
Selecting new_code periods by project_uuid.

sonarDB=> 
select * from new_code_periods where project_uuid='AXYKmHx31W5kG7yc_CXo';
uuid | project_uuid | branch_uuid | type | value | updated_at | created_at
------+--------------+-------------+------+-------+------------+------------
(0 rows)
  1. Changing default settings.
    image
sonarDB=> select * from new_code_periods where project_uuid='AXYKmHx31W5kG7yc_CXo';
         uuid         |     project_uuid     |     branch_uuid      |       type       | value  |  updated_at   |  created_at
----------------------+----------------------+----------------------+------------------+--------+---------------+---------------
 AXYKtQCv1W5kG7yc_CX1 | AXYKmHx31W5kG7yc_CXo | AXYKmHx31W5kG7yc_CXo | REFERENCE_BRANCH | master | 1606497403052 | 1606497403052
(1 row)
  1. Refresh
    image
sonarDB=> select * from new_code_periods where project_uuid='AXYKmHx31W5kG7yc_CXo';
         uuid         |     project_uuid     |     branch_uuid      |       type       | value  |  updated_at   |  created_at
----------------------+----------------------+----------------------+------------------+--------+---------------+---------------
 AXYKtQCv1W5kG7yc_CX1 | AXYKmHx31W5kG7yc_CXo | AXYKmHx31W5kG7yc_CXo | REFERENCE_BRANCH | master | 1606497403052 | 1606497403052
(1 row)
  1. Update & Refresh
sonarDB=> update new_code_periods set branch_uuid=null where uuid='AXYKtQCv1W5kG7yc_CX1';
UPDATE 1

image

sonarDB=> select * from new_code_periods where project_uuid='AXYKmHx31W5kG7yc_CXo';
         uuid         |     project_uuid     |     branch_uuid      |       type       | value  |  updated_at   |  created_at
----------------------+----------------------+----------------------+------------------+--------+---------------+---------------
 AXYKtQCv1W5kG7yc_CX1 | AXYKmHx31W5kG7yc_CXo |                      | REFERENCE_BRANCH | master | 1606497403052 | 1606497403052
(1 row)
  1. Saved master branch settings at branch level & refresh
    image
sonarDB=> select * from new_code_periods where project_uuid='AXYKmHx31W5kG7yc_CXo';
         uuid         |     project_uuid     |     branch_uuid      |       type       | value  |  updated_at   |  created_at
----------------------+----------------------+----------------------+------------------+--------+---------------+---------------
 AXYKtQCv1W5kG7yc_CX1 | AXYKmHx31W5kG7yc_CXo |                      | REFERENCE_BRANCH | master | 1606497403052 | 1606497403052
 AXYKwcip1W5kG7yc_CX2 | AXYKmHx31W5kG7yc_CXo | AXYKmHx31W5kG7yc_CXo | PREVIOUS_VERSION |        | 1606498240679 | 1606498240679
(2 rows)

@Sleepy-GH
Copy link

I'm running into this as well with the new SonarQube 8.9 LTS version and 1.8.0 version of the plugin.

mc1arke added a commit that referenced this issue Jul 2, 2021
The New Code Period webservices contain logic that specifically sets the target branch UUID to the main branch of the project if the Community version of Sonarqube is being used, thereby overriding the branch name that's been saved in the new code period's value.

The existing Java Agent functionality has been extended to alter the constructors of the relevant New Code services so they override the bundled Edition Provider that specifies the current platform edition as being Community edition, and instead injects a provider that overrides the current distribution as Developer edition, thereby causing the webservice logic to skip applying defaults for branch values.
mc1arke added a commit that referenced this issue Jul 2, 2021
The New Code Period webservices contain logic that specifically sets the target branch UUID to the main branch of the project if the Community version of Sonarqube is being used, thereby overriding the branch name that's been saved in the new code period's value.

The existing Java Agent functionality has been extended to alter the constructors of the relevant New Code services so they override the bundled Edition Provider that specifies the current platform edition as being Community edition, and instead injects a provider that overrides the current distribution as Developer edition, thereby causing the webservice logic to skip applying defaults for branch values.
mc1arke added a commit that referenced this issue Jul 2, 2021
The New Code Period webservices contain logic that specifically sets the target branch UUID to the main branch of the project if the Community version of Sonarqube is being used, thereby overriding the branch name that's been saved in the new code period's value.

The existing Java Agent functionality has been extended to alter the constructors of the relevant New Code services so they override the bundled Edition Provider that specifies the current platform edition as being Community edition, and instead injects a provider that overrides the current distribution as Developer edition, thereby causing the webservice logic to skip applying defaults for branch values.
mc1arke added a commit that referenced this issue Jul 2, 2021
The New Code Period webservices contain logic that specifically sets the target branch UUID to the main branch of the project if the Community version of Sonarqube is being used, thereby overriding the branch name that's been saved in the new code period's value.

The existing Java Agent functionality has been extended to alter the constructors of the relevant New Code services so they override the bundled Edition Provider that specifies the current platform edition as being Community edition, and instead injects a provider that overrides the current distribution as Developer edition, thereby causing the webservice logic to skip applying defaults for branch values.
@mc1arke mc1arke added awaiting release Merged but not currently in release version backport candidate This feature or fix should be included in another release branch labels Jul 2, 2021
@BlankSergey
Copy link

when it will be released?

@pro-krastinator
Copy link

Looking forward to release as well :)

@Golovanoff
Copy link

It's a miracle we need - the miracle
😀

@mc1arke
Copy link
Owner

mc1arke commented Aug 14, 2021

Released in v1.9.0 of the plugin.

@mc1arke mc1arke closed this as completed Aug 14, 2021
@Sleepy-GH
Copy link

@mc1arke Any chance that this can get backported to version 1.8.0 of the plugin?

@mc1arke
Copy link
Owner

mc1arke commented Aug 18, 2021

@mc1arke Any chance that this can get backported to version 1.8.0 of the plugin?

Yes! I was giving it a couple of days between the 1.9.0 release and performing any back-porting to make sure no-one reported any major issues. I'll be looking to back-port all the 1.9.0 functional changes other than the commit for supporting Sonarqube 9.0. I'll hopefully get a 1.8.1 release of the plugin out toward the end of this week.

@Sleepy-GH
Copy link

Yes! I was giving it a couple of days between the 1.9.0 release and performing any back-porting to make sure no-one reported any major issues. I'll be looking to back-port all the 1.9.0 functional changes other than the commit for supporting Sonarqube 9.0. I'll hopefully get a 1.8.1 release of the plugin out toward the end of this week.

This is awesome. Thanks for your effort, it's much appreciated!

mc1arke added a commit that referenced this issue Aug 22, 2021
The New Code Period webservices contain logic that specifically sets the target branch UUID to the main branch of the project if the Community version of Sonarqube is being used, thereby overriding the branch name that's been saved in the new code period's value.

The existing Java Agent functionality has been extended to alter the constructors of the relevant New Code services so they override the bundled Edition Provider that specifies the current platform edition as being Community edition, and instead injects a provider that overrides the current distribution as Developer edition, thereby causing the webservice logic to skip applying defaults for branch values.

(cherry picked from commit 6f589e6)
@mc1arke
Copy link
Owner

mc1arke commented Aug 23, 2021

Backported to 1.8.1 of the plugin for Sonarqube 8.9 support.

@mc1arke mc1arke removed awaiting release Merged but not currently in release version backport candidate This feature or fix should be included in another release branch labels Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants