@@ -1655,7 +1655,7 @@ func Test_createRun(t *testing.T) {
16551655 expectedOut : "https://github.com/OWNER/REPO/pull/12\n " ,
16561656 },
16571657 {
1658- name : "if reviewer contains any team, fetch teams " ,
1658+ name : "fetch org teams non-interactively if reviewer contains any team" ,
16591659 setup : func (opts * CreateOptions , t * testing.T ) func () {
16601660 opts .TitleProvided = true
16611661 opts .BodyProvided = true
@@ -1718,7 +1718,7 @@ func Test_createRun(t *testing.T) {
17181718 expectedErrOut : "" ,
17191719 },
17201720 {
1721- name : "if reviewer does NOT contain any team, do NOT fetch teams " ,
1721+ name : "do not fetch org teams non-interactively if reviewer does not contain any team" ,
17221722 setup : func (opts * CreateOptions , t * testing.T ) func () {
17231723 opts .TitleProvided = true
17241724 opts .BodyProvided = true
@@ -1773,6 +1773,130 @@ func Test_createRun(t *testing.T) {
17731773 expectedOut : "https://github.com/OWNER/REPO/pull/12\n " ,
17741774 expectedErrOut : "" ,
17751775 },
1776+ {
1777+ name : "fetch org teams interactively if reviewer metadata selected" ,
1778+ tty : true ,
1779+ setup : func (opts * CreateOptions , t * testing.T ) func () {
1780+ // In order to test additional metadata, title and body cannot be provided here.
1781+ opts .HeadBranch = "feature"
1782+ return func () {}
1783+ },
1784+ cmdStubs : func (cs * run.CommandStubber ) {
1785+ // Stub git commits for `initDefaultTitleBody` when initializing PR state.
1786+ cs .Register (
1787+ "git -c log.ShowSignature=false log --pretty=format:%H%x00%s%x00%b%x00 --cherry origin/master...feature" ,
1788+ 0 ,
1789+ "3a9b48085046d156c5acce8f3b3a0532cd706a4a\u0000 first commit of pr\u0000 first commit description\u0000 \n " ,
1790+ )
1791+ cs .Register (`git rev-parse --show-toplevel` , 0 , "" )
1792+ },
1793+ promptStubs : func (pm * prompter.PrompterMock ) {
1794+ firstConfirmSubmission := true
1795+ pm .InputFunc = func (message , defaultValue string ) (string , error ) {
1796+ switch message {
1797+ case "Title (required)" :
1798+ return "TITLE" , nil
1799+ default :
1800+ return "" , fmt .Errorf ("unexpected input prompt: %s" , message )
1801+ }
1802+ }
1803+ pm .MarkdownEditorFunc = func (message , defaultValue string , allowEmpty bool ) (string , error ) {
1804+ switch message {
1805+ case "Body" :
1806+ return "BODY" , nil
1807+ default :
1808+ return "" , fmt .Errorf ("unexpected markdown editor prompt: %s" , message )
1809+ }
1810+ }
1811+ pm .MultiSelectFunc = func (message string , defaults []string , options []string ) ([]int , error ) {
1812+ switch message {
1813+ case "What would you like to add?" :
1814+ return prompter .IndexesFor (options , "Reviewers" )
1815+ case "Reviewers" :
1816+ return prompter .IndexesFor (options , "MonaLisa (Mona Display Name)" , "OWNER/core" )
1817+ default :
1818+ return nil , fmt .Errorf ("unexpected multi-select prompt: %s" , message )
1819+ }
1820+ }
1821+ pm .SelectFunc = func (message , defaultValue string , options []string ) (int , error ) {
1822+ switch message {
1823+ case "Where should we push the 'feature' branch?" :
1824+ return 0 , nil
1825+ case "What's next?" :
1826+ if firstConfirmSubmission {
1827+ firstConfirmSubmission = false
1828+ return prompter .IndexFor (options , "Add metadata" )
1829+ }
1830+ return prompter .IndexFor (options , "Submit" )
1831+ default :
1832+ return 0 , fmt .Errorf ("unexpected select prompt: %s" , message )
1833+ }
1834+ }
1835+ },
1836+ httpStubs : func (reg * httpmock.Registry , t * testing.T ) {
1837+ reg .Register (
1838+ httpmock .GraphQL (`query UserCurrent\b` ),
1839+ httpmock .StringResponse (`{"data": {"viewer": {"login": "OWNER"} } }` ))
1840+ reg .Register (
1841+ httpmock .GraphQL (`query PullRequestTemplates\b` ),
1842+ httpmock .StringResponse (`{ "data": { "repository": { "pullRequestTemplates": [] } } }` ),
1843+ )
1844+ reg .Register (
1845+ httpmock .GraphQL (`query RepositoryAssignableUsers\b` ),
1846+ httpmock .StringResponse (`
1847+ { "data": { "repository": { "assignableUsers": {
1848+ "nodes": [
1849+ { "login": "hubot", "id": "HUBOTID", "name": "" },
1850+ { "login": "MonaLisa", "id": "MONAID", "name": "Mona Display Name" }
1851+ ],
1852+ "pageInfo": { "hasNextPage": false }
1853+ } } } }
1854+ ` ))
1855+ reg .Register (
1856+ httpmock .GraphQL (`query OrganizationTeamList\b` ),
1857+ httpmock .StringResponse (`
1858+ { "data": { "organization": { "teams": {
1859+ "nodes": [
1860+ { "slug": "core", "id": "COREID" },
1861+ { "slug": "robots", "id": "ROBOTID" }
1862+ ],
1863+ "pageInfo": { "hasNextPage": false }
1864+ } } } }
1865+ ` ))
1866+ reg .Register (
1867+ httpmock .GraphQL (`mutation PullRequestCreate\b` ),
1868+ httpmock .GraphQLMutation (`
1869+ { "data": { "createPullRequest": { "pullRequest": {
1870+ "id": "NEWPULLID",
1871+ "URL": "https://github.com/OWNER/REPO/pull/12"
1872+ } } } }
1873+ ` ,
1874+ func (inputs map [string ]interface {}) {
1875+ assert .Equal (t , "TITLE" , inputs ["title" ])
1876+ assert .Equal (t , "BODY" , inputs ["body" ])
1877+ if v , ok := inputs ["assigneeIds" ]; ok {
1878+ t .Errorf ("did not expect assigneeIds: %v" , v )
1879+ }
1880+ if v , ok := inputs ["userIds" ]; ok {
1881+ t .Errorf ("did not expect userIds: %v" , v )
1882+ }
1883+ }))
1884+ reg .Register (
1885+ httpmock .GraphQL (`mutation PullRequestCreateRequestReviews\b` ),
1886+ httpmock .GraphQLMutation (`
1887+ { "data": { "requestReviews": {
1888+ "clientMutationId": ""
1889+ } } }
1890+ ` , func (inputs map [string ]interface {}) {
1891+ assert .Equal (t , "NEWPULLID" , inputs ["pullRequestId" ])
1892+ assert .Equal (t , []interface {}{"COREID" }, inputs ["teamIds" ])
1893+ assert .Equal (t , []interface {}{"MONAID" }, inputs ["userIds" ])
1894+ assert .Equal (t , true , inputs ["union" ])
1895+ }))
1896+ },
1897+ expectedOut : "https://github.com/OWNER/REPO/pull/12\n " ,
1898+ expectedErrOut : "\n Creating pull request for feature into master in OWNER/REPO\n \n " ,
1899+ },
17761900 }
17771901 for _ , tt := range tests {
17781902 t .Run (tt .name , func (t * testing.T ) {
0 commit comments