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

Would like a nicer way to detect config as code projects #133

Open
borland opened this issue Aug 9, 2022 · 2 comments
Open

Would like a nicer way to detect config as code projects #133

borland opened this issue Aug 9, 2022 · 2 comments

Comments

@borland
Copy link
Collaborator

borland commented Aug 9, 2022

The current approach expects the caller to do this:

project.PersistenceSettings.GetType() != "VersionControlled"

Reference:

if project.PersistenceSettings != nil && project.PersistenceSettings.GetType() == "VersionControlled" {

It would be nice if there was a cleaner way to detect a version-controlled project other than comparing with this magic string

@borland
Copy link
Collaborator Author

borland commented Aug 9, 2022

Throwing ideas out: 1

We could define a type-aliased string, like we did with AccountType
(ref: https://github.com/OctopusDeploy/go-octopusdeploy/blob/21f647f96584020014c295a92badc902b71b1581/pkg/accounts/account_types.go )

For this example it would be something like

type ProjectPersistenceType string

const ProjectPersistenceTypeVersionControlled =  ProjectPersistenceType("VersionControlled")
const ProjectPersistenceTypeDatabase =  ProjectPersistenceType("Database")

A possible issue with this approach is that it appears as though the persistence type can be sent in JSON from the server

https://github.com/OctopusDeploy/go-octopusdeploy/blob/21f647f96584020014c295a92badc902b71b1581/pkg/projects/persistence_settings.go

If indeed it is, then this opens up the possibility of there being additional persistence types other than VersionControlled/Database in the future, and we might want to consider what to do there.

@borland
Copy link
Collaborator Author

borland commented Aug 9, 2022

Throwing ideas out: 2

The different persistence settings are actually represented by different structs in Go

e.g. https://github.com/OctopusDeploy/go-octopusdeploy/blob/21f647f96584020014c295a92badc902b71b1581/pkg/projects/database_persistence_settings.go

We could therefore use the go casting operator to detect a project persistence type, e.g.

dbSettings, ok := project.PersistenceSettings.(DatabasePersistenceSettings)
if ok {
   // we know it's a database project
}

This is a bit awkward though and makes the code longer, it's not a clear win

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

No branches or pull requests

1 participant