@@ -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
@@ -722,6 +724,20 @@ def parse_commands(body, username, user_id, repo_label, repo_cfg, state,
722
724
723
725
state .save ()
724
726
727
+ elif command .action == 'squash' :
728
+ if not _try_auth_verified ():
729
+ continue
730
+ state .squash = True
731
+
732
+ state .save ()
733
+
734
+ elif command .action == 'unsquash' :
735
+ if not _try_auth_verified ():
736
+ continue
737
+ state .squash = False
738
+
739
+ state .save ()
740
+
725
741
elif command .action == 'force' and realtime :
726
742
if not _try_auth_verified ():
727
743
continue
@@ -1004,6 +1020,29 @@ def create_merge(state, repo_cfg, branch, logger, git_cfg,
1004
1020
desc = 'Auto-squashing failed'
1005
1021
comment = ''
1006
1022
ok = False
1023
+ if state .squash :
1024
+ try :
1025
+ merge_base_sha = subprocess .check_output (
1026
+ git_cmd (
1027
+ 'merge-base' ,
1028
+ base_sha ,
1029
+ state .head_sha )).decode ('ascii' ).strip ()
1030
+ git_editor = os .environ ['GIT_EDITOR' ]
1031
+ os .environ ['GIT_EDITOR' ] = "sed -i '2,/^$/s/^pick\b /s/'"
1032
+ utils .logged_call (git_cmd (
1033
+ '-c' ,
1034
+ 'user.name=' + git_cfg ['name' ],
1035
+ '-c' ,
1036
+ 'user.email=' + git_cfg ['email' ],
1037
+ 'rebase' ,
1038
+ '-i' ,
1039
+ '--onto' ,
1040
+ merge_base_sha , base_sha ))
1041
+ os .environ ['GIT_EDITOR' ] = git_editor
1042
+ except subprocess .CalledProcessError :
1043
+ desc = 'Squashing failed'
1044
+ comment = ''
1045
+ ok = False
1007
1046
1008
1047
if ok :
1009
1048
utils .logged_call (git_cmd ('checkout' , '-B' , branch , base_sha ))
@@ -1735,6 +1774,7 @@ def main():
1735
1774
priority INTEGER,
1736
1775
try_ INTEGER,
1737
1776
rollup INTEGER,
1777
+ squash INTEGER,
1738
1778
delegate TEXT,
1739
1779
UNIQUE (repo, num)
1740
1780
)''' )
@@ -1779,6 +1819,10 @@ def main():
1779
1819
db_query (db , 'SELECT treeclosed_src FROM repos LIMIT 0' )
1780
1820
except sqlite3 .OperationalError :
1781
1821
db_query (db , 'ALTER TABLE repos ADD COLUMN treeclosed_src TEXT' )
1822
+ try :
1823
+ db_query (db , 'SELECT squash FROM pull LIMIT 0' )
1824
+ except sqlite3 .OperationalError :
1825
+ db_query (db , 'ALTER TABLE pull ADD COLUMN squash INT' )
1782
1826
1783
1827
for repo_label , repo_cfg in cfg ['repo' ].items ():
1784
1828
repo_cfgs [repo_label ] = repo_cfg
@@ -1796,9 +1840,9 @@ def main():
1796
1840
1797
1841
db_query (
1798
1842
db ,
1799
- '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
1843
+ '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
1800
1844
[repo_label ])
1801
- for num , head_sha , status , title , body , head_ref , base_ref , assignee , approved_by , priority , try_ , rollup , delegate , merge_sha in db .fetchall (): # noqa
1845
+ 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
1802
1846
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
1803
1847
state .title = title
1804
1848
state .body = body
@@ -1810,6 +1854,7 @@ def main():
1810
1854
state .priority = int (priority )
1811
1855
state .try_ = bool (try_ )
1812
1856
state .rollup = rollup
1857
+ state .squash = bool (squash )
1813
1858
state .delegate = delegate
1814
1859
builders = []
1815
1860
if merge_sha :
0 commit comments