chdsbd / kodiak

🔮 A bot to automatically update and merge GitHub PRs
https://kodiakhq.com
GNU Affero General Public License v3.0
1.03k stars 65 forks source link

feature: option to remove separator as part of cutting body #770

Closed jbergstroem closed 2 years ago

jbergstroem commented 2 years ago

When using cut body before or after, there should be an option to include removing the separator from said result.

At my company we take parts of the PR body, validate it with commitlint and if ok, tell kodiak to use it for body. We use the markdown hr separator to split what we want in the commit body and what we can keep in the PR body (---). Right now, if I use cut_body_after, it keeps the separator:

Original body

Here's a body

---

And here's the footer

Expected output

Here's a body

Actual output

Here's a body

---

I would like to suggest an option that toggles the removal of the separator as part of cutting the body.

Also, perhaps something that removes extra newlines (1 empty newline between title, body and footer seems to be the norm)?

chdsbd commented 2 years ago

This seems like a simple change to make.

We'd need to add a new configuration option and then update this code:

https://github.com/chdsbd/kodiak/blob/852e3450af4b67467c405b8dd37a07a051e0bef5/bot/kodiak/evaluation.py#L81-L88

I'm not sure what the new configuration option should be called. Maybe merge.message.cut_body_and_text

jbergstroem commented 2 years ago

I'm not sure what the new configuration option should be called. Maybe merge.message.cut_body_and_text

I have a PR almost done, used the name strip_separator: (True|False). I chose to not refactor the code (I think we can redo how its calculated), lmk what you think in a bit - happy to change name.

Edit: renamed per your suggestion.

jbergstroem commented 2 years ago

FYI, ran into issues updating the config schema:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/opt/python@3.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/jbergstroem/wrk/oss/kodiak/bot/kodiak/cli.py", line 9, in <module>
    from kodiak import app_config as conf
  File "/Users/jbergstroem/wrk/oss/kodiak/bot/kodiak/app_config.py", line 39, in <module>
    "REDISCLOUD_URL", cast=databases.DatabaseURL
  File "/Users/jbergstroem/wrk/oss/kodiak/bot/kodiak/app_config.py", line 32, in __call__
    return super().get(key, cast=cast, default=default)  # type: ignore [arg-type]
  File "/Users/jbergstroem/wrk/oss/kodiak/bot/.venv/lib/python3.7/site-packages/starlette/config.py", line 72, in get
    raise KeyError(f"Config '{key}' is missing, and has no default.")
KeyError: "Config 'REDISCLOUD_URL' is missing, and has no default."
sbdchd commented 2 years ago

I think you need to cp example.env .env to get the default env vars to work

jbergstroem commented 2 years ago

I think you need to cp example.env .env to get the default env vars to work

Ah, right. Will give it a go.

In case anyone else runs into this:

  1. copy example.env to .env
  2. create an empty file – your-app-name.some-date.private-key.pem – expected to exist via GITHUB_PRIVATE_KEY_PATH
  3. (re)generate the schema as normal