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

Standup rota: Use people-related classes and notify them in Slack #698

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mikerkelly
Copy link
Contributor

@mikerkelly mikerkelly commented Jan 15, 2025

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.

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. I find the syntax for `Enum` a
bit unintuitive and unreadable too, `People.MIKE` was not `Person('Mike',
...)`, but rather a `Person` object with `name=="MIKE"` and
`value==Person('Mike', ...)`. Enums are more common in languages like
C/C++/Java where they allow the compiler to do microoptimization but I don't
think that's relevant here.

This allows us to make `get_person_from_github_username` a method of
`PeopleDict` rather than a module-level method and `PEOPLE_BY_GITHUB_USERNAME`
constant. It's not possible to do that kind of class-construction-time
calculation as pre-indexing the dict with an Enum.

It also avoids the need for accessing `.value` everywhere, which was less
readable (e.g., was `checker.value.get_formatted_slack_username()` now
`checker.get_formatted_slack_username()`).

This also allows us to write tests of `people.py` that don't rely on the
specific real `People` Enum, but rather test a testing-only `PeopleDict` (next
commit).
This separates testing the classes from the actual team members' data, and
makes changing the latter easier without randomly breaking these tests of the
general functionality.

It also makes it clearer what the tests are actually testing (see next commit
which will break them up based on which class they are testing.
…orter`, to avoid it happening without this being noticed.
@mikerkelly mikerkelly changed the title Standup rota: Use people class and notify them in Slack Standup rota: Use people-related classes and notify them in Slack Jan 15, 2025
@Jongmassey
Copy link
Contributor

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

@mikerkelly
Copy link
Contributor Author

mikerkelly commented Jan 16, 2025

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 Person object, which I had to remember to do manually a few times while developing this ticket and spent maybe a minute or two the first time confused about why People.XXX didn't have attributes I was adding to Person and understanding that I needed to use People.XXX.value.human_readable, for example. It's also a bit inconvenient to have to type the Person's name twice in two different formats when adding someone new to the list.

Specific members of the Enum are only accessed a few times in the code. I can see it could be much more convenient to have autocomplete in a different use case for Enum where it was used much more widely in the code, and the name was significant but the value was not. Note that the last couple of lines below don't exist anymore if we take up the change to test_people.py from 4f004cd to make it use test data rather than the real data. So it would only be a couple of instances at present.

workspace/dependabot/jobs.py:        candidates = [r for r in TEAM_REX if r != People.KATIE]
tests/workspace/test_dependabot_rota.py:TEAM_REX = [People.JON, People.LUCY, People.KATIE]
tests/workspace/test_people.py:    assert result == People.LUCY.value
tests/workspace/test_people.py:    result = get_formatted_slack_username(People.LUCY.value)

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 .value to People.XXX; convenience when adding users; being able to test the people.py classes more directly and with test data rather than the real People; and being able to make get_person_from_github_username a class method. Happy to discuss, or just revert if you feel strongly.

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

Successfully merging this pull request may close these issues.

Refactor Team REX Standup Rota
2 participants