KEMBAR78
Implement Backup Feature by baile320 · Pull Request #272 · dotenv-linter/dotenv-linter · GitHub
Skip to content

Conversation

baile320
Copy link
Contributor

@baile320 baile320 commented Aug 21, 2020

Hey All, I had some questions/comments about this PR. The basic functionality is in the PR to create a copy of a file via the -c/--copy flag, though.

Questions:

  1. I just used a Unix epoch time timestamp. We could add a more nicely formatted one, but it seems likely we'd need to add a crate (I'm not sure?), and I don't know if that's wanted or needed. The Unix timestamps still allow the copies to easily be sorted by most recent.

  2. Should copying the file be automatic any time there are fixes?

    1. If it should be automatic, should there be an opt-out flag? If so, what flag? -n//--no-copy?
    2. If users should always specify a flag to create a copy, should we prompt them that their file will get overwritten?
  • This PR has been added to CHANGELOG.md (at the top of the list);
  • Tests for the changes have been added (for bug fixes / features);
  • Docs have been added / updated (for bug fixes / features).

@baile320 baile320 mentioned this pull request Aug 21, 2020
21 tasks
@mgrachev mgrachev added the discussion Discussion of something label Aug 21, 2020
@mgrachev
Copy link
Member

mgrachev commented Aug 21, 2020

@baile320 Thanks a lot for your proposal! 🔥

  1. I just used a Unix epoch time timestamp. We could add a more nicely formatted one, but it seems likely we'd need to add a crate (I'm not sure?), and I don't know if that's wanted or needed. The Unix timestamps still allow the copies to easily be sorted by most recent.

I think the Unix timestamps will be enough for the first time.

  1. Should copying the file be automatic any time there are fixes?

    1. If it should be automatic, should there be an opt-out flag? If so, what flag? -n//--no-copy?
    2. If users should always specify a flag to create a copy, should we prompt them that their file will get overwritten?

I think this feature should be by default when a user tries to fix warnings and we should add an argument to skip this action.

Also, I have some proposals:

  1. This feature should be named backup;
  2. The flag to skip this action should be named --no-backup;
  3. We should inform users about creating a backup copy of files after fixing.

@mgrachev mgrachev requested a review from a team August 21, 2020 12:09
@baile320
Copy link
Contributor Author

Thanks for your comments, I will make those changes and convert this from a draft when I'm finished 👍

@baile320
Copy link
Contributor Author

baile320 commented Aug 26, 2020

Just an update/FYI - I haven't forgotten about this, just been busy. I think I'll have time do make the changes later today.

@baile320 baile320 changed the title Implement Copy Flag Implement Backup Feature Aug 30, 2020
@baile320
Copy link
Contributor Author

I believe this should be ready for review now. Changes made since discussion:

  1. Renamed feature from Copy to Backup (changed arg to "no-backup", --no-backup, and no short name)
  2. Using fs::copy instead of fs::write to create the file.
  3. Inform users of the file created after creating it.
  4. Only back up file if the .env file is being modified
  5. Added the backup files to .gitignore as well (.env_)

@baile320
Copy link
Contributor Author

I'm not sure why the CI / Test and coverage / Linux (pull_request) Failing after 45s — Test and coverage / Linux is failing, is this something I need to look into? I see a couple other PRs where it failed as well.

@baile320 baile320 marked this pull request as ready for review August 30, 2020 14:47
@evgeniy-r
Copy link
Contributor

I'm not sure why the CI / Test and coverage / Linux (pull_request) Failing after 45s — Test and coverage / Linux is failing, is this something I need to look into?

This is due to a change in the output:
https://github.com/dotenv-linter/dotenv-linter/pull/272/checks?check_run_id=1047857184#step:9:210

@mgrachev
Copy link
Member

mgrachev commented Sep 1, 2020

This is due to a change in the output:
https://github.com/dotenv-linter/dotenv-linter/pull/272/checks?check_run_id=1047857184#step:9:210

Please also update all integration tests and write another one to cover the --no-backup flag.

@mgrachev mgrachev requested a review from a team September 1, 2020 10:49
Copy link
Member

@DDtKey DDtKey left a comment

Choose a reason for hiding this comment

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

Thank you for you contribution! 🚀
I left some comments, please take a look them.

