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

bug fix for deploy target config & updated test #83

Closed
wants to merge 4 commits into from

Conversation

rashed-k
Copy link
Contributor

@rashed-k rashed-k commented Mar 20, 2024

As the previous code did not remove old duplicate target config which had same branch, pull-request, deploytarget ID and weight (As it assumed that the desired and existing matched according to the logic and did not perform the task). I added grouped_configs to use in the function for marking addition and deletion of deploy target config.

@rashed-k rashed-k requested review from steveworley and yusufhm March 20, 2024 04:42
grouped_configs[key].append(config)

#Identify duplicates and mark older ones for deletion
for key, configs in grouped_configs.items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rashed-k can you explain the need to do this? In the above iteration you know if you've added a deploy config based on the constructed key to the seen config list so you could mark them for delete at that time without this extra logic.


grouped_configs = {}
for config in existing_configs:
key = (config['branches'], config['pullrequests'], str(config['deployTarget']['id']), str(config['weight']))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is config['weight'] a good field to create a unique key on if this is to fix duplicate configuration items? weight is generally used to control ordering and it is common practice to use 0 when no weight is given.

For example:

configs = [{
	"id": 3524,
	"branches": "^master$",
	"pullrequests": "false",
	"deployTarget": {
		"created": "2021-10-06 05:05:44",
		"id": 6
	},
	"weight": 1
},
{
	"id": 3525,
	"branches": "^master$",
	"pullrequests": "false",
	"deployTarget": {
		"created": "2021-10-06 05:05:44",
		"id": 6
	},
	"weight": 2
}
]

The key would look something like:

Created key: ('^master$', 'false', '6', '1')
Created key: ('^master$', 'false', '6', '2')

For each item and it would skip removing the duplicate entry for ^master$


if not found or not uptodate:
key = (desired['branches'], desired['pullrequests'], str(desired['deployTarget']), str(desired['weight']))
if key not in grouped_configs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, I think we could simplify this logic loop — you can modify config when you see it first and add a exists property rather than duplicating the key logic which will make this simpler to maintain going forward.

@rashed-k rashed-k closed this Apr 8, 2024
@rashed-k rashed-k deleted the feature/fix-bug-deploy-target-config branch November 24, 2024 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants