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 code for maintainabilty #206

Merged
merged 8 commits into from
Jan 24, 2022

Conversation

neomilium
Copy link
Contributor

@neomilium neomilium commented Dec 31, 2020

This PR improves code structure to help owners to maintain the code and contributors to add features.

About the maintainability, this PR attempts to:

  • reduce code repeats (using classes to hold properties)
  • prevent from some name shadowing
  • reduce passed arguments (e.g. options were passed to many methods)
  • make rubocop happier ;-)

This PR also adds tests for bump, tag and changelog features.

To help contributors, this PR renames some methods with IMHO more explicit names and organizes code into classes.

Even msync have been made to manage Puppet modules, there are some users which use it for other purpose (e.g. @raphink wrote https://dev.to/camptocamp-ops/templating-puppet-control-repositories-3pk7) so I started to split specific code into PuppetModule class, while generic one is now in SourceCode class.

More details in commit logs.

@neomilium neomilium marked this pull request as draft December 31, 2020 15:01
@neomilium
Copy link
Contributor Author

This PR have been flagged as draft due to its dependency on #202 and #204.

@neomilium
Copy link
Contributor Author

This PR is so big... I started to split it to speed up review and merges.

@neomilium
Copy link
Contributor Author

#212 is the first part.

@ekohl I have some unexpected spare time to contribute to modulesync this day, quicker parts are merged, more will be.

neomilium added a commit to opus-codium/modulesync that referenced this pull request Apr 21, 2021
Please note that previous commit introduced some offences that will be fixed in upcomming commits (some are already available in voxpupuli#206
neomilium added a commit to opus-codium/modulesync that referenced this pull request Apr 21, 2021
Please note that previous commit introduced some offences that will be fixed in upcomming commits (some are already available in voxpupuli#206
neomilium added a commit to opus-codium/modulesync that referenced this pull request Apr 21, 2021
Please note that previous commit introduced some offences that will be fixed in upcomming commits (some are already available in voxpupuli#206
neomilium added a commit to opus-codium/modulesync that referenced this pull request Apr 21, 2021
Please note that previous commit introduced some offences that will be fixed in upcomming commits (some are already available in voxpupuli#206
@neomilium neomilium force-pushed the code-refactoring branch 2 times, most recently from 2a43a87 to 36fb210 Compare April 22, 2021 14:18
@neomilium neomilium force-pushed the code-refactoring branch 8 times, most recently from 8ae088c to 7fd4261 Compare April 27, 2021 18:06
@neomilium
Copy link
Contributor Author

This PR is stalled, waiting #219 to be merged.

@codecov
Copy link

codecov bot commented Oct 8, 2021

Codecov Report

Merging #206 (5a03a6d) into master (5b33600) will increase coverage by 1.16%.
The diff coverage is 86.84%.

❗ Current head 5a03a6d differs from pull request most recent head 627fffa. Consider uploading reports for the commit 627fffa to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #206      +/-   ##
==========================================
+ Coverage   84.76%   85.93%   +1.16%     
==========================================
  Files          30       30              
  Lines         906      917      +11     
==========================================
+ Hits          768      788      +20     
+ Misses        138      129       -9     
Impacted Files Coverage Δ
lib/modulesync/git_service.rb 70.58% <50.00%> (+16.24%) ⬆️
lib/modulesync/source_code.rb 97.50% <50.00%> (-2.50%) ⬇️
lib/modulesync/git_service/factory.rb 92.30% <80.00%> (+1.39%) ⬆️
lib/modulesync/git_service/base.rb 90.47% <90.90%> (+0.47%) ⬆️
lib/modulesync/cli.rb 100.00% <100.00%> (ø)
lib/modulesync/git_service/gitlab.rb 100.00% <100.00%> (ø)
lib/modulesync/repository.rb 93.20% <100.00%> (+0.13%) ⬆️
spec/helpers/faker/puppet_module_remote_repo.rb 87.20% <100.00%> (ø)
spec/unit/modulesync/git_service_spec.rb 100.00% <100.00%> (ø)

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 5b33600...627fffa. Read the comment docs.

@neomilium neomilium force-pushed the code-refactoring branch 4 times, most recently from cac2762 to 8c8d4ad Compare October 11, 2021 17:31
During debug, the following git error raised:
fatal: ambiguous argument 'XXX': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

With the git help recommandation the error is (a bit) more explicit:
fatal: bad revision 'XXX'
@neomilium
Copy link
Contributor Author

@neomilium neomilium marked this pull request as ready for review October 18, 2021 14:29
Copy link
Member

@smortex smortex left a comment

Choose a reason for hiding this comment

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

LGTM

@neomilium neomilium mentioned this pull request Oct 18, 2021
@@ -12,14 +12,13 @@ def self.defaults
end

class Hook < Thor
class_option :project_root,
Copy link
Member

Choose a reason for hiding this comment

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

can you explain why you drop the parameter? that means we need to do a major release?

Copy link
Contributor Author

@neomilium neomilium Oct 18, 2021

Choose a reason for hiding this comment

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

can you explain why you drop the parameter?

Yes, its not used in hook.

that means we need to do a major release?

No, I do not think so. I was just a extra parameter with no effect, AFAICS.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Overall this looks good.

Comment on lines +23 to +24
endpoint += '/api/v4'
endpoint
Copy link
Member

Choose a reason for hiding this comment

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

Another way of writing this (but I'm not sure this is clearer)

Suggested change
endpoint += '/api/v4'
endpoint
endpoint + '/api/v4'

lib/modulesync/repository.rb Show resolved Hide resolved
features/cli.feature Show resolved Hide resolved
@neomilium neomilium merged commit 3c9e406 into voxpupuli:master Jan 24, 2022
@neomilium neomilium deleted the code-refactoring branch January 24, 2022 18:02
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

Successfully merging this pull request may close these issues.

4 participants