@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2020

Codecov Report

Merging #272 into master will decrease coverage by 0.18%.
The diff coverage is 86.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #272      +/-   ##
==========================================
- Coverage   97.64%   97.46%   -0.19%     
==========================================
  Files          31       31              
  Lines        2634     2679      +45     
==========================================
+ Hits         2572     2611      +39     
- Misses         62       68       +6     
Impacted Files Coverage Δ
src/lib.rs 89.85% <40.00%> (-3.90%) ⬇️
src/fs_utils.rs 97.14% <92.30%> (-2.86%) ⬇️
src/main.rs 91.48% <100.00%> (+0.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a86e76...a7bc286. Read the comment docs.

@baile320
Copy link
Contributor Author

baile320 commented Sep 1, 2020

Please also update all integration tests and write another one to cover the --no-backup flag.

Still need to complete this task, will get to it later today and post a reply when completed

@mgrachev mgrachev added this to the v2.2.0 milestone Sep 2, 2020
@baile320
Copy link
Contributor Author

baile320 commented Sep 2, 2020

hmm... i'm not sure how much detail I should be checking when a backup is created in an integration test. since the file is created with a timestamp, i'm not sure how to know when testing what that timestamp would be? I could just check for a wildcard file or something if that's necessary? I feel a little stuck on testing these fs components.

but in the unit test i already do make sure the filepath & backup filepath are different, and that the backup filepath has the original environment.

@mgrachev
Copy link
Member

mgrachev commented Sep 5, 2020

hmm... i'm not sure how much detail I should be checking when a backup is created in an integration test. since the file is created with a timestamp, i'm not sure how to know when testing what that timestamp would be? I could just check for a wildcard file or something if that's necessary? I feel a little stuck on testing these fs components.

but in the unit test i already do make sure the filepath & backup filepath are different, and that the backup filepath has the original environment.

In my opinion, in the intragration test you should create a file with some problems, for example: foo=bar.
Then, you should run dotenv-linter with the -f flag and check that:

  1. The content of the .env file doesn't equal foo=bar;
  2. The content of the backup file equal foo=bar;

I think that is all.

@mgrachev mgrachev requested a review from DDtKey September 5, 2020 13:08
@baile320
Copy link
Contributor Author

baile320 commented Sep 6, 2020

Hm. I think having a separate function for a single test is probably overkill as well, but I think I need a testing function that has some different functionality than the current ones.

I think I need a test function that will let me

  1. supply arguments
  2. not close/delete TestDir when done, and doesn't take ownership
  3. doesn't require me to supply the expected output.

The reasons for those are:

  1. I changed the other tests to have -f --no-backup (I think this is OK, it basically acts to preserve the functionality of the tests that existed prior to adding this feature),
  2. I need to be able to the examine the TestDir for the backup file after running
  3. I don't know what the expected output will be because we're generating a dynamic timestamp every time we run, and I don't see an easy way of mocking that value.

I'm open to suggestions on any of these points, especially the last one.

@baile320 baile320 requested a review from mgrachev September 6, 2020 14:14
@mgrachev
Copy link
Member

Hm. I think having a separate function for a single test is probably overkill as well, but I think I need a testing function that has some different functionality than the current ones.

I think I need a test function that will let me

  1. supply arguments
  2. not close/delete TestDir when done, and doesn't take ownership
  3. doesn't require me to supply the expected output.

The reasons for those are:

  1. I changed the other tests to have -f --no-backup (I think this is OK, it basically acts to preserve the functionality of the tests that existed prior to adding this feature),
  2. I need to be able to the examine the TestDir for the backup file after running
  3. I don't know what the expected output will be because we're generating a dynamic timestamp every time we run, and I don't see an easy way of mocking that value.

I'm open to suggestions on any of these points, especially the last one.

👌 Let it be 🙂

@baile320 baile320 requested a review from mgrachev September 11, 2020 12:36
@mgrachev mgrachev removed the discussion Discussion of something label Sep 11, 2020
@mgrachev mgrachev merged commit afdbf91 into dotenv-linter:master Sep 11, 2020
@mgrachev
Copy link
Member

@baile320 Thanks a lot! You're awesome! ❤️

@mgrachev mgrachev removed the request for review from DDtKey September 11, 2020 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants