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

Update .gitignore when generating templates #137

Merged
merged 1 commit into from
Nov 6, 2017

Conversation

viveksyngh
Copy link
Contributor

@viveksyngh viveksyngh commented Oct 3, 2017

… present .gitignore

Signed-off-by: Vivek Singh [email protected]

Description

Motivation and Context

  • I have raised an issue to propose this change (required)

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@viveksyngh
Copy link
Contributor Author

viveksyngh commented Oct 3, 2017

#127

@alexellis
Copy link
Member

How Has This Been Tested?

This needs to be filled out.

@@ -85,6 +85,8 @@ the "Dockerfile" lang type in your YAML file.
fmt.Printf("Folder: %s created.\n", functionName)
}

createORUpdateGitignore()
Copy link
Member

Choose a reason for hiding this comment

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

Probably could be: updateGitignore - add a comment that it creates it if non-existant

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 have updated the function name.

func createORUpdateGitignore() {
FILES_TO_IGNORE := []string{"template", "build"}

f, err := os.OpenFile(".gitignore", os.O_RDWR|os.O_CREATE, 0644)
Copy link
Member

Choose a reason for hiding this comment

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

does this need an os.Stat to check for the file before opening?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will create file if it is not present otherwise it will open it with read-write

return false
}

func createORUpdateGitignore() {
Copy link
Member

Choose a reason for hiding this comment

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

Would be better if this returned an error instead of printing out to fmt. Then we can print in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated and pushed the changes.

@open-derek
Copy link

open-derek bot commented Oct 3, 2017

Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off.
That's something we need before your Pull Request can be merged. Please see our contributing guide.

@open-derek open-derek bot added the no-dco label Oct 3, 2017
@viveksyngh
Copy link
Contributor Author

viveksyngh commented Oct 3, 2017

I have tested this with 2 scenario ..
1.) Created new function when .gitignore file is not present in the current directory
2.) Created a new function when .gitignore file is already present and having some files added

Any suggestion for testcases ?

lines := strings.Split(string_content, "\n")
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

Looks much cleaner without all the nested if statements. 👍

return false
}

func updateGitignore() (err error) {
Copy link
Member

Choose a reason for hiding this comment

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

While we may not be able to test the file editing easily, what do you think about extracting a method that does the transform and testing that independently? This would be good for regression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that extracted functions will only take the file content, updates the content and returns it back ? I should write test for that function ?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like a good approach. That way the function only does 1 thing and can be tested without worrying about editing on disk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay .. I will do that. In which file am I supposed to write test and which library to use for testing ?

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.

Updated and pushed suggested changes.

@alexellis alexellis changed the title create .gitingore file if does not exists otherwise append to already… Update .gitignore when generating templates Oct 4, 2017
Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Please could you rebase/squash all these commits into one?

@viveksyngh
Copy link
Contributor Author

viveksyngh commented Oct 5, 2017

I tried doing that .. but it is increasing the number of commit. Can you guide me on this ?

I squashed the commits in local .. when I took pull and pushed the branch to remote it increased the number of commits. Should push only the commit on which I have squashed all other commits ?

@open-derek open-derek bot removed the no-dco label Oct 5, 2017
@viveksyngh
Copy link
Contributor Author

@alexellis Never mind I got it.

@viveksyngh
Copy link
Contributor Author

I have made the requested changes and squashed all commits into a single commit.

@alexellis
Copy link
Member

alexellis commented Oct 6, 2017

Thank you for that 👍 @viveksyngh I think we should test this on a Windows machine or VM before merging. Can you do that or should we call someone in to the thread?

@viveksyngh
Copy link
Contributor Author

I can do that. I will setup a windows VM and development environment in window and do the testing.

@viveksyngh
Copy link
Contributor Author

viveksyngh commented Oct 7, 2017

@alexellis I have tested it in windows.. It is working fine. Please find the attached gif.

ekkootm4pe

You can also have look at this video.

http://recordit.co/ekkoOtM4PE

@viveksyngh
Copy link
Contributor Author

@alexellis Please review the test result from windows environment that I have attached in previous reply. Please Let me know if further testing is required for windows environment.

func updateContent(content string) (updated_content string) {
// append files to ignore to file content if it is not already ignored

FILES_TO_IGNORE := []string{"template", "build"}
Copy link
Member

@alexellis alexellis Oct 23, 2017

Choose a reason for hiding this comment

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

Please case this as "filesToIgnore" or "ignore"

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

Changes requested, otherwise we need to merge this soon, so please get in touch if you need help.

@open-derek open-derek bot added the no-dco label Oct 23, 2017
@open-derek
Copy link

open-derek bot commented Oct 23, 2017

Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off.
That's something we need before your Pull Request can be merged. Please see our contributing guide.

… present .gitignore

Signed-off-by: Vivek Singh <[email protected]>

changed function name to updateGitignore, return error from function and print at one place

Signed-off-by: Vivek Singh <[email protected]>

extracted update function, placed all update .gitignore func in one file

added testcases for updateContent func

Signed-off-by: Vivek Singh <[email protected]>

extracted update function, placed all update .gitignore func in one file

added testcases for updateContent func

Signed-off-by: Vivek Singh <[email protected]>

added testcases for updateContent func

changes FILES_TO_IGNORE variable to filesToIgnore

Signed-off-by: Vivek Singh <[email protected]>

changes FILES_TO_IGNORE variable to filesToIgnore
@viveksyngh
Copy link
Contributor Author

@alexellis I have made the requested changes and updated the PR. Please review it.

@alexellis
Copy link
Member

Thank you @viveksyngh, apologies for the delay. Are you also on Slack? It's a good place to ping someone for merge/review.

@alexellis alexellis merged commit 16f019b into openfaas:master Nov 6, 2017
@viveksyngh
Copy link
Contributor Author

Yes I am on slack. How can I join the slack channel ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants