|
18 | 18 |
|
19 | 19 | from bert_e import exceptions
|
20 | 20 | from bert_e.job import handler as job_handler
|
21 |
| -from bert_e.job import QueuesJob |
| 21 | +from bert_e.job import QueuesJob, PullRequestJob |
22 | 22 | from bert_e.lib import git
|
23 | 23 |
|
24 | 24 | from ..git_utils import clone_git_repo, consecutive_merge, robust_merge, push
|
25 | 25 | from ..pr_utils import send_comment
|
26 |
| -from .branches import (BranchCascade, DevelopmentBranch, IntegrationBranch, |
27 |
| - QueueBranch, QueueIntegrationBranch, |
28 |
| - branch_factory, build_queue_collection) |
| 26 | +from .branches import (BranchCascade, DevelopmentBranch, GWFBranch, |
| 27 | + IntegrationBranch, QueueBranch, QueueCollection, |
| 28 | + QueueIntegrationBranch, branch_factory, |
| 29 | + build_queue_collection) |
29 | 30 | from .integration import get_integration_branches
|
30 |
| - |
| 31 | +from typing import List |
31 | 32 | LOG = logging.getLogger(__name__)
|
32 | 33 |
|
33 | 34 |
|
@@ -207,3 +208,38 @@ def close_queued_pull_request(job, pr_id, cascade):
|
207 | 208 | except git.RemoveFailedException:
|
208 | 209 | # not critical
|
209 | 210 | pass
|
| 211 | + |
| 212 | + |
| 213 | +def is_needed( |
| 214 | + job: PullRequestJob, |
| 215 | + wbranches: List[GWFBranch], |
| 216 | + queues: QueueCollection | None): |
| 217 | + """Determine if queuing is required to merge the given PR. |
| 218 | +
|
| 219 | + Queuing a pull request should only be done if: |
| 220 | + - The PR or the integration branches are not up to date |
| 221 | + with the destination branch. |
| 222 | + - Other PRs are already in the queue. |
| 223 | +
|
| 224 | + Returns: |
| 225 | + - True if the PR should be queued. |
| 226 | + - False otherwise. |
| 227 | + """ |
| 228 | + |
| 229 | + if queues is None or job.settings.use_queue is False: |
| 230 | + return False |
| 231 | + |
| 232 | + if (job.settings.skip_queue_when_not_needed is False or |
| 233 | + already_in_queue(job, wbranches) or |
| 234 | + len(queues.queued_prs) > 0): |
| 235 | + return True |
| 236 | + |
| 237 | + if not job.git.src_branch.includes_commit( |
| 238 | + job.git.dst_branch.get_latest_commit()): |
| 239 | + return True |
| 240 | + # Check if the wbranches all contain the commits in the dst branches |
| 241 | + for branch, dst_branch in zip(wbranches, job.git.cascade.dst_branches): |
| 242 | + if not branch.includes_commit(dst_branch.get_latest_commit()): |
| 243 | + return True |
| 244 | + |
| 245 | + return False |
0 commit comments