@@ -8,6 +8,7 @@ import { promises as fs } from "fs";
8
8
import { Octokit } from "octokit" ;
9
9
import prettier from "prettier" ;
10
10
import replace from "replace-in-file" ;
11
+ import { titleCase } from "title-case" ;
11
12
12
13
let caughtError ;
13
14
36
37
strict : false ,
37
38
} ) ;
38
39
40
+ async function getDefaultSettings ( ) {
41
+ let gitRemoteFetch ;
42
+ try {
43
+ gitRemoteFetch = await $ `git remote -v | grep fetch` ;
44
+ } catch {
45
+ console . log (
46
+ chalk . gray (
47
+ "Could not populate default owner and repository. Did not detect a Git repository with an origin. "
48
+ )
49
+ ) ;
50
+ return {
51
+ defaultOwner : "UserName" ,
52
+ defaultRepository : "my-lovely-repository" ,
53
+ } ;
54
+ }
55
+
56
+ const [ , defaultOwner , defaultRepository ] = gitRemoteFetch . stdout . match (
57
+ / \s .+ \/ ( [ ^ / ] + ) \/ ( [ ^ / ] + ) \( f e t c h \) /
58
+ ) ;
59
+
60
+ return { defaultOwner, defaultRepository } ;
61
+ }
62
+
63
+ const { defaultOwner, defaultRepository } = await getDefaultSettings ( ) ;
64
+
39
65
async function getPrefillOrPromptedValue ( key , message , placeholder ) {
40
66
if ( values [ key ] ) {
41
67
console . log ( chalk . grey ( `Pre-filling ${ key } to ${ values [ key ] } .` ) ) ;
@@ -63,19 +89,19 @@ try {
63
89
const repository = await getPrefillOrPromptedValue (
64
90
"repository" ,
65
91
"What will the kebab-case name of the repository be?" ,
66
- "my-lovely-repository"
92
+ defaultRepository
67
93
) ;
68
94
69
95
const title = await getPrefillOrPromptedValue (
70
96
"title" ,
71
97
"What will the Title Case title of the repository be?" ,
72
- "My Lovely Repository"
98
+ titleCase ( repository ) . replaceAll ( "-" , " " )
73
99
) ;
74
100
75
101
const owner = await getPrefillOrPromptedValue (
76
102
"owner" ,
77
103
"What owner or user will the repository be under?" ,
78
- "UserName"
104
+ defaultOwner
79
105
) ;
80
106
81
107
const description = await getPrefillOrPromptedValue (
0 commit comments