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

Refactoring the way formatters are loaded to make easy to include custom formatter #451

Closed
emilio2hd opened this issue Oct 22, 2023 · 5 comments

Comments

@emilio2hd
Copy link
Contributor

emilio2hd commented Oct 22, 2023

Context

I was talking with a friend once about how pronto can create a huge noise adding too many comments on github, when a PR is big.
By the time, we're discussing how other tool was nice posting the comments as github annotation leaving the comments just for developers.
So, I've thought how it would be nice if pronto could do the same thing.

Workaround

Investigating the code, I noticed that the json formatter wouldn't be enough. I ended up creating this (not yet released) gem pronto-annotations_formatter, which produces a json to be consumed by pronto-annotate-action.
I wasn't happy because I had to do some Monkeypatch stuff to modify the Pronto::Formatter::FORMATTERS, which I think it's really dangerous, but it was the only way I could think.

One could argue "you could've just used a rake task". Well, yeah but I want to shared this solution because more people could benefit from it, and I think nothing is better than a Gem to share this.

Refactoring

After analysing the code again, I thought on how Devise loads its strategies. The same pattern could be applied to formatter.
I branched out the repo and implemented the pattern.
Please check the PR #450.

Now, with this solution I don't need to use Monkeypatch in my Gem, I just need to do:

module Pronto
  module Formatter
    class MyCustomFormatter < Pronto::Formatter::Base
      def format(messages, _repo, _patches)
        # Do stuff
      end
    end
  end
end

Pronto::Formatter.add('mycustom', Pronto::Formatter::MyCustomFormatter)
@ashkulz
Copy link
Member

ashkulz commented Oct 27, 2023

@emilio2hd please let me know if you want me to make a release for the above tools to depend on -- I'd be eager to try it at $WORK as well 😁

@emilio2hd emilio2hd changed the title Refator the way formatters are loaded to make easy to include custom formatter Refactoring the way formatters are loaded to make easy to include custom formatter Oct 27, 2023
@emilio2hd
Copy link
Contributor Author

Hey @ashkulz yahoo! Let's do it!
Thank you!

@ashkulz
Copy link
Member

ashkulz commented Oct 30, 2023

@emilio2hd pronto 0.11.2 released to RubyGems 🎉

@ashkulz
Copy link
Member

ashkulz commented Oct 30, 2023

@emilio2hd I'm looking forward to you updating pronto-annotations_formatter to remove the monkey patch 👍

@emilio2hd
Copy link
Contributor Author

@ashkulz Done! released latest version removing the monkey patch 🎉

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

No branches or pull requests

2 participants