-
Notifications
You must be signed in to change notification settings - Fork 223
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
Conversation
This needs to be filled out. |
commands/new_function.go
Outdated
@@ -85,6 +85,8 @@ the "Dockerfile" lang type in your YAML file. | |||
fmt.Printf("Folder: %s created.\n", functionName) | |||
} | |||
|
|||
createORUpdateGitignore() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
commands/new_function.go
Outdated
func createORUpdateGitignore() { | ||
FILES_TO_IGNORE := []string{"template", "build"} | ||
|
||
f, err := os.OpenFile(".gitignore", os.O_RDWR|os.O_CREATE, 0644) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
commands/new_function.go
Outdated
return false | ||
} | ||
|
||
func createORUpdateGitignore() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. |
I have tested this with 2 scenario .. Any suggestion for testcases ? |
commands/new_function.go
Outdated
lines := strings.Split(string_content, "\n") | ||
if err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
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. 👍
commands/new_function.go
Outdated
return false | ||
} | ||
|
||
func updateGitignore() (err error) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
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 ? |
61fa096
to
72061f5
Compare
@alexellis Never mind I got it. |
I have made the requested changes and squashed all commits into a single commit. |
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? |
I can do that. I will setup a windows VM and development environment in window and do the testing. |
@alexellis I have tested it in windows.. It is working fine. Please find the attached gif. You can also have look at this video. |
@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. |
commands/update_gitignore.go
Outdated
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"} |
There was a problem hiding this comment.
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"
There was a problem hiding this 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.
Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off. |
… 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
bfcca78
to
d40dd48
Compare
@alexellis I have made the requested changes and updated the PR. Please review it. |
Thank you @viveksyngh, apologies for the delay. Are you also on Slack? It's a good place to ping someone for merge/review. |
Yes I am on slack. How can I join the slack channel ? |
… present .gitignore
Signed-off-by: Vivek Singh [email protected]
Description
Motivation and Context
How Has This Been Tested?
Types of changes
Checklist:
git commit -s