semantic-release icon indicating copy to clipboard operation
semantic-release copied to clipboard

feature request: provide context to plugins

Open superewald opened this issue 9 months ago • 0 comments

Providing a context to the plugins would be useful to reduce code duplicates and maintainability of the plugins itself.

motivation

I'm currently writing a hook plugin which automates the distribution of release assets and publishing packages. That requires some information which are currently only available in the root config (which plugins by default have no access to) and initializing clients for github/gitlab myself. This produces alot of "duplicate" code (since the config and providers are initialized by semantic-release before) and is somehow a bit error prone.

(You can take a look into https://github.com/superewald/semantic-release-hooks-distributor for reference, it's not finished but shows clearly why a context would be useful)

proposal

In order to make it easier for plugins to access resources which are already initialized by semantic-release a context should be passed to the plugin. I would suggest the context should provide the following resources to the plugin:

  • root config (to access options which are out of the plugin scope) https://github.com/go-semantic-release/semantic-release/blob/c2f6a1730a89a96c8d389a3e1f84b9b0fb07f9eb/cmd/semantic-release/main.go#L85
  • provider plugin (to access the initialized clients for gitlab/github/...) https://github.com/go-semantic-release/semantic-release/blob/c2f6a1730a89a96c8d389a3e1f84b9b0fb07f9eb/cmd/semantic-release/main.go#L129
  • plugin manager or list of plugins (to check if dependant plugins are installed)

considerations

  • which plugins would benefit of such context (I assume it is only relevant to hook plugins)
  • how to pass the context to the plugin (obviously it would be needed at the Init but is there a nice way to add the context and maybe keep backwards compatibility ?)

I would be happy to implement this feature but beforehands I want to know if it would be integrated and need to have the considerations answered.

superewald avatar Oct 05 '23 12:10 superewald