← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ines-almeida/launchpad:merge-button/add-merge-type-model into launchpad:master

 

Ines Almeida has proposed merging ~ines-almeida/launchpad:merge-button/add-merge-type-model into launchpad:master with ~ines-almeida/launchpad:update-is-mergeable as a prerequisite.

Commit message:
Add `merge_type` to BranchMergeProposal model
    
This will allow keeping track of merges done via Launchpad's API and UI, and which strategies were used (initially we will only allow REGULAR_MERGE)

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ines-almeida/launchpad/+git/launchpad/+merge/486009

Add value to model to be used for the merge API functionality (MP to come next)
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ines-almeida/launchpad:merge-button/add-merge-type-model into launchpad:master.
diff --git a/lib/lp/code/enums.py b/lib/lp/code/enums.py
index 93392af..a1912dc 100644
--- a/lib/lp/code/enums.py
+++ b/lib/lp/code/enums.py
@@ -27,6 +27,7 @@ __all__ = [
     "GitPermissionType",
     "GitRepositoryStatus",
     "GitRepositoryType",
+    "MergeType",
     "NON_CVS_RCS_TYPES",
     "RevisionControlSystems",
     "RevisionStatusArtifactType",
@@ -644,6 +645,32 @@ class BranchMergeProposalStatus(DBEnumeratedType):
     )
 
 
+class MergeType(DBEnumeratedType):
+    """Merge Proposal Merge Type.
+
+    The types of merges a merge proposal can be merged as using Launchpad's
+    API and UI.
+    """
+
+    UNKNOWN = DBItem(
+        0,
+        """
+        Unknown
+
+        Either unmerged or manually merged.
+        """,
+    )
+
+    REGULAR_MERGE = DBItem(
+        1,
+        """
+        Regular merge.
+
+        Default merge with a merge commit.
+        """,
+    )
+
+
 class BranchSubscriptionDiffSize(DBEnumeratedType):
     """Branch Subscription Diff Size
 
diff --git a/lib/lp/code/interfaces/branchmergeproposal.py b/lib/lp/code/interfaces/branchmergeproposal.py
index 90f23c3..4de6d3a 100644
--- a/lib/lp/code/interfaces/branchmergeproposal.py
+++ b/lib/lp/code/interfaces/branchmergeproposal.py
@@ -56,7 +56,7 @@ from zope.schema import (
 from lp import _
 from lp.app.interfaces.launchpad import IPrivacy
 from lp.bugs.interfaces.buglink import IBugLinkTarget
-from lp.code.enums import BranchMergeProposalStatus, CodeReviewVote
+from lp.code.enums import BranchMergeProposalStatus, CodeReviewVote, MergeType
 from lp.code.interfaces.branch import IBranch
 from lp.code.interfaces.diff import IPreviewDiff
 from lp.code.interfaces.gitref import IGitRef
@@ -269,6 +269,13 @@ class IBranchMergeProposalPublic(IPrivacy):
         "The branch that the source branch branched from (VCS-agnostic)."
     )
 
+    merge_type = Choice(
+        title=_("Merge type"),
+        vocabulary=MergeType,
+        required=True,
+        readonly=True,
+    )
+
     parent = Attribute(
         "The parent object for use in navigation: source branch for Bazaar, "
         "or source repository for Git."
diff --git a/lib/lp/code/model/branchmergeproposal.py b/lib/lp/code/model/branchmergeproposal.py
index 17168fe..0396b59 100644
--- a/lib/lp/code/model/branchmergeproposal.py
+++ b/lib/lp/code/model/branchmergeproposal.py
@@ -38,6 +38,7 @@ from lp.code.enums import (
     BranchSubscriptionNotificationLevel,
     CodeReviewNotificationLevel,
     CodeReviewVote,
+    MergeType,
 )
 from lp.code.errors import (
     BadBranchMergeProposalSearchContext,
@@ -218,6 +219,10 @@ class BranchMergeProposal(StormBase, BugLinkTargetMixin):
         name="dependent_git_commit_sha1", default=None, allow_none=True
     )
 
+    merge_type = DBEnum(
+        enum=MergeType, allow_none=False, default=MergeType.UNKNOWN
+    )
+
     @property
     def source_git_ref(self):
         if self.source_git_repository is None:
@@ -890,6 +895,7 @@ class BranchMergeProposal(StormBase, BugLinkTargetMixin):
         merged_revision_id=None,
         date_merged=None,
         merge_reporter=None,
+        merge_type=MergeType.UNKNOWN,
     ):
         """See `IBranchMergeProposal`."""
         old_state = self.queue_status
@@ -899,6 +905,7 @@ class BranchMergeProposal(StormBase, BugLinkTargetMixin):
         self.merged_revno = merged_revno
         self.merged_revision_id = merged_revision_id
         self.merge_reporter = merge_reporter
+        self.merge_type = merge_type
 
         # The reviewer of a merged proposal is assumed to have approved, if
         # they rejected it remove the review metadata to avoid confusion.
diff --git a/lib/lp/code/model/tests/test_branchmergeproposal.py b/lib/lp/code/model/tests/test_branchmergeproposal.py
index 6118d71..e1ef1eb 100644
--- a/lib/lp/code/model/tests/test_branchmergeproposal.py
+++ b/lib/lp/code/model/tests/test_branchmergeproposal.py
@@ -35,6 +35,7 @@ from lp.code.enums import (
     BranchSubscriptionNotificationLevel,
     CodeReviewNotificationLevel,
     CodeReviewVote,
+    MergeType,
 )
 from lp.code.errors import (
     BadStateTransition,
@@ -544,6 +545,7 @@ class TestBranchMergeProposalSetStatus(TestCaseWithFactory):
             proposal.queue_status, BranchMergeProposalStatus.MERGED
         )
         self.assertEqual(proposal.merged_revision_id, "1000")
+        self.assertEqual(proposal.merge_type, MergeType.UNKNOWN)
 
     def test_set_status_invalid_status(self):
         # IBranchMergeProposal.setStatus doesn't work in the case of

Follow ups