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
diff --git a/olsjenkaas/commands.py b/olsjenkaas/commands.py
index 971843a..b07563f 100644
--- a/olsjenkaas/commands.py
+++ b/olsjenkaas/commands.py
@@ -531,8 +531,13 @@ class LandApprovedProposal(CommandWithContainer):
531531
532 def land_proposal(self, proposal, target_url):532 def land_proposal(self, proposal, target_url):
533 """533 """
534 Land a proposal (validate, merge, run landing tests, push upstream).534 Lands a proposal by performing the necessary steps including validation,
535 Returns 0 if successful, otherwise 1.535 merging, running tests, pushing merged branch, and updating the proposal status.
536
537 :param proposal: The proposal to land. See https://api.launchpad.net/devel.html#branch_merge_proposal
538 for data structure.
539 :param target_url: The URL of the merge target.
540 :return: 0 if the proposal was successfully landed, 1 if it failed or was rejected.
536 """541 """
537542
538 logger.info("Trying to land {}".format(proposal.web_link))543 logger.info("Trying to land {}".format(proposal.web_link))
@@ -542,6 +547,8 @@ class LandApprovedProposal(CommandWithContainer):
542 raise Rejected("A commit message must be set.")547 raise Rejected("A commit message must be set.")
543 if not launchpad.is_approved(proposal, self.target):548 if not launchpad.is_approved(proposal, self.target):
544 raise Rejected("Voting criteria not met.")549 raise Rejected("Voting criteria not met.")
550 if not launchpad.all_dependencies_merged(proposal):
551 raise Rejected("A dependent proposal is still not merged.")
545552
546 # prepare merge target553 # prepare merge target
547 local_work_dir = os.path.realpath(self.options.work_dir)554 local_work_dir = os.path.realpath(self.options.work_dir)
diff --git a/olsjenkaas/launchpad.py b/olsjenkaas/launchpad.py
index 0f3d653..68f941e 100644
--- a/olsjenkaas/launchpad.py
+++ b/olsjenkaas/launchpad.py
@@ -104,3 +104,44 @@ def is_approved(proposal, target):
104 votes['Needs Information'] == 0)):104 votes['Needs Information'] == 0)):
105 approved = True105 approved = True
106 return approved106 return approved
107
108
109def get_dependencies(proposal):
110 """
111 Get all dependencies of the proposal.
112
113 :param proposal: The proposal with dependencies to fetch. See https://api.launchpad.net/devel.html#branch_merge_proposal
114 for data structure.
115 :return: A list of all dependencies
116 """
117
118 if not proposal.prerequisite_git_repository:
119 return []
120
121 # search all merge proposals of the parent git repository
122 # find candidates where MP source (identity) matches the
123 # original proposal's prerequisite
124 prerequisites = (
125 mp
126 for mp in proposal.target_git_repository.getMergeProposals()
127 if mp.source_git_path
128 and mp.source_git_path == proposal.prerequisite_git_path
129 )
130
131 return prerequisites
132
133
134def all_dependencies_merged(proposal):
135 """
136 Checks if all dependencies of a proposal have been merged.
137
138 :param proposal: The proposal with dependencies to check. See https://api.launchpad.net/devel.html#branch_merge_proposal
139 for data structure.
140 :return: True if all dependencies are merged, False otherwise.
141 """
142
143 for dependency in get_dependencies(proposal):
144 if dependency.queue_status != 'Merged':
145 return False
146
147 return True

Subscribers

People subscribed via source and target branches