@@ -2012,6 +2012,40 @@ def _convert_diff_document(self, document):
20122012 new_doc = self ._conv_to_dict (document )
20132013 return new_doc
20142014
2015+ def apply (self ,
2016+ before_version ,
2017+ after_version ,
2018+ branch = None ,
2019+ message = None ,
2020+ author = None ):
2021+ """Diff two different commits and apply changes on branch
2022+
2023+ Parameters
2024+ ----------
2025+ before_version : string
2026+ Before branch/commit to compare
2027+ after_object : string
2028+ After branch/commit to compare
2029+ branch : string
2030+ Branch to apply to. Optional.
2031+ """
2032+ self ._check_connection ()
2033+ branch = branch if branch else self .branch
2034+ return json .loads (
2035+ _finish_response (
2036+ requests .post (
2037+ self ._apply_url (branch = branch ),
2038+ headers = self ._default_headers ,
2039+ json = {
2040+ "commit_info" : self ._generate_commit (message , author ),
2041+ "before_commit" : before_version ,
2042+ "after_commit" : after_version ,
2043+ },
2044+ auth = self ._auth (),
2045+ )
2046+ )
2047+ )
2048+
20152049 def diff_object (self , before_object , after_object ):
20162050 """Diff two different objects.
20172051
@@ -2836,14 +2870,16 @@ def _branch_url(self, branch_id: str):
28362870 def _repo_base (self , action : str ):
28372871 return self ._db_base (action ) + f"/{ self ._repo } "
28382872
2839- def _branch_base (self , action : str ):
2873+ def _branch_base (self , action : str , branch : Optional [ str ] = None ):
28402874 base = self ._repo_base (action )
28412875 if self ._repo == "_meta" :
28422876 return base
28432877 if self ._branch == "_commits" :
28442878 return base + f"/{ self ._branch } "
28452879 elif self .ref :
28462880 return base + f"/commit/{ self ._ref } "
2881+ elif branch :
2882+ return base + f"/branch/{ branch } "
28472883 else :
28482884 return base + f"/branch/{ self ._branch } "
28492885 return base
@@ -2916,6 +2952,9 @@ def _squash_url(self):
29162952 def _diff_url (self ):
29172953 return self ._branch_base ("diff" )
29182954
2955+ def _apply_url (self , branch : Optional [str ] = None ):
2956+ return self ._branch_base ("apply" , branch )
2957+
29192958 def _patch_url (self ):
29202959 return self ._branch_base ("patch" )
29212960
0 commit comments