@@ -1831,6 +1831,170 @@ layer("GitHubPullRequestCli.layer", (it) => {
18311831 } ) ,
18321832 ) ;
18331833
1834+ it . effect . each ( [ "merge" , "enable-auto-merge" ] as const ) (
1835+ "removes agent credits from the proposed message for %s" ,
1836+ ( action ) =>
1837+ Effect . gen ( function * ( ) {
1838+ mockedExecute
1839+ . mockReturnValueOnce (
1840+ Effect . succeed (
1841+ output (
1842+ encodeJson ( {
1843+ data : {
1844+ repository : {
1845+ pullRequest : {
1846+ isMergeQueueEnabled : false ,
1847+ headRefOid : "abc123" ,
1848+ viewerMergeBodyText :
1849+ "Details\n\nCo-authored-by: Alice <[email protected] >\nCo-authored-by: Claude <[email protected] >" , 1850+ } ,
1851+ } ,
1852+ } ,
1853+ } ) ,
1854+ ) ,
1855+ ) ,
1856+ )
1857+ . mockReturnValueOnce ( Effect . succeed ( output ( "" ) ) ) ;
1858+ const cli = yield * GitHubPullRequestCli . GitHubPullRequestCli ;
1859+ yield * cli . runPullRequestAction ( {
1860+ cwd : "/w" ,
1861+ repository : "acme/web" ,
1862+ host : "github.com" ,
1863+ number : 7 ,
1864+ action,
1865+ mergeMethod : "squash" ,
1866+ removeAgentCreditsOnMerge : true ,
1867+ } ) ;
1868+ expect ( callAt ( 0 ) . args ) . toContain ( "method=SQUASH" ) ;
1869+ expect ( callAt ( 1 ) . args . slice ( - 2 ) ) . toEqual ( [ "--body-file" , "-" ] ) ;
1870+ expect ( callAt ( 1 ) . args ) . toContain ( "--match-head-commit" ) ;
1871+ expect ( callAt ( 1 ) . args ) . toContain ( "abc123" ) ;
1872+ expect ( callAt ( 1 ) . stdin ) . toBe ( "Details\n\nCo-authored-by: Alice <[email protected] >" ) ; 1873+ expect ( callAt ( 1 ) . args . join ( " " ) ) . not . toContain ( "[email protected] " ) ; 1874+ } ) ,
1875+ ) ;
1876+
1877+ it . effect . each ( [
1878+ {
1879+ description : "an unchanged message" ,
1880+ body :
"Details\n\nCo-authored-by: Alice <[email protected] >" , 1881+ queued : false ,
1882+ } ,
1883+ {
1884+ description : "a merge queue" ,
1885+ body :
"Co-authored-by: Claude <[email protected] >" , 1886+ queued : true ,
1887+ } ,
1888+ ] as const ) ( "keeps GitHub's default message for $description" , ( { body, queued } ) =>
1889+ Effect . gen ( function * ( ) {
1890+ mockedExecute
1891+ . mockReturnValueOnce (
1892+ Effect . succeed (
1893+ output (
1894+ encodeJson ( {
1895+ data : {
1896+ repository : {
1897+ pullRequest : {
1898+ isMergeQueueEnabled : queued ,
1899+ headRefOid : "abc123" ,
1900+ viewerMergeBodyText : body ,
1901+ } ,
1902+ } ,
1903+ } ,
1904+ } ) ,
1905+ ) ,
1906+ ) ,
1907+ )
1908+ . mockReturnValueOnce ( Effect . succeed ( output ( "" ) ) ) ;
1909+ const cli = yield * GitHubPullRequestCli . GitHubPullRequestCli ;
1910+ yield * cli . runPullRequestAction ( {
1911+ cwd : "/w" ,
1912+ repository : "acme/web" ,
1913+ host : "github.com" ,
1914+ number : 7 ,
1915+ action : "merge" ,
1916+ removeAgentCreditsOnMerge : true ,
1917+ } ) ;
1918+ expect ( callAt ( 0 ) . args ) . toContain ( "method=MERGE" ) ;
1919+ expect ( callAt ( 1 ) . args ) . not . toContain ( "--body-file" ) ;
1920+ expect ( callAt ( 1 ) . stdin ) . toBeUndefined ( ) ;
1921+ } ) ,
1922+ ) ;
1923+
1924+ it . effect ( "passes an explicitly empty body when the proposed message only credits an agent" , ( ) =>
1925+ Effect . gen ( function * ( ) {
1926+ mockedExecute
1927+ . mockReturnValueOnce (
1928+ Effect . succeed (
1929+ output (
1930+ encodeJson ( {
1931+ data : {
1932+ repository : {
1933+ pullRequest : {
1934+ isMergeQueueEnabled : false ,
1935+ headRefOid : "abc123" ,
1936+ viewerMergeBodyText :
"Co-authored-by: Claude <[email protected] >" , 1937+ } ,
1938+ } ,
1939+ } ,
1940+ } ) ,
1941+ ) ,
1942+ ) ,
1943+ )
1944+ . mockReturnValueOnce ( Effect . succeed ( output ( "" ) ) ) ;
1945+ const cli = yield * GitHubPullRequestCli . GitHubPullRequestCli ;
1946+ yield * cli . runPullRequestAction ( {
1947+ cwd : "/w" ,
1948+ repository : "acme/web" ,
1949+ host : "github.com" ,
1950+ number : 7 ,
1951+ action : "merge" ,
1952+ removeAgentCreditsOnMerge : true ,
1953+ } ) ;
1954+ expect ( callAt ( 1 ) . stdin ) . toBe ( "" ) ;
1955+ expect ( callAt ( 1 ) . args ) . toContain ( "--body-file" ) ;
1956+ } ) ,
1957+ ) ;
1958+
1959+ it . effect ( "does not fetch a message for rebase merges" , ( ) =>
1960+ Effect . gen ( function * ( ) {
1961+ mockedExecute . mockReturnValue ( Effect . succeed ( output ( "" ) ) ) ;
1962+ const cli = yield * GitHubPullRequestCli . GitHubPullRequestCli ;
1963+ yield * cli . runPullRequestAction ( {
1964+ cwd : "/w" ,
1965+ repository : "acme/web" ,
1966+ host : "github.com" ,
1967+ number : 7 ,
1968+ action : "merge" ,
1969+ mergeMethod : "rebase" ,
1970+ removeAgentCreditsOnMerge : true ,
1971+ } ) ;
1972+ expect ( mockedExecute ) . toHaveBeenCalledTimes ( 1 ) ;
1973+ expect ( callAt ( 0 ) . args ) . toContain ( "--rebase" ) ;
1974+ } ) ,
1975+ ) ;
1976+
1977+ it . effect ( "refuses to merge when the proposed message cannot be read" , ( ) =>
1978+ Effect . gen ( function * ( ) {
1979+ mockedExecute . mockReturnValue (
1980+ Effect . succeed ( output ( '{"data":{"repository":{"pullRequest":null}}}' ) ) ,
1981+ ) ;
1982+ const cli = yield * GitHubPullRequestCli . GitHubPullRequestCli ;
1983+ const result = yield * Effect . result (
1984+ cli . runPullRequestAction ( {
1985+ cwd : "/w" ,
1986+ repository : "acme/web" ,
1987+ host : "github.com" ,
1988+ number : 7 ,
1989+ action : "merge" ,
1990+ removeAgentCreditsOnMerge : true ,
1991+ } ) ,
1992+ ) ;
1993+ expect ( result . _tag ) . toBe ( "Failure" ) ;
1994+ expect ( mockedExecute ) . toHaveBeenCalledTimes ( 1 ) ;
1995+ } ) ,
1996+ ) ;
1997+
18341998 it . effect ( "arms auto-merge with the same strategy a merge would have used" , ( ) =>
18351999 Effect . gen ( function * ( ) {
18362000 mockedExecute . mockReturnValue ( Effect . succeed ( output ( "" ) ) ) ;
0 commit comments