parkr/auto-reply

Figure out the right way to do configuration

parkr opened this issue · 0 comments

parkr commented

Sometimes, out of laziness, I threw it in the package itself. We have a few options:

  • Add a Handler to every package which has all the fields necessary. Put all the actual event handlers on this object so it requires instantiation in order to use it
package chlog

// Just a default handler
var DefaultHandler = &Handler{} // modify me!

// then pull it into the hook handler
package main

func newJekyllHandler() *hooks.GlobalHandler {
  chlog.DefaultHandler.AddRepo("jekyll/jekyll") // or whatever, but key is you modify this package-wide handler
  return &hooks.GlobalHandler{
        Context:       newContext(),
        EventHandlers: map[hooks.EventType][]hooks.EventHandler{
          hooks.CreateEvent: {chlog.DefaultHandler.CreateReleaseOnTagHandler},
        },
    }
}
  • Do an exported variable that is an instance of the baseline Handler. The importing main package then just uses this
func newJekyllHandler() *hooks.GlobalHandler {
  chlogHandler := chlog.NewHandler()
  chlogHandler.AddRepo("jekyll/jekyll") // or whatever, but key is you make the handler
  return &hooks.GlobalHandler{
        Context:       newContext(),
        EventHandlers: map[hooks.EventType][]hooks.EventHandler{
          hooks.CreateEvent: {chlogHandler.CreateReleaseOnTagHandler},
        },
    }
}
  • Do configuration in JSON or something that offers us configuration of the handlers on a per-repo basis, like
{
  "jekyll/jekyll": {
    "lgtm": { "quorum": 2 },
    "affinity": {},
  },
  "jekyll/jekyll-help" : {
    "deprecate": {
      "message": "Hey! Thanks for your issue. We have moved..."
    }
  },
}

Then each package's Handler would be unmarshalled into a Go object and given the JSON values in the config.

Which which which?