Fixed: CxFlow tries do delete a wrong SAST project when the project name was defined in config-as-code #384
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.
Description
This is what happened before the fix:
Suppose user has a 'MyRepo' repository with 'featureBranch' that contains config-as-code. The config-as-code contains
no Groovy script for project name generation is present, and 'multi-tenant' is set to 'true' in application.yml.
* If for some reason a 'MyRepo-featureBranch' project does exist in SAST, then we get a situation when a wrong project is deleted.
The fix
Add support for a new application.yml property:
use-config-as-code-from-default-branch: true/false
If true: config-as-code is always loaded from the default repo branch.
If false: config-as-code is loaded from the current branch (this is the default value).
The new property has effect in all the flows (pull, push, delete). The new property is currently supported for GitHub only.
Change in deletion flow: if the deleted branch is protected (is within the cx-flow/branches list):
How this will help to resolve the issue:
- User sets use-config-as-code-from-default-branch: true in application.yml
- User makes sure that the default repo branch contains a correct config-as-code.
- This way CxFlow will use the correct SAST project name both when the SAST project is created and deleted.
References
GitHub issue: #345
Work item: 202
Testing
Added tests for the 2 parts of the fix. See delete-branch.feature and cxconfig.feature.