Commit Graph

2043 Commits

Author SHA1 Message Date
Xavier Morel
4fa93266c6 [IMP] *: remove dead imports 2025-02-28 16:12:40 +01:00
Xavier Morel
9d2638e653 [FIX] runbot_merge: don't show unreceive optional statuses
... by default. Optional statuses we haven't at least received a
`pending` for are irrelevant to the PR's state, so should remain
hidden.

This subtetly was missed when fixing #1062

Fixes #1066
2025-02-28 16:12:40 +01:00
Xavier Morel
50568cfcc6 [IMP] runbot_merge: convert staging.statuses to namedtuples
As they're mostly used in views after all, and views don't support
tuple unpacking, having to index into a 4-uple is a bit of a pain.
2025-02-28 16:12:40 +01:00
Xavier Morel
f172dff6ab [IMP] runbot_merge: un-magic a bunch of color adjustments
- Adjust background colors via CSS variables instead of manual CSS
  rules.
- Reset table background rules to use "normal" background colors
  instead of bootstrap's bespoke thing.
- Change bg-unmerged to interpolate between "info" and "success"
  background colors (in LAB it seems to yield the colors we originally
  had hardcoded).
- Partially soft-code the alter-primary bg color adjustment. The
  saturation and lightness changes are kinda arbitrary but it's now
  based on the primary at least...
2025-02-26 12:55:23 +01:00
Martin Trigaux (mat)
ccfff33d56 [IMP] runbot_merge: latest patches first 2025-02-25 15:34:34 +01:00
Martin Trigaux (mat)
a2b27abef1 [ADD] runbot_merge: create controller to merge a commit
This used to be done in RPC but the goal is to be able to call this from
another server and not rely on a user account.
2025-02-25 15:34:34 +01:00
Xavier Morel
e6057afde7 [FIX] runbot_merge: handle missing patch commits
Commits can take some time to propagate through the network (I guess),
or human error can lead to the wrong commit being set.

Either way, because the entire thing was done using a single fetch in
`check=True` the cron job would fail entirely if any of the patch
commits was yet unavailable.

Update the updater to:

- fallback on individual fetches
- remove the patch from the set of applicable patch if we (still)
  can't find its commit

I'd have hoped `fetch` could retrieve whatever it found, but
apparently the server just crashes out when it doesn't find the commit
we ask for, and `fetch` doesn't update anything.

No linked issue because I apparently forgot to jot it down (and only
remembered about this issue with the #1063 patching issue) but this
was reported by mat last week (2025-02-21) when they were wondering
why one of their patches was taking a while:

- At 0832 patch was created by automated script.
- At 0947, an attempt to apply was made, the commit was not found.
- At 1126, a second attempt was made but an other patch had been
  created whose commit was not found, failing both.
- At 1255, there was a concurrency error ("cannot lock ref" on the
  target branch).
- Finally at 1427 the patch was applied.

All in all it took 6 hours to apply the patch, which is 3-4 staging
cycles.
2025-02-25 14:38:15 +01:00
Xavier Morel
5d08b79550 [IMP] runbot_merge: replace show --pretty=%H by rev-list -1
It's shorter, it's simpler (kinda), and it's 70% faster (although
that's unlikely to be any sort of bottleneck given applying patches
involves multiple network roundtrips).
2025-02-25 11:53:39 +01:00
Xavier Morel
157fec3492 [FIX] runbot_merge: reject patches yielding empty commits
Verify that the tree is different before and after applying the patch,
otherwise if there's a mistake made (e.g. a script does not check that
they have content and request a patch applying an existing commit
which is how odoo/enterprise#612a9cf3cadba64e4b18d535ca0ac7e3f4429a08
occurred) we end up with a completely empty commit and a duplicated
commit message.

Fixes #1063

Note: using `rev-parse` to retrieve the commit's tree would be 50%
faster, but we're talking 3.2 versus 2.4ms and it requires string
formatting instead of nice clean arguments so it's a bit meh.
2025-02-25 11:51:22 +01:00
Xavier Morel
abf1298b1d [IMP] runbot_merge: add optional statuses on PRs
If a status is defined as `optional`, then the PR is considered valid
if the status is never sent, but *if* the status is sent then it
becomes required.

Note that as ever this is a per-commit requirement, so it's mostly
useful for conditional statuses.

Fixes #1062
2025-02-25 09:50:45 +01:00
Xavier Morel
98bb01edfc [ADD] runbot_merge, tests: opentelemetry support
Mostly for tests: it can be really difficult to correlate issues as
there are 3 different processes involved (the test runner, the odoo
being tested, and dummy-central (as github)) and the intermixing of
logs between the test driver and the odoo being tested is
not *amazing*.

- `pytest-opentelemetry`'s `--export-traces` is the signal for running
  tests with tracing enabled, that way just having
  `pytest-opentelemetry` installed does not do anything untowards.
- Until chrisguidry/pytest-opentelemetry#34 is merged, should probably
  use the linked branch as the default / base mode of having a single
  trace for the entire test suite is not great when there are 460
  tests, especially as local clients (opentelemetry-desktop-viewer,
  venator) mostly work on traces and aren't very good at zooming on
  *spans* at least currently.
- Additionally, the conftest plugin adds hooks for propagating through
  the xmlrpc client (communications with odoo) and enables the
  requests instrumentor from the opentelemetry python contribs.
- The dummy `saas_worker` was moved into the filesystem, that makes it
  easier to review and update.
- A second such module was added for the otel instrumentation *of the
  odoo under test*, that instruments psycopg2, requests, wsgi, and the
  server side of xmlrpc.
- The git ops were instrumented directly in runbot_merge, as I've
  tried to keep `saas_tracing` relatively generic, in case it could be
  moved to community or used by internal eventually.

Some typing was added to the conftest hooks and fixtures, and they
were migrated from tmpdir (py.path) to tmp_path (pathlib) for
consistency, even though technically the `mkdir` of pathlib is an
annoying downgrade.

Fixes #835
2025-02-24 15:43:11 +01:00
Xavier Morel
93a52b5f43 [FIX] forwardport: type error
`groupby` returns an iterator of `(key, list[value])`, not a
recordset. So `BaseModel.__or__` is invalid.

I missed that bit because I didn't bother writing a test where a PR
has more than 6 months and triggers generating / sending emails, but
turns out we do have those in the production database, and as a result
the mergebot hasn't sent an outstanding fw notification since I
deployed 892fce4ddf in early
february (oops).

Thanks to @clbr-odoo for the notification / report of the issue.
2025-02-24 15:41:45 +01:00
xmo-odoo
d9b2441549
Critical commands fix 2025-02-20 14:24:25 +01:00
Xavier-Do
49c9314d3a [IMP] mergebot: improve command line 2025-02-20 14:06:47 +01:00
Xavier Morel
d8c2782d1f [IMP] runbot_merge: add cron trigger button
"Run manually" is a bit meh, as it runs the cron synchronously (so you
have to wait for it, and hope it doesn't run for longer than the
request timeout which may be smaller than the cron timeout) and it can
run in a subtly different environment than normal, which can lead to
different behaviour.

Instead add a button to enqueue a cron trigger, now that they exist
that's much closer to what we actually want, and it does run the cron
in a normal / expected environment.
2025-02-18 11:45:56 +01:00
Xavier Morel
e19a9fad8f [REM] forwardport: re-enablement of forward ports when closing wizard
This can yield odd effects when playing around e.g. opening freeze
wizards then cancelling them. There is a check that there are no
wizards left, but if a freeze is performed then an other is created
and cancelled it will immediately re-enable forward ports,
unexpectedly.
2025-02-18 11:45:56 +01:00
Xavier Morel
b765bb8446 [FIX] forwardport: a source may be unmerged
Since forever, if a PR gets added to an existing forward ported batch
it will be forward ported immediately, leading to a forwardport having
a source with no merge date.

Since the addition of the skipmerge feature, it's even more possible
than before.

