@@ -15,10 +15,12 @@ import {
1515 getCloneDestinationPath ,
1616 getCloneDirectoryName ,
1717 getDefaultCloneUrl ,
18- getNewProjectGitHubRepository ,
19- getNewProjectGitHubTarget ,
2018 getNewProjectPathPreview ,
19+ getNewProjectPublishTarget ,
20+ getNewProjectPublishTargets ,
21+ getNewProjectRepository ,
2122 normalizePastedCloneUrl ,
23+ parseAddProjectRemoteSource ,
2224 resolveAddProjectPath ,
2325 sortAddProjectProviderSources ,
2426 type AddProjectRemoteSource ,
@@ -48,6 +50,7 @@ import {
4850 type EnvironmentMachineKind ,
4951 ProjectId ,
5052 resolveEnvironmentMachineKind ,
53+ SourceControlProviderKind ,
5154} from "@t3tools/contracts" ;
5255import { CommonActions , StackActions , useNavigation } from "@react-navigation/native" ;
5356import { SymbolView } from "../../components/AppSymbol" ;
@@ -70,6 +73,7 @@ import { AppText as Text, AppTextInput as TextInput } from "../../components/App
7073import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol" ;
7174import { ErrorBanner } from "../../components/ErrorBanner" ;
7275import { SourceControlIcon } from "../../components/SourceControlIcon" ;
76+ import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients" ;
7377import { ThemedSwitch } from "../../components/ThemedSwitch" ;
7478import { uuidv4 } from "../../lib/uuid" ;
7579import { useAtomCommand } from "../../state/use-atom-command" ;
@@ -122,18 +126,7 @@ function stringParam(value: string | string[] | undefined): string | null {
122126}
123127
124128function sourceFromParam ( value : string | string [ ] | undefined ) : AddProjectRemoteSource {
125- const source = stringParam ( value ) ;
126- if (
127- source === "url" ||
128- source === "github" ||
129- source === "gitlab" ||
130- source === "forgejo" ||
131- source === "bitbucket" ||
132- source === "azure-devops"
133- ) {
134- return source ;
135- }
136- return "url" ;
129+ return parseAddProjectRemoteSource ( stringParam ( value ) ) ;
137130}
138131
139132function SectionTitle ( props : { readonly children : string } ) {
@@ -498,7 +491,7 @@ function SourceControlRow(props: {
498491 />
499492 ) : (
500493 < SourceControlIcon
501- kind = { props . source }
494+ kind = { sourceControlClients . get ( props . source ) . icon }
502495 size = { Platform . OS === "android" ? 24 : 18 }
503496 colorClassName = "accent-icon"
504497 />
@@ -658,13 +651,13 @@ export function AddProjectSourceScreen() {
658651 key = { candidate }
659652 source = { candidate }
660653 selectedEnvironmentId = { selectedEnvironment . environmentId }
661- ready = { canCloneProject && readiness [ candidate ] . ready }
654+ ready = { canCloneProject && readiness ( candidate ) . ready }
662655 hint = {
663656 ! canCloneProject
664657 ? "This connection cannot clone projects."
665- : readiness [ candidate ] . ready
658+ : readiness ( candidate ) . ready
666659 ? addProjectRemoteSourcePathHint ( candidate )
667- : ( readiness [ candidate ] . hint ?? "" )
660+ : ( readiness ( candidate ) . hint ?? "" )
668661 }
669662 isFirst = { false }
670663 />
@@ -1003,9 +996,12 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
1003996 input : { } ,
1004997 } ) ,
1005998 ) ;
1006- const githubTarget = getNewProjectGitHubTarget ( discoveryState . data ) ;
999+ const publishTargets = getNewProjectPublishTargets ( discoveryState . data ) ;
10071000 const [ name , setName ] = useState ( "" ) ;
1008- const [ publishesToGitHub , setPublishesToGitHub ] = useState ( false ) ;
1001+ const [ publishes , setPublishes ] = useState ( false ) ;
1002+ // Null takes the first ready host, GitHub when it is ready.
1003+ const [ publishKind , setPublishKind ] = useState < SourceControlProviderKind | null > ( null ) ;
1004+ const publishTarget = getNewProjectPublishTarget ( publishTargets , publishKind ) ;
10091005 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
10101006 const [ error , setError ] = useState < string | null > ( null ) ;
10111007 const trimmedName = name . trim ( ) ;
@@ -1074,19 +1070,19 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
10741070 if ( commitError !== undefined ) {
10751071 Alert . alert ( "Created without a first commit" , commitError ) ;
10761072 }
1077- if ( publishesToGitHub && githubTarget !== null ) {
1073+ if ( publishes && publishTarget !== null ) {
10781074 void publishRepository ( {
10791075 environmentId : environment . environmentId ,
10801076 input : {
10811077 cwd : workspaceRoot ,
1082- provider : "github" ,
1083- repository : getNewProjectGitHubRepository ( githubTarget , workspaceRoot ) ,
1078+ provider : publishTarget . definition . kind ,
1079+ repository : getNewProjectRepository ( publishTarget , workspaceRoot ) ,
10841080 visibility : "private" ,
10851081 } ,
10861082 } ) . then ( ( publishResult ) => {
10871083 if ( AsyncResult . isFailure ( publishResult ) ) {
10881084 Alert . alert (
1089- " Could not create the GitHub repository" ,
1085+ ` Could not create the ${ publishTarget . definition . label } repository` ,
10901086 errorMessage ( Cause . squash ( publishResult . cause ) ) ,
10911087 ) ;
10921088 }
@@ -1141,32 +1137,63 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
11411137 </ Text >
11421138 ) : null }
11431139 { machineRows }
1144- { githubTarget !== null ? (
1140+ { publishTarget !== null ? (
11451141 < ListSection >
11461142 < ListRow
1147- title = " Create private repository on GitHub"
1143+ title = { ` Create private repository on ${ publishTarget . definition . label } ` }
11481144 subtitle = {
11491145 trimmedName . length > 0 && pathPreview !== null
1150- ? getNewProjectGitHubRepository ( githubTarget , pathPreview )
1151- : githubTarget . account
1146+ ? getNewProjectRepository ( publishTarget , pathPreview )
1147+ : publishTarget . owner
11521148 }
11531149 icon = {
11541150 < SourceControlIcon
1155- kind = "github"
1151+ kind = { publishTarget . definition . icon }
11561152 size = { Platform . OS === "android" ? 24 : 18 }
11571153 colorClassName = "accent-icon"
11581154 />
11591155 }
11601156 isFirst
11611157 right = {
11621158 < ThemedSwitch
1163- accessibilityLabel = " Create private repository on GitHub"
1164- value = { publishesToGitHub }
1165- onValueChange = { setPublishesToGitHub }
1159+ accessibilityLabel = { ` Create private repository on ${ publishTarget . definition . label } ` }
1160+ value = { publishes }
1161+ onValueChange = { setPublishes }
11661162 />
11671163 }
1168- onPress = { ( ) => setPublishesToGitHub ( ( publishes ) => ! publishes ) }
1164+ onPress = { ( ) => setPublishes ( ( current ) => ! current ) }
11691165 />
1166+ { publishes && publishTargets . length > 1
1167+ ? publishTargets . map ( ( target ) => {
1168+ const selected = target . definition . kind === publishTarget . definition . kind ;
1169+ return (
1170+ < ListRow
1171+ key = { target . definition . kind }
1172+ title = { target . definition . label }
1173+ icon = {
1174+ < SourceControlIcon
1175+ kind = { target . definition . icon }
1176+ size = { Platform . OS === "android" ? 24 : 17 }
1177+ colorClassName = "accent-icon"
1178+ />
1179+ }
1180+ selected = { selected }
1181+ disabled = { isSubmitting }
1182+ right = {
1183+ selected ? (
1184+ < SymbolView
1185+ name = "checkmark"
1186+ size = { Platform . OS === "android" ? 20 : 14 }
1187+ tintColorClassName = "accent-icon"
1188+ type = "monochrome"
1189+ />
1190+ ) : null
1191+ }
1192+ onPress = { ( ) => setPublishKind ( target . definition . kind ) }
1193+ />
1194+ ) ;
1195+ } )
1196+ : null }
11701197 </ ListSection >
11711198 ) : null }
11721199 < PrimaryActionButton
0 commit comments