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

Refactor-x, closes #373 #386

Merged
merged 14 commits into from Aug 27, 2018
Merged

Refactor-x, closes #373 #386

merged 14 commits into from Aug 27, 2018

Conversation

krhubert
Copy link
Contributor

@antho1404
Copy link
Member

please make sure to fix the tests and issues with code climate.
Otherwise it looks great, I like that now most of utils functions really have a meaning :)

@krhubert krhubert force-pushed the refactor-x branch 3 times, most recently from 6e3e2b9 to 3a755b6 Compare August 23, 2018 10:18
package xstrings

// ContainsString returns true if slice s contains e element, false otherwise.
func ContainsString(a []string, e string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

would be better rename to _ SliceContains()_

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ContainsString was chosen based on similarity to strings/bytes pkg:
Contains(s, substr string)
ContainsAny(s, chars string)
ContainsRune(s string, r rune)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see but in our case String word in the function name in xstrings package is not necessary because we define the package functions for the same context with package name. And for this case, it'd be good to indicate we're working on slices otherwise it looks like we're trying to find a substring in a string with current naming.

@@ -77,40 +75,17 @@ func downloadServiceIfNeeded(path string) (newPath string, didDownload bool, err
if !govalidator.IsURL(path) {
return path, false, nil
}
newPath, err = createTempFolder()
newPath, err = ioutil.TempDir("", "mesg-")
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make mesg- a const

@@ -140,12 +141,13 @@ func getTemplateResult(result string, templates []*templateStruct) (tmpl *templa
}

func downloadTemplate(tmpl *templateStruct) (path string, err error) {
path, err = createTempFolder()
path, err = ioutil.TempDir("", "mesg-")
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make mesg- a const

@@ -140,12 +141,13 @@ func getTemplateResult(result string, templates []*templateStruct) (tmpl *templa
}

func downloadTemplate(tmpl *templateStruct) (path string, err error) {
path, err = createTempFolder()
path, err = ioutil.TempDir("", "mesg-")
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make mesg- a const

if err != nil {
return "", false, err
}
if err := gitClone(path, newPath, "Downloading service..."); err != nil {
fmt.Println("Downloading service...")
Copy link
Contributor

Choose a reason for hiding this comment

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

forgot to use utils.ShowSpinnerForFunc()? it was defined in previous version of gitClone()

if err != nil {
return "", err
}

return path, gitClone(tmpl.URL, path, "Downloading template "+tmpl.Name+"...")
fmt.Printf("Downloading template %s ...\n", tmpl.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

forgot to use utils.ShowSpinnerForFunc()? it was defined in previous version of gitClone()

@@ -20,33 +19,6 @@ func TestBuildDockerImagePathDoNotExist(t *testing.T) {
require.NotNil(t, err)
}

func TestGitCloneRepositoryDoNotExist(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should keep these tests

Copy link
Contributor

@ilgooz ilgooz Aug 23, 2018

Choose a reason for hiding this comment

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

changed my mind, no need this here but got to put equivalent to xgit. and mock underlying git package if possible. we need these tests to see if we call git.PlainClone() with the right args.

require.NotNil(t, err)
}

func TestGitCloneWithoutURLSchema(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should keep these tests

Copy link
Contributor

@ilgooz ilgooz Aug 23, 2018

Choose a reason for hiding this comment

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

changed my mind, no need this here but got to put equivalent to xgit. and mock underlying git package if possible. we need these tests to see if we call git.PlainClone() with the right args.

require.Nil(t, err)
}

func TestGitCloneCustomBranch(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should keep these tests

Copy link
Contributor

@ilgooz ilgooz Aug 23, 2018

Choose a reason for hiding this comment

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

changed my mind, no need this here but got to put equivalent to xgit. and mock underlying git package if possible. we need these tests to see if we call git.PlainClone() with the right args.

@krhubert krhubert force-pushed the refactor-x branch 2 times, most recently from 94e6643 to 0ec576d Compare August 23, 2018 14:41
ilgooz
ilgooz previously requested changes Aug 23, 2018
//
// This function uses md5 hashing function and default formatter. See also Dump()
// function.
func Hash(c interface{}, version int) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

can test this with structhash.Version(hash) by comparing versions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope :P

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't make sense to me, leaving this to @antho1404's watch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

)

// WaitForInterrupt creates a read channel for catch SIGINT and SIGTERM signals.
func WaitForInterrupt() <-chan os.Signal {
Copy link
Contributor

Choose a reason for hiding this comment

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

can test this with:

Copy link
Contributor

Choose a reason for hiding this comment

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

leaving this to @antho1404's judgment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

x/xos/os.go Outdated
if err != nil {
return err
}
f.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

we can return error with an err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

t.Fatalf("Touched file dosen't exist")
}

if err := Touch(name); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why we Touch twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// Touch creates a new file, truncating it if it already exists. => to make sure touch doesn't' return an error

name := filepath.Join(os.TempDir(), "__test-file")
defer Remove(name)
if err := Touch(name); err != nil {
t.Fatalf("Touch failed: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

we can use require package for testing x package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally didn't use require package here to keep it as simple as possible and reduce dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't make sense to me, leaving this to @antho1404's watch

Copy link
Member

Choose a reason for hiding this comment

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

I kind of prefer to use the require package in order to have a coherence in the codebase. And for now these packages are still in the project so it doesn't really matter to have this extra dependency but I understand that maybe one day it can be useful.

In other terms I don't mind one or the other are fine, it's not a big deal for me even if I would prefer to use require package from now to have consistency

x/xos/file.go Outdated
return err
}

// RemoveAll removes all given paht and any children it contains.
Copy link
Contributor

Choose a reason for hiding this comment

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

paht to path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

x/xos/file.go Outdated
}

// RemoveAll removes all given paht and any children it contains.
func RemoveAll(paths ...string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

can be renamed as RemoveRecursive, if you wish

Copy link
Member

Choose a reason for hiding this comment

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

RemoveAll is fine for me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving RemoveAll

antho1404
antho1404 previously approved these changes Aug 24, 2018
Copy link
Member

@antho1404 antho1404 left a comment

Choose a reason for hiding this comment

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

Except the few other remarks already in the PR it's good for me

Copy link
Member

@NicolasMahe NicolasMahe left a comment

Choose a reason for hiding this comment

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

Can you merge the dev branch please

if err != nil {
return "", err
}

return path, gitClone(tmpl.URL, path, "Downloading template "+tmpl.Name+"...")
message := fmt.Sprintf("Downloading template %s ...\n", tmpl.Name)
Copy link
Member

Choose a reason for hiding this comment

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

This is not valid, the \n create some problems with the spinner. We should never use a \n when it's a message for the spinner

⣾ Downloading template Javascript ...
⣽ Downloading template Javascript ...
⣻ Downloading template Javascript ...
⢿ Downloading template Javascript ...
⡿ Downloading template Javascript ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,14 @@
package xrequire
Copy link
Contributor

Choose a reason for hiding this comment

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

xarchive

if err != nil {
return err
// prepareService downloads if needed, create the service, build it and inject configuration
func prepareService(path string) *service.Service {
Copy link
Member

Choose a reason for hiding this comment

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

thanks to codeclimate, I think this function is not needed here, same for downloadServiceIfNeeded or injectConfigurationInDependencies because they moved to the mesg/deploy @ilgooz can you confirm ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes that is correct. @krhubert can you please check the current version of cmd/service/utils.go in dev branch and compare with yours to see diffs. Thanks a lot.

antho1404
antho1404 previously approved these changes Aug 26, 2018
Copy link
Member

@NicolasMahe NicolasMahe left a comment

Choose a reason for hiding this comment

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

Some changes to do, maybe related to a merge

)

// GzippedTar creates an archive from the directory at path compressed with gzip.
func GzippedTar(path string) (io.Reader, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This function is not used anywhere. Maybe a problem with the merge?

The codebase is still using TarWithOptions

Copy link
Contributor

Choose a reason for hiding this comment

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

i requested this one, will be used by tests

Copy link
Member

Choose a reason for hiding this comment

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

Why not using it in the codebase instead of TarWithOptions?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes we should

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @ilgooz pointed out, the function will be used

Copy link
Member

Choose a reason for hiding this comment

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

So, please update the codebase to use this GzippedTar function or at least create some issue to not forget. Otherwise, I worry that we will end up with a lot of function in x packages that no other function.

Here are some place that use TarWithOptions:

https://github.com/mesg-foundation/core/blob/8711a71037209288d39287805c7653f7bb043da9/container/build.go#L26-L29

https://github.com/mesg-foundation/core/blob/8711a71037209288d39287805c7653f7bb043da9/mesg/deploy_test.go#L30

https://github.com/mesg-foundation/core/blob/8711a71037209288d39287805c7653f7bb043da9/mesg/deploy_test.go#L77

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same with git clone, it's another branch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

)

// Clone clones a repository from url into the path.
func Clone(URL string, path string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and? What's about the PlainClone?

Copy link
Member

Choose a reason for hiding this comment

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

Why not make the deploy_deployer file use the function from x packages?

Copy link
Member

Choose a reason for hiding this comment

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

The following function has been moved to xgit:

https://github.com/mesg-foundation/core/blob/8711a71037209288d39287805c7653f7bb043da9/mesg/deploy_deployer.go#L80-L96

So let's remove it, and update the code to use the one from xgit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but deploy_deplyer.go is inside another branch. So we need to merge this into the dev and then merge dev into that branch and update code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


// GetenvDefault retrieves the value of the environment variable named by the key.
// It returns the value, which will be set to fallback if the variable is empty.
func GetenvDefault(key, fallback string) string {
Copy link
Member

Choose a reason for hiding this comment

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

This function is never used.

Copy link
Member

Choose a reason for hiding this comment

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

And I would recommend to use Viper for the default value management

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left it if someone need this function (eg for testing)

@NicolasMahe NicolasMahe added this to In progress in v1.2 via automation Aug 27, 2018
@NicolasMahe NicolasMahe moved this from In progress to Changes requested in v1.2 Aug 27, 2018
v1.2 automation moved this from Changes requested to Needs review Aug 27, 2018
@antho1404 antho1404 merged commit d017e19 into dev Aug 27, 2018
v1.2 automation moved this from Needs review to Done Aug 27, 2018
@antho1404 antho1404 deleted the refactor-x branch August 27, 2018 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v1.2
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants