Skip to content

Conversation

@joemsak
Copy link
Contributor

@joemsak joemsak commented May 27, 2025

This version update addresses an issue with using CodeTeams plugins, which is that a developer must manually inline the plugin where they want to access that data in the code.

For example, if I want to use my github plugin, my production code has to look like this:

def my_method(name)
  team = CodeTeams.find(name)
  github_team = GithubPlugin.for(team).github
  foo = github_team.foo

  # do something...
end

We are proposing to extract this extra work away from the developer and provide a convenient interface that is automatically baked into the CodeTeams::Team instance:

def my_method(name)
  team = CodeTeams.find(name)
  foo = team.github.foo
  
  # do something...
end

In this PR:

  • Add RSpec binstub bin/rspec
  • Move test setup methods into shared helpers with conventional RSpec mixin / config
  • Add plugin methods to instances of CodeTeams::Team:
    • e.g., team.github for a given Github plugin
  • Maintain backwards compatibility with the "old way"
    • e.g., MyPlugin.for(team).my_plugin still works, but it has been rendered unnecessary
    • developers should upgrade to the "new way," i.e., team.my_plugin
  • Update version to 1.1.0
  • Update the README

Not much has changed about how to develop a plugin, except that the ideal way to define it is such that your plugin's data access method should match the name of the plugin class (this is a convention developers at Gusto are already using informally). There is an option to deviate from the convention by overriding the default data_accessor_name (shown below)

Note that these examples just show a simplified plugin where the method returns a static value instead of the whole ceremony of turning the raw_hash into a struct (another informal convention seen in most of the plugins at Gusto - we plan to release a major update that will standardize that as an internal implementation feature of CodeTeams::Plugin)

# Assuming a team config.yml with `my_plugin:` entry

class MyNamespace::MyPlugin < CodeTeams::Plugin
  # the convention is to have the method match the plugin's class name
  def my_plugin
    'foo'
  end
end

team = CodeTeams.find('my_team')

# the NEW way:
team.my_plugin
# => 'foo'

# VS. having to use the plugin inline manually
# the OLD way:
MyNamespace::MyPlugin.for(team).my_plugin
# => 'foo'

If you need your plugin to use a custom data_accessor_name for the data:

# Assuming a team config.yml with `foo:` entry

class Namespace::MyCustomKeyPlugin < CodeTeams::Plugin
  data_accessor_name 'foo'

  def foo
    'bar'
  end
end

team = CodeTeams.find('my_team')

team.foo
# => 'foo'

@github-project-automation github-project-automation bot moved this to Triage in Modularity May 27, 2025
@joemsak joemsak changed the title Auto plugin helpers Extract plugin ceremony into automatic convenience methods on Team instances May 28, 2025
@joemsak joemsak changed the title Extract plugin ceremony into automatic convenience methods on Team instances v1.1 - Extract plugin ceremony into automatic convenience methods on Team instances May 28, 2025
@joemsak joemsak changed the title v1.1 - Extract plugin ceremony into automatic convenience methods on Team instances v1.1.0 - Extract plugin ceremony into automatic convenience methods on Team instances May 28, 2025
@joemsak joemsak marked this pull request as ready for review May 28, 2025 21:37
Copy link
Contributor

@vburzynski vburzynski left a comment

Choose a reason for hiding this comment

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

Added a few suggestions, I'll need to finish my review tomorrow

@joemsak
Copy link
Contributor Author

joemsak commented May 29, 2025

Thank you @vburzynski for your feedback so far. I've implemented it, so please let me know if it's looking better now. Thanks!

@joemsak joemsak marked this pull request as draft May 29, 2025 16:05
Copy link
Contributor

@vburzynski vburzynski left a comment

Choose a reason for hiding this comment

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

Overall looks good to me. I think we could open this up for review

@joemsak joemsak marked this pull request as ready for review May 29, 2025 20:08
@martinemde
Copy link
Contributor

We got the build updated so it runs ruby 3.2 - 3.4.

@joemsak joemsak force-pushed the auto-plugin-helpers branch from 8971de1 to a29287e Compare June 2, 2025 21:34
@martinemde martinemde merged commit 372d337 into rubyatscale:main Jun 2, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from Triage to Done in Modularity Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants