@@ -141,6 +141,7 @@ class PullReqState:
141141 num = 0
142142 priority = 0
143143 rollup = 0
144+ squash = False
144145 title = ''
145146 body = ''
146147 head_ref = ''
@@ -347,7 +348,7 @@ def get_test_on_fork_repo(self):
347348 def save (self ):
348349 db_query (
349350 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
351352 [
352353 self .repo_label ,
353354 self .num ,
@@ -363,6 +364,7 @@ def save(self):
363364 self .priority ,
364365 self .try_ ,
365366 self .rollup ,
367+ self .squash ,
366368 self .delegate ,
367369 ])
368370
@@ -722,6 +724,20 @@ def parse_commands(body, username, user_id, repo_label, repo_cfg, state,
722724
723725 state .save ()
724726
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+
725741 elif command .action == 'force' and realtime :
726742 if not _try_auth_verified ():
727743 continue
@@ -1004,6 +1020,29 @@ def create_merge(state, repo_cfg, branch, logger, git_cfg,
10041020 desc = 'Auto-squashing failed'
10051021 comment = ''
10061022 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
10071046
10081047 if ok :
10091048 utils .logged_call (git_cmd ('checkout' , '-B' , branch , base_sha ))
@@ -1735,6 +1774,7 @@ def main():
17351774 priority INTEGER,
17361775 try_ INTEGER,
17371776 rollup INTEGER,
1777+ squash INTEGER,
17381778 delegate TEXT,
17391779 UNIQUE (repo, num)
17401780 )''' )
@@ -1779,6 +1819,10 @@ def main():
17791819 db_query (db , 'SELECT treeclosed_src FROM repos LIMIT 0' )
17801820 except sqlite3 .OperationalError :
17811821 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' )
17821826
17831827 for repo_label , repo_cfg in cfg ['repo' ].items ():
17841828 repo_cfgs [repo_label ] = repo_cfg
@@ -1796,9 +1840,9 @@ def main():
17961840
17971841 db_query (
17981842 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
18001844 [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
18021846 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
18031847 state .title = title
18041848 state .body = body
@@ -1810,6 +1854,7 @@ def main():
18101854 state .priority = int (priority )
18111855 state .try_ = bool (try_ )
18121856 state .rollup = rollup
1857+ state .squash = bool (squash )
18131858 state .delegate = delegate
18141859 builders = []
18151860 if merge_sha :
0 commit comments