-
Notifications
You must be signed in to change notification settings - Fork 1
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
Standup rota: Use people-related classes and notify them in Slack #698
Standup rota: Use people-related classes and notify them in Slack #698
Conversation
people
class and notify them in Slack
One of the advantages of using an enum over a dict is that you get editor autocompletion which is easier and less error prone than using strings for the dictionary keys |
Thanks, Jon, I wasn't aware of that. Sorry for clobbering over without prior discussion. I had the idea as I was approaching a meeting and it seemed more expedient to just get the example out in a commit and discuss in review. Speaking purely personally I find either way about as convenient. I would note that it's also a little inconvenient to have to remember to dereference the value of the enum to access the actual Specific members of the
I suppose we need to weigh up the convenience for devs of autocomplete when using particular text editors against avoiding the need to remember to add |
Sorry for taking so long on this. I've had a think about your comment and I agree that dereferencing the value is inconvenient and error prone. I've knocked up this draft which I think incorporates perhaps the best of both worlds, I'd love to hear your thoughts. |
This will make it easier to read and see the changes in subsequent commits.
This allows access to richer information about people. This enables a later commit in the same PR to use `get_formatted_slack_username`. They're split up to keep the change per-commit small.
A function that has as its only parameter an instance of a certain class is effectively a method of that class, and making that explicit is slightly clearer.
I don't think Enum is the best structure for accessing a set of instances. Enum are typically used where you don't care about the actual value, and just want to restrict the names used. An example given in the Python docs: ``` class Color(Enum): RED = 1 GREEN = 2 BLUE = 3 ``` We do care about the Person object referenced. Enums are not normal Python classes and have special properties and behaviours we don't rely on. Defining a simple class with static attributes avoids the need to dereference `.value` in various places and risks of complications from using Enum where it isn't strictly needed. We can also make `get_person_from_github_username` a method of People rather than a module-level function that relates to People.
This is a slightly richer class for defining data in code and can help editors like VSCode with type hints and with type checking tools.
81be38c
to
2364b31
Compare
@Jongmassey, thanks for this. My dict-based attempt was quite messy. I like your use of I think the main benefit you want to see from using I've tried rebasing to another attempt taking several of your improvements but subclassing |
I've made People iterable as we discussed this morning on that basis you're off on AL for a few days :) |
aeb17ff
to
c8b7e7b
Compare
This is to allow `for person in People` or similar to work. Now `People.all` is not required. Add ordering to the dataclass to allow the iterator to be sorted for a consistent ordering. Note that changing `TEAM_REX` affects `DependabotRotaReporter`. This might help avoid change happening without this linkage being noticed.
b3614a3
to
6ad2681
Compare
`PersonCollection.__init__()` populates `human_readable` based on attribute value if not set explicitly. This occurs when the class definition is read. This avoids the need to explicitly specify it for most people, when it's mostly duplicative of the attribute value, for example MIKE => Mike. Cases where the attempted conversion doesn't give the result we want can still be manually specified in the definition of `People`. For example, with "BEN_BC" it's not easy to determine programatically that all of the second word should be capitalized, so we specify explicitly as "Ben BC".
Doing it in the metaclass at `People`-definition-time is slightly clearer and more efficient than calculating and caching it the first time it's accessed.
6ad2681
to
6b3aa19
Compare
I've made commits to use a metaclass for the iterator and to populate human readable from the attribute name rather than needing to specify it manually (except for special cases like BEN_BC that can't easily be converted). Ready for another review. |
Fixes #695.
This uses the new people-related data structures and allows users to be named by Slack username in the
standup daily monday
repo, @-ing them in Slack. I tested this in the test Slack workspace (temporarily changing my own slack username locally as the username string is different per workspace apparently).I don't think the
DependabotRotaReporter
class is suitable for this report as that cycles through a list of candidates and reports one of them each week, whereas the standup rota reports 6 people in a certain order each week, with the ordering alternating between "even" and "odd" weeks.Also some changes to the class and test design that are hopefully beneficial, see individual commit messages.