As a result, the `outstanding` listing should not assume the
merge_date of a source is always set.
2025-02-18 11:45:56 +01:00
Xavier Morel
905b0e0de4 [ADD] forwardport: test on resuming fw by hand
Hit issues where this didn't seem to work after deactivating 17.2 and
trying to recover from the autoport being broken (see previous
commits), but apparently this says everything works just fine so
╮( ̄▽ ̄"")╭

Fixes #1052
2025-02-14 13:38:21 +01:00
Xavier Morel
79116fc850 [FIX] forwardport: duplicate batch completion
In the case where multiple batch completions are triggered (see 3
commits earlier) one of the issues is that the "already ported" check
is incorrect, as it checks the (source, target) pair against the PR
used to trigger the completion check. That PR *should* be the one PR
which was just added to a batch, but if one of its descendants is used
to re-trigger a port then the dupe check fails and we try to port the
thing again.

Remember to deref' the subject's source in order to perform the dupe
check, as well as set the source for the forwardport we create.

Fixes #1052
2025-02-14 09:31:09 +01:00
Xavier Morel
8a931adeac [IMP] forwardport: better fw batch failure notification
When an fw batch fails, log a message to its chatter (so the reason
for the failure doesn't necessarily have to be hunted down in the
logs, although depending on the quality of the error that might still
be an issue).

Also if a batch keeps failing (fails for more than a day at a retry
every hour -- increased from a previous 30mn), stop retrying it and
flag it in the list view, it's clearly not going to go through.

This is because we hit an issue with a completion fw batch created on
January 27th which kept failing until it was deleted on February
10th. Thankfully it failed on `git push` and git operations apparently
are not rate limited at all, but still it's not great stewartship to
keep trying a forwardport which keeps failing. Retrying in case of
transient failure makes sense, but after 24 attempts over a day it's
either not transient, or it's not working because github is down and
hammering it won't help.
2025-02-13 14:26:50 +01:00
Xavier Morel
5bdeb04df2 [FIX] runbot_merge: disable autosave on boolean toggles
That's a bit of a weird one: apparently the boolean_toggle widget has
an `autosave` option which should be `true` by default, effecting the
row as soon as the toggle is toggled[^1]. But in 15.0 and 18.0 it
seems to have no effect, the `boolean_toggle` always just stores the
change in the parent form and that gets "committed on save.

In 16.0 and 17.0 however it does have an effect, toggling the control
will immediately save its value *without going through the parent
form*, resulting in the override to `Project.write` managing
new/existing branches to not be called, thus not calling
`Project_followup_prs`, and ultimately not creating the followup
forward ports.

After contacting AAB to get more info (and grepping a bit):

- autosave was added (enabled by default) in 16.0 after the owl
  rewrite (odoo/odoo@28e6b7eb83)
- toggle was added in 17.0
  (odoo/odoo@a449b05221)
- feature was removed in 18.0
  (odoo/odoo@6bd2c1fdfb)

Which explains why the issue occurs in 16.0 and 17.0, and not in 15.0
or 18.0.

Fixes #1051

[^1]: but apparently not going through the parent form...
2025-02-12 14:28:18 +01:00
Xavier Morel
0dd11acce8 [FIX] *: double forwardport when adding a PR to an existing batch
This is a bit of an odd case which was only noticed because of
persistent forwardport.batches, which ended up having a ton of related
traceback in the logs (the mergebot kept trying to create forward
ports from Jan 27th to Feb 10th, thankfully the errors happened in git
so did not seem to eat through our API rate limiting).

The issue was triggered by the addition of odoo/enterprise#77876 to
odoo/odoo#194818. This triggered a completion job which led to the
creation of odoo/enterprise#77877 to odoo/enterprise#77880, so far so
good.

Except the bit of code responsible for creating completion jobs only
checked if the PR was being added to a batch with a descendant. That
is the case of odoo/enterprise#77877 to odoo/enterprise#77879 (not
odoo/enterprise#77880 because that's the end of the line). As a
result, those triggered 3 more completion jobs, which kept failing in
a loop because they tried pushing different commits to their
next-siblings (without forcing, leading git to reject the non-ff push,
hurray).

A completion request should only be triggered by the addition of a
new *source* (a PR without a source) to an existing batch with
descendants, so add that to the check. This requires updating
`_from_json` to create PRs in a single step (rather than one step to
create based on github's data, and an other one for the hierarchical
tracking) as we need the source to be set during `create` not as a
post-action.

Although there was a test which could have triggered this issue, the
test only had 3 branches so was not long enough to trigger the issue:

- Initial PR 1 on branch A merged then forward-ported to B and C.
- Sibling PR 2 added to the batch in B.
- Completed to C.
- Ending there as C(1) has no descendant batch, leading to no further
  completion request.

Adding a 4th branch did surface / show the issue by providing space
for a new completion request from the creation of C(2). Interestingly
even though I the test harness attempts to run all triggered crons to
completion there can be misses, so the test can fail in two different
ways (being now checked for):

- there's a leftover forwardport.batch after we've created all our
  forwardports
- there's an extra PR targeting D, descending from C(2)
- in almost every case there's also a traceback in the logs, which
  does fail the build thanks to the `env` fixture's check
2025-02-11 14:27:53 +01:00
Xavier Morel
6d8f9d9fb0 [IMP] forwardport: batch push on updates
Looks like `--force-with-lease` can work in multi-head updates, and
this should allow just one push per repository for the entire sequence
of update, then commit the entire thing if it succeeds.
2025-02-06 15:43:01 +01:00
Xavier Morel
e3b4d2bb40 [IMP] *: cleanup status contexts in tests
For historical reasons pretty much all tests used to use the contexts
legal/cla and ci/runbot. While there are a few tests where we need the
interactions of multiple contexts and that makes sense, on the vast
majority of tests that's just extra traffic and noise in the
test (from needing to send multiple statuses unnecessarily).

In fact on the average PR where everything passes by default we could
even remove the required statuses entirely...
2025-02-06 14:55:28 +01:00
Xavier Morel
6d5c539c77 [IMP] *: fork with main_branch_only
Should limit the risk of cases where the fork contains outdated
versions of the reference branches and we end up with odd outdated /
not up to date basis for branches & updates, which can lead to
confusing situations.
2025-02-06 12:41:03 +01:00
Xavier Morel
3b0e59a3cd [IMP] conftest: fstring-ify repo forking
Also use the fork's response for the fork's own URL instead of
composing it by hand.
2025-02-06 12:41:03 +01:00
Xavier Morel
e065206f79 [IMP] conftest: minor cleanups to repo creation
- Use f-strings where appropriate.
- Get the repo url from github instead of composing it by hand
- Resolve URI template for the contents endpoint instead of
  hand-building the URL. URI template implementation is janky AF.
2025-02-06 12:40:54 +01:00
Xavier Morel
88453aa462 [FIX] conftest: assert tunnel response is a proper URL
Since the tunnel value is now a path to a script to run (and get the
public facing address out of), it's pretty easy to give the path to
the wrong program e.g. `--tunnel ngrok` will run ngrok itself, which
is going to yield an error message and do nothing, and then break when
we try to use the nonsensical result (e.g. an empty string or an error
message) as a URL.

So assert that the result does parse as a URL-ish with at least a
scheme and netloc.
2025-02-04 08:16:31 +01:00
Xavier Morel
c67bb64537 [ADD] *: fw=skipmerge
Skipmerge creates forward-ports before the source PR is even merged.

- In a break from the norm, skipmerge will create forwardports even in
  the face of conflicts.
- It will also not *detach* pull requests in case of conflicts, this
  is so the source PR can be updated and the update correctly cascades
  through the stack (likewise for any intermediate PR though *that*
  will detach as usual).

Note that this doesn't really look at outstandings, especially as they
were recently updated, so it might need to be fixed up in case of
freakout, but I feel like that should not be too much of an issue, the
authors will just get their FW reminders earlier than usual. If that's
a hassle we can always update the reminder job to ignore forward ports
whose source is not merged I guess.

Fixes #418
2025-02-04 08:05:15 +01:00
Xavier Morel
12ac32e169 [IMP] forwardport: avoid a full scan when we just want a boolean
There should only be 1 PR with a given parent at most anyway, but
still if it's a boolean we can stop at the first occurrence if any. pg
might even be able to do something more efficient in that case.
2025-02-03 15:14:08 +01:00
Xavier Morel
981760430c [IMP] *: cleanup dead locals 2025-02-03 15:13:49 +01:00
Xavier Morel
9fa106f277 [FIX] runbot_merge: squash update on ignored PR events
Apparently when I updated the logic of the lookup to that of search I
forgot to update the *method* to `search`.
2025-02-03 08:03:08 +01:00
Xavier Morel
d7da328b9f [IMP] runbot_merge: relax requirements for setting the merge method
Not entirely sure about just allowing any PR author to set the merge
method as it gives them a lot more control over commits (via the PR
message), and I'm uncertain about the ramifications of doing that.

However if the author of the PR is classified as an
employee (via a provisioned user linked to the github account) then
allow it. Should not be prone to abuse at least.

Fixes #1036
2025-01-30 11:53:52 +01:00
Xavier Morel
1099fc5119 [IMP] runbot_merge: check squash on every PR event
All `pull_request` events seem to provide the `commits` count
property. As such we can use them all to check the `squash` state even
if we don't otherwise care for the event.

Also split out notifying an approved pull request about its missing
merge method into a separate cron from the one notifying a PR that its
siblings are ready.

Fixes #1036
2025-01-30 11:53:44 +01:00
Xavier Morel
645a10a7ca [IMP] runbot_merge: de-randomise fw/bp uniquifier
The forward port process adds a uniquifier to the branch name as it's
possible to reuse branch names for different sets of PRs (and some
individuals do that systematically) which can cause collisions in the
fw branches.

Originally this uniquifier was random by necessity, however now that
batches are reified and forward port is performed batch-wise we don't
need the randomness we can just use the source batch's id as it's
unique per sequence of forward ports. This means it'll eventually be
possible for an external system to retrieve the source(s) of a forward
port by reading the batch object, and it's also possible to correlate
forward ports through the batch id (although not possible to find the
source set without access to the mergebot's information).

Do the same thing for backports, because why not.
2025-01-30 09:57:43 +01:00
Xavier Morel
25cfaa95a5 [IMP] runbot_merge: remove team when disabling user 2025-01-29 15:39:40 +01:00
Xavier Morel
1097c5f19e [ADD] runbot_merge: support for file creation in patch
Had been left out of the original impl, but turns out it might be
useful e.g. when a new lang gets added to the i18n export.

Fixes #1042
2025-01-29 13:29:53 +01:00
Xavier Morel
54337aeccc [IMP] runbot_merge: rework (de)provisioning
- Update `get_reviewers` to returning all active users, as that makes
  more sense for the server side operations, this is now redundant
  with `list_users`, so eventually internals should be fixed and it
  removed.
- Update `remove_users` to deactivate the user as well as move it to
  portal, since the mergebot doesn't use portal keeping enabled portal
  users doesn't make much sense.
- Reorganise `provision_user` to make the update path more obvious.

Fixes #968
2025-01-28 16:11:14 +01:00
Xavier Morel
62dd3ee636 [ADD] tests: shitty support for context
The API doesn't correctly match the server-side `Environment`/`Model`
API, but neither did `with_user`, so probably fine for now, can
revisit this thing if I start needing it more than once in a blue
moon.
2025-01-28 15:53:04 +01:00
Xavier Morel
86796ed730 [FIX] runbot_merge: project fixture
Turns out this has a hard dependency on `rolemap` to ensure
`conf['github']['name']` is populated.
2025-01-28 15:13:47 +01:00
Xavier Morel
892fce4ddf [ADD] forwardport: email reminders
After 6 months of sitting unmerged, forward ports will now trigger a
monthly email.

Or would, if an email server was configured on the mergebot, but
adding this now should allow debugging its working and tracking the
generation of emails through the "Delivery Failed" collection. This
way if we ever decide to actually do the thing we can just enable an
SMTP server.

Fixes #801
2025-01-28 07:51:27 +01:00
Xavier Morel
896624674f [IMP] forwardport: show a user's outstanding tally in the main alert
Previously the alert would show the total number of outstanding
forward ports, which most people don't care about (if they're even
logged which probably isn't the case), so that was mostly useful
for... me.

Add the current user's tally to the message as well. If the user is
logged. Which is always, because the alert only shows up if the user
has read access to PRs.

Fixes #801
2025-01-24 15:54:58 +01:00
Xavier Morel
63a4916d00 [FIX] forwardport: avoid double counting PRs for teams
In the case where both author and reviewer of a PR have the same
team (which is very common e.g. self review or a team member approving
your PR) then the `outstanding_per_group` entry would be incremented
twice, leading to overcounting outstanding forward ports for the team.

Fixes #801
2025-01-24 15:20:19 +01:00
Xavier Morel
edaf507863 [IMP] runbot_merge: make space characters in regexes clearer
pycharm is a bit dumb so it considers `[ ]` to be unnecessary even in
`re.VERBOSE` regexes. But it has a bit of a point in that it's not
super clear, so inject the space characters by (unicode) name, the
behaviour should be the exact same but the regexes should be slightly
less opaque.
2025-01-24 14:53:47 +01:00
Xavier Morel
60b84490c6 [IMP] forwardport: classify FP as outstanding a week after creation
Rather than a week after *source merge*.

Fixes #801
2025-01-24 14:53:47 +01:00
Xavier Morel
942570e60a [IMP] forwardport: outstanding FP reminders
- only remind weekly initially (not daily)
- root reminders on the forward port's creation, not the source's
  merge date
- cap reminder interval at 4 weeks (instead of doubling every time)
- track reminders on forward ports, don't share between siblings
- remove `forwardport_updated_before` from the testing system, it's
  now possible to just update `reminder_next` to a past date and see
  if it gets triggered (it should to nothing on sources, or on forward
  port in a state which does not warrant concern)

Fixes #801
2025-01-24 14:53:34 +01:00
Xavier Morel
916f144163 [IMP] runbot_merge: staging form
Link stagings to the staging commits instead of the commits directly
in order to have the repository name and not need to try the commit on
every repository.

Also make the trees editable, in combination with `readonly="1"` this
does not make the trees editable but does prevent clicking on a row to
open a dialog with the linked objects, which is convenient if one
wants to copy the commit hash.
2025-01-20 16:04:02 +01:00
Xavier Morel
f3dd3e6fde [FIX] runbot_merge: make staging serialization more useful
Having the staged and merged heads via an easy to reach endpoint is
nice, but having *just* the hashes is not as it requires basically
exhaustively checking commits against repos to see which is
where. That's annoying.

Make the head serializations a map of repository to commit
hash. That's a lot more convenient.
2025-01-20 15:48:47 +01:00
Xavier Morel
f900eb68b6 [FIX] runbot_merge: my pager lied to me
Hopefully this is the last fix to the patcher. From the start of the
implementation I relied on the idea that `git show` was adding a line
composed of a single space (and a newline) before and after the patch
message, as that is what I observed in my terminal, and it's
consistent with RFC 3676 signatures (two dashes, a space, and a
newline).

Turns out that single space, while present in my terminal indeed, was
completely made up by `less(1)`. `git show` itself doesn't generate
that, neither does it appear when using most pagers, or even when
piping the output of `less` into something (a file, an other pager,
...). It's pretty much just something `less(1)` sends to a terminal
during interactive sessions to fuck with you.

Fixes #1037
2025-01-15 08:51:28 +01:00
Xavier Morel
7d5c3dcb73 [IMP] mergebot: staging endpoints
- use lingo `staged` and `merged` for clarity (instead of `heads` and
  `commits`)
- convert from json-rpc to regular HTTP to make easier to call
- add the staged and merged heads when returning staging data
- return more complete objects (rather than a list of ids) when
  matching stagings based on commits / heads

Fixes #1018
2025-01-14 15:05:03 +01:00