Merge ~lofidevops/ols-jenkaas:sn1780-mergebot-dependent-branches into ols-jenkaas:main

Proposed by David
Status: Work in progress
Proposed branch: ~lofidevops/ols-jenkaas:sn1780-mergebot-dependent-branches
Merge into: ols-jenkaas:main
Diff against target: 78 lines (+50/-2)
2 files modified
olsjenkaas/commands.py (+9/-2)
olsjenkaas/launchpad.py (+41/-0)
Reviewer Review Type Date Requested Status
Maximiliano Bertacchini Approve
Emma Brostrom (community) Needs Information
Review via email: mp+463204@code.launchpad.net

Commit message

Add check for merged dependencies before landing a proposal. Fixes SN-1780.

Description of the change

All dependencies of a given proposal must be merged. If not, do not merge.

This will prevent developers accidentally merging proposals with pending dependencies.

To post a comment you must log in.
Revision history for this message
Emma Brostrom (emmabrostrom) wrote :

Thanks for this David, looks great! I wanted to mention one thing - this approach is only inclusive of git repositories, and some of ours are bzr. I think you'll want to add some logic that takes into account bzr proposals. Here is an example of what that logic could look like: https://git.launchpad.net/tarmac/tree/tarmac/bin/commands.py#n357. I haven't thought too much about the implementation, but it could look like using the LandBzrProposal and LandGitProposal subclasses of LandApprovedProposals.

Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

This is great!! But I don't really understand the matching logic, check below. Sorry!
Thanks

145457a... by David

Use Sphinx formatting.

Signed-off-by: David Seaward <email address hidden>

4986524... by David

Refactor dependency logic.

Signed-off-by: David Seaward <email address hidden>

Revision history for this message
David (lofidevops) wrote :

Responded.

Revision history for this message
David (lofidevops) wrote :

Just a comment to confirm that we decided not to support bzr.

4a4822c... by David

Fix selection logic for prerequisite proposals. Use generator rather than list.

Signed-off-by: David Seaward <email address hidden>

Revision history for this message
Emma Brostrom (emmabrostrom) wrote :

Thanks for the updates David! I had a few questions below. Also as far as testing goes - you could create your own repo, similar to what I did for pre-merge CI:https://code.launchpad.net/~ubuntuone-hackers/golem/+git/golem-tests. Or just use that one honestly. But you can use that to create some MPs with dependencies and test it out with lp-shell.

review: Needs Information
Revision history for this message
David (lofidevops) :
aaa94e1... by David

Fix prerequisite logic to use the correct fields. Add comment.

Signed-off-by: David Seaward <email address hidden>

Revision history for this message
Emma Brostrom (emmabrostrom) wrote :

Thanks David! A few nitpicks/ one question.

review: Needs Information
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

one comment regarding getMergeProposals

Revision history for this message
Emma Brostrom (emmabrostrom) wrote :

Did a quick test using lp-shell - see comment below

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

> Did a quick test using lp-shell - see comment below

I see 3 in https://code.launchpad.net/~ubuntuone-pqm-team/golem/+git/golem/+ref/main/+activereviews but one is a WIP one.

Could you check if the 3 you get in lp-shell have different status?

Revision history for this message
Emma Brostrom (emmabrostrom) wrote :

Updated paste: https://pastebin.canonical.com/p/x5VTxJsFYV/

Work in progress is considered an active review. The 3 MPs found from repo.getMergeProposals() are the ones from active review. I don't believe a "Merged" MP would be returned from this.

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

> Updated paste: https://pastebin.canonical.com/p/x5VTxJsFYV/
>
> Work in progress is considered an active review. The 3 MPs found from
> repo.getMergeProposals() are the ones from active review. I don't believe a
> "Merged" MP would be returned from this.

Indeed, merged ones need to be explicitly requested.

Thanks for checking!

Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

Looks great to me! +1 provided all relevant comments/suggestions are addressed/replied. Thanks

review: Approve
Revision history for this message
Emma Brostrom (emmabrostrom) :

Unmerged commits

aaa94e1... by David

Fix prerequisite logic to use the correct fields. Add comment.

Signed-off-by: David Seaward <email address hidden>

4a4822c... by David

Fix selection logic for prerequisite proposals. Use generator rather than list.

Signed-off-by: David Seaward <email address hidden>

4986524... by David

Refactor dependency logic.

Signed-off-by: David Seaward <email address hidden>

145457a... by David

Use Sphinx formatting.

Signed-off-by: David Seaward <email address hidden>

8157455... by David

Add check for merged dependencies before landing a proposal.

Signed-off-by: David Seaward <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/olsjenkaas/commands.py b/olsjenkaas/commands.py
2index 971843a..b07563f 100644
3--- a/olsjenkaas/commands.py
4+++ b/olsjenkaas/commands.py
5@@ -531,8 +531,13 @@ class LandApprovedProposal(CommandWithContainer):
6
7 def land_proposal(self, proposal, target_url):
8 """
9- Land a proposal (validate, merge, run landing tests, push upstream).
10- Returns 0 if successful, otherwise 1.
11+ Lands a proposal by performing the necessary steps including validation,
12+ merging, running tests, pushing merged branch, and updating the proposal status.
13+
14+ :param proposal: The proposal to land. See https://api.launchpad.net/devel.html#branch_merge_proposal
15+ for data structure.
16+ :param target_url: The URL of the merge target.
17+ :return: 0 if the proposal was successfully landed, 1 if it failed or was rejected.
18 """
19
20 logger.info("Trying to land {}".format(proposal.web_link))
21@@ -542,6 +547,8 @@ class LandApprovedProposal(CommandWithContainer):
22 raise Rejected("A commit message must be set.")
23 if not launchpad.is_approved(proposal, self.target):
24 raise Rejected("Voting criteria not met.")
25+ if not launchpad.all_dependencies_merged(proposal):
26+ raise Rejected("A dependent proposal is still not merged.")
27
28 # prepare merge target
29 local_work_dir = os.path.realpath(self.options.work_dir)
30diff --git a/olsjenkaas/launchpad.py b/olsjenkaas/launchpad.py
31index 0f3d653..68f941e 100644
32--- a/olsjenkaas/launchpad.py
33+++ b/olsjenkaas/launchpad.py
34@@ -104,3 +104,44 @@ def is_approved(proposal, target):
35 votes['Needs Information'] == 0)):
36 approved = True
37 return approved
38+
39+
40+def get_dependencies(proposal):
41+ """
42+ Get all dependencies of the proposal.
43+
44+ :param proposal: The proposal with dependencies to fetch. See https://api.launchpad.net/devel.html#branch_merge_proposal
45+ for data structure.
46+ :return: A list of all dependencies
47+ """
48+
49+ if not proposal.prerequisite_git_repository:
50+ return []
51+
52+ # search all merge proposals of the parent git repository
53+ # find candidates where MP source (identity) matches the
54+ # original proposal's prerequisite
55+ prerequisites = (
56+ mp
57+ for mp in proposal.target_git_repository.getMergeProposals()
58+ if mp.source_git_path
59+ and mp.source_git_path == proposal.prerequisite_git_path
60+ )
61+
62+ return prerequisites
63+
64+
65+def all_dependencies_merged(proposal):
66+ """
67+ Checks if all dependencies of a proposal have been merged.
68+
69+ :param proposal: The proposal with dependencies to check. See https://api.launchpad.net/devel.html#branch_merge_proposal
70+ for data structure.
71+ :return: True if all dependencies are merged, False otherwise.
72+ """
73+
74+ for dependency in get_dependencies(proposal):
75+ if dependency.queue_status != 'Merged':
76+ return False
77+
78+ return True

Subscribers

People subscribed via source and target branches