Answer prose round 1: 0 🔴, 9 🟡 (0 misread); say DM throughout, untangle the notifier's help, error and README lines, and sort the new README bullets
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Sends a direct message from a Mattermost bot to one user, through Mattermost's REST API v4. `notifier` picks it where a project's config names `mattermost`."""
|
||||
"""Sends a direct message from a Mattermost bot to one user, through Mattermost's REST API v4. The `notifier` setting `mattermost` picks it."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import urllib.parse
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Sends a notice through the notifier that a project's config names."""
|
||||
"""Sends a DM through the notifier that a project's config names."""
|
||||
import dataclasses
|
||||
import pathlib
|
||||
import typing
|
||||
@@ -16,7 +16,7 @@ Sender = typing.Callable[[str], Failure | None]
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Backend:
|
||||
"""A notifier's three parts. `read_config` returns whatever `send` takes as its config."""
|
||||
"""What one notifier needs: `read_config` reads its credentials from an env file, and returns whatever `send` takes as its config; `send` posts a message with them through `http`; `keys` are the env file's keys."""
|
||||
read_config: typing.Callable[[pathlib.Path], typing.Any]
|
||||
send: typing.Callable[[typing.Any, str, Http], Failure | None]
|
||||
http: Http
|
||||
@@ -33,7 +33,7 @@ assert tuple(BACKENDS) == NOTIFIERS
|
||||
def sender_of(project: ProjectConfig, http: Http | None = None) -> Sender | Failure:
|
||||
"""A sender through the project's notifier, with the credentials in its env file read; http replaces the backend's own. A Failure where the project names no notifier or its env file cannot be used."""
|
||||
if project.notifier is None or project.env_file is None:
|
||||
return Failure(f"{project.folder / 'config.toml'} sets no `{NOTIFIER}`; set it to one of {', '.join(NOTIFIERS)}, and `env-file` to the file that holds its keys: mattermost needs {', '.join(BACKENDS['mattermost'].keys)}, slack needs {', '.join(BACKENDS['slack'].keys)}")
|
||||
return Failure(f"{project.folder / 'config.toml'} sets no `{NOTIFIER}`; set `notifier` to {' or '.join(NOTIFIERS)}, and `env-file` to the file that holds that service's keys ({'; '.join(f'{name}: {', '.join(backend.keys)}' for name, backend in BACKENDS.items())})")
|
||||
backend = BACKENDS[project.notifier]
|
||||
config = backend.read_config(project.env_file)
|
||||
if isinstance(config, Failure):
|
||||
@@ -44,7 +44,7 @@ def sender_of(project: ProjectConfig, http: Http | None = None) -> Sender | Fail
|
||||
def notify(text: str, directory: str | None, home: pathlib.Path, http: Http | None = None) -> Failure | None:
|
||||
"""Sends text through the notifier of the project whose checkout holds directory.
|
||||
|
||||
It is skipped where the config names no notifier, since the project hasn't asked for notices. It is skipped too where no config can be read: loop-claude has stopped with that reason, and without a config there is no notifier to ask."""
|
||||
The DM is skipped where the config names no notifier, since the project hasn't asked for DMs. It is skipped too where no config can be read: loop-claude has stopped with that reason, and without a config there is no notifier to ask."""
|
||||
project = located(directory, home)
|
||||
if isinstance(project, Failure) or project.notifier is None:
|
||||
return None
|
||||
|
||||
@@ -99,7 +99,7 @@ class Notify(Project):
|
||||
def test_sender_in_names_the_settings_to_add_where_the_config_names_no_notifier(self):
|
||||
failed = notify.sender_in(str(self.checkout), self.home)
|
||||
assert isinstance(failed, Failure), failed
|
||||
self.assertEqual(failed.reason, f"{self.folder / 'config.toml'} sets no `notifier`; set it to one of mattermost, slack, and `env-file` to the file that holds its keys: mattermost needs MATTERMOST_URL, MATTERMOST_TOKEN, MATTERMOST_RECIPIENT, slack needs SLACK_TOKEN, SLACK_RECIPIENT")
|
||||
self.assertEqual(failed.reason, f"{self.folder / 'config.toml'} sets no `notifier`; set `notifier` to mattermost or slack, and `env-file` to the file that holds that service's keys (mattermost: MATTERMOST_URL, MATTERMOST_TOKEN, MATTERMOST_RECIPIENT; slack: SLACK_TOKEN, SLACK_RECIPIENT)")
|
||||
|
||||
|
||||
class Main(Project):
|
||||
|
||||
@@ -36,10 +36,10 @@ a path that starts with / or ~/ and lies outside the checkout and the config's f
|
||||
"~/.claude-projects/acme-billing.env". Where it is left out, the project has no credentials file, and
|
||||
a tool that needs one fails naming the setting. It is printed with the others only where it is set.
|
||||
|
||||
`notifier` is an optional setting, "mattermost" or "slack": the service that carries loop-claude's notices
|
||||
and `notify`'s messages to the human, with the credentials in `env-file`, which it then requires; `notify
|
||||
--help` names the keys. Left out, the project gets no notices. It is printed with the others only where
|
||||
it is set.
|
||||
`notifier` is an optional setting, "mattermost" or "slack": the service that sends loop-claude's DMs and
|
||||
`notify`'s messages to the human. Setting it requires `env-file`, which holds that service's keys;
|
||||
`notify --help` names them. Left out, the project gets no DMs. It is printed with the others only where it
|
||||
is set.
|
||||
|
||||
`wait-for-approval` is an optional setting, true or false: whether `chunk-pr merge` waits for a human's
|
||||
approval of the pull request, as its branch protection requires on GitHub, before it merges. Left out, it is
|
||||
@@ -89,8 +89,9 @@ The chunk for the issue ABC-123 is then on the branch ABC-123, in the worktree <
|
||||
and its commits and pull request are titled "ABC-123 - …".
|
||||
|
||||
Exit 1, naming each fault on stderr, where no config names the checkout, or its config leaves out a
|
||||
setting, names an unknown one, misspells a path, a language or a template, names a notifier that is neither mattermost nor slack or sets one without `env-file`, sets `wait-for-approval` or
|
||||
`tooling-on-host` to anything but true or false, or sets `readability-floor` to anything but a number
|
||||
setting, names an unknown one, misspells a path, a language or a template, sets `wait-for-approval` or
|
||||
`tooling-on-host` to anything but true or false, sets `notifier` to anything but mattermost or slack or
|
||||
without `env-file`, or sets `readability-floor` to anything but a number
|
||||
from 1 to 10, and where `env-file` or `notifier` is asked for and not set. No path setting has a default.
|
||||
"""
|
||||
import pathlib
|
||||
|
||||
@@ -19,7 +19,7 @@ SETTINGS = ("plan", "working-rules", "decisions", "score-anchors", "comprehensio
|
||||
SPELLING = '"checkout:<path>" for a path in the checkout, "folder:<path>" for one in the config\'s folder, or a path that starts with / or ~/'
|
||||
# A path setting a project may leave out: the file of KEY=value credentials its tools read. It has no default either: a project without it asks for no credentials, and never reads another project's.
|
||||
ENV_FILE = "env-file"
|
||||
# An optional setting: the service that carries the loop's notices to the human, one of NOTIFIERS. A project that names none gets no notices, so a client's env file for Jira credentials is never read for a chat token. It needs `env-file`, which holds the notifier's credentials.
|
||||
# An optional setting: the service that sends the loop's DMs to the human, one of NOTIFIERS. A project that names none gets no DMs, so a client's env file of Jira credentials is never read for a chat token.
|
||||
NOTIFIER = "notifier"
|
||||
NOTIFIERS = ("mattermost", "slack")
|
||||
# An optional boolean setting: whether `chunk-pr merge` waits for a human's approval of the pull request. False where left out.
|
||||
|
||||
@@ -19,7 +19,7 @@ class NoRedirect(urllib.request.HTTPRedirectHandler):
|
||||
return None
|
||||
|
||||
|
||||
# Sends a request: method, url, token and the body as JSON where there is one. It answers the JSON, or a Failure saying why there is none.
|
||||
# Sends a request: method, url, token and the body as JSON where there is one. It returns the JSON answer, or a Failure saying why there is none.
|
||||
Http = typing.Callable[[str, str, str, object], object]
|
||||
|
||||
OPENER = urllib.request.build_opener(NoRedirect)
|
||||
|
||||
Reference in New Issue
Block a user