@@ -141,6 +141,7 @@ class PullReqState:
141
141
num = 0
142
142
priority = 0
143
143
rollup = 0
144
+ squash = False
144
145
title = ''
145
146
body = ''
146
147
head_ref = ''
@@ -347,7 +348,7 @@ def get_test_on_fork_repo(self):
347
348
def save (self ):
348
349
db_query (
349
350
self .db ,
350
- 'INSERT OR REPLACE INTO pull (repo, num, status, merge_sha, title, body, head_sha, head_ref, base_ref, assignee, approved_by, priority, try_, rollup, delegate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' , # noqa
351
+ 'INSERT OR REPLACE INTO pull (repo, num, status, merge_sha, title, body, head_sha, head_ref, base_ref, assignee, approved_by, priority, try_, rollup, squash, delegate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' , # noqa
351
352
[
352
353
self .repo_label ,
353
354
self .num ,
@@ -363,6 +364,7 @@ def save(self):
363
364
self .priority ,
364
365
self .try_ ,
365
366
self .rollup ,
367
+ self .squash ,
366
368
self .delegate ,
367
369
])
368
370
@@ -723,6 +725,20 @@ def parse_commands(body, username, user_id, repo_label, repo_cfg, state,
723
725
724
726
state .save ()
725
727
728
+ elif command .action == 'squash' :
729
+ if not _try_auth_verified ():
730
+ continue
731
+ state .squash = True
732
+
733
+ state .save ()
734
+
735
+ elif command .action == 'unsquash' :
736
+ if not _try_auth_verified ():
737
+ continue
738
+ state .squash = False
739
+
740
+ state .save ()
741
+
726
742
elif command .action == 'force' and realtime :
727
743
if not _try_auth_verified ():
728
744
continue
@@ -1005,6 +1021,29 @@ def create_merge(state, repo_cfg, branch, logger, git_cfg,
1005
1021
desc = 'Auto-squashing failed'
1006
1022
comment = ''
1007
1023
ok = False
1024
+ if state .squash :
1025
+ try :
1026
+ merge_base_sha = subprocess .check_output (
1027
+ git_cmd (
1028
+ 'merge-base' ,
1029
+ base_sha ,
1030
+ state .head_sha )).decode ('ascii' ).strip ()
1031
+ git_editor = os .environ ['GIT_EDITOR' ]
1032
+ os .environ ['GIT_EDITOR' ] = "sed -i '2,/^$/s/^pick\b /s/'"
1033
+ utils .logged_call (git_cmd (
1034
+ '-c' ,
1035
+ 'user.name=' + git_cfg ['name' ],
1036
+ '-c' ,
1037
+ 'user.email=' + git_cfg ['email' ],
1038
+ 'rebase' ,
1039
+ '-i' ,
1040
+ '--onto' ,
1041
+ merge_base_sha , base_sha ))
1042
+ os .environ ['GIT_EDITOR' ] = git_editor
1043
+ except subprocess .CalledProcessError :
1044
+ desc = 'Squashing failed'
1045
+ comment = ''
1046
+ ok = False
1008
1047
1009
1048
if ok :
1010
1049
utils .logged_call (git_cmd ('checkout' , '-B' , branch , base_sha ))
@@ -1736,6 +1775,7 @@ def main():
1736
1775
priority INTEGER,
1737
1776
try_ INTEGER,
1738
1777
rollup INTEGER,
1778
+ squash INTEGER,
1739
1779
delegate TEXT,
1740
1780
UNIQUE (repo, num)
1741
1781
)''' )
@@ -1780,6 +1820,10 @@ def main():
1780
1820
db_query (db , 'SELECT treeclosed_src FROM repos LIMIT 0' )
1781
1821
except sqlite3 .OperationalError :
1782
1822
db_query (db , 'ALTER TABLE repos ADD COLUMN treeclosed_src TEXT' )
1823
+ try :
1824
+ db_query (db , 'SELECT squash FROM pull LIMIT 0' )
1825
+ except sqlite3 .OperationalError :
1826
+ db_query (db , 'ALTER TABLE pull ADD COLUMN squash INT' )
1783
1827
1784
1828
for repo_label , repo_cfg in cfg ['repo' ].items ():
1785
1829
repo_cfgs [repo_label ] = repo_cfg
@@ -1797,9 +1841,9 @@ def main():
1797
1841
1798
1842
db_query (
1799
1843
db ,
1800
- 'SELECT num, head_sha, status, title, body, head_ref, base_ref, assignee, approved_by, priority, try_, rollup, delegate, merge_sha FROM pull WHERE repo = ?' , # noqa
1844
+ 'SELECT num, head_sha, status, title, body, head_ref, base_ref, assignee, approved_by, priority, try_, rollup, squash, delegate, merge_sha FROM pull WHERE repo = ?' , # noqa
1801
1845
[repo_label ])
1802
- for num , head_sha , status , title , body , head_ref , base_ref , assignee , approved_by , priority , try_ , rollup , delegate , merge_sha in db .fetchall (): # noqa
1846
+ for num , head_sha , status , title , body , head_ref , base_ref , assignee , approved_by , priority , try_ , rollup , squash , delegate , merge_sha in db .fetchall (): # noqa
1803
1847
state = PullReqState (num , head_sha , status , db , repo_label , mergeable_que , gh , repo_cfg ['owner' ], repo_cfg ['name' ], repo_cfg .get ('labels' , {}), repos , repo_cfg .get ('test-on-fork' )) # noqa
1804
1848
state .title = title
1805
1849
state .body = body
@@ -1811,6 +1855,7 @@ def main():
1811
1855
state .priority = int (priority )
1812
1856
state .try_ = bool (try_ )
1813
1857
state .rollup = rollup
1858
+ state .squash = bool (squash )
1814
1859
state .delegate = delegate
1815
1860
builders = []
1816
1861
if merge_sha :
0 commit comments