@@ -40,16 +40,27 @@ const saveRepositoryPrConfig = ({ repositoryFullName, config }) => {
4040 }
4141}
4242
43- const clearRepositoryPrConfig = repositoryFullName => {
43+ const clearRepositoryPrDraftFields = ( {
44+ repositoryFullName,
45+ componentFilePath,
46+ stylesFilePath,
47+ baseBranch,
48+ } ) => {
4449 if ( typeof repositoryFullName !== 'string' || ! repositoryFullName . trim ( ) ) {
4550 return
4651 }
4752
48- try {
49- localStorage . removeItem ( `${ prConfigStoragePrefix } ${ repositoryFullName } ` )
50- } catch {
51- /* noop */
52- }
53+ saveRepositoryPrConfig ( {
54+ repositoryFullName,
55+ config : {
56+ componentFilePath,
57+ stylesFilePath,
58+ baseBranch,
59+ headBranch : '' ,
60+ prTitle : '' ,
61+ prBody : '' ,
62+ } ,
63+ } )
5364}
5465
5566const toSafeText = value => ( typeof value === 'string' ? value . trim ( ) : '' )
@@ -97,18 +108,20 @@ const validateFilePath = value => {
97108}
98109
99110const sanitizeBranchPart = value => {
100- const trimmed = toSafeText ( value ) . toLowerCase ( )
111+ const trimmed = toSafeText ( value )
101112 if ( ! trimmed ) {
102113 return ''
103114 }
104115
105116 return trimmed
106- . replace ( / [ ^ a - z 0 - 9 . _ / - ] / g, '-' )
117+ . replace ( / [ ^ A - Z a - z 0 - 9 . _ / - ] / g, '-' )
107118 . replace ( / \/ + / g, '/' )
108119 . replace ( / - { 2 , } / g, '-' )
109120 . replace ( / ^ [ - / . ] + | [ - / . ] + $ / g, '' )
110121}
111122
123+ const sanitizeAutoBranchPart = value => sanitizeBranchPart ( value ) . toLowerCase ( )
124+
112125const toUtcBranchStamp = ( ) => {
113126 const now = new Date ( )
114127 const parts = [
@@ -137,7 +150,7 @@ const isAutoGeneratedHeadBranch = value => {
137150}
138151
139152const createDefaultBranchName = repository => {
140- const repoName = sanitizeBranchPart ( repository ?. name ?? '' ) || 'repo'
153+ const repoName = sanitizeAutoBranchPart ( repository ?. name ?? '' ) || 'repo'
141154 const stamp = toUtcBranchStamp ( )
142155 const entropy = createBranchEntropySuffix ( )
143156 return `develop/${ repoName } /editor-sync-${ stamp } -${ entropy } `
@@ -322,7 +335,8 @@ export const createGitHubPrDrawer = ({
322335 const syncFormForRepository = ( { resetBranch = false , resetAll = false } = { } ) => {
323336 const repository = getSelectedRepositoryObject ( )
324337 const repositoryFullName = getRepositoryFullName ( repository )
325- const savedConfig = resetAll ? { } : readRepositoryPrConfig ( repositoryFullName )
338+ const savedConfig = readRepositoryPrConfig ( repositoryFullName )
339+ const savedDraftConfig = resetAll ? { } : savedConfig
326340
327341 const componentFilePath =
328342 typeof savedConfig . componentFilePath === 'string' && savedConfig . componentFilePath
@@ -352,7 +366,7 @@ export const createGitHubPrDrawer = ({
352366
353367 if ( headBranchInput instanceof HTMLInputElement ) {
354368 if ( resetAll || resetBranch || ! toSafeText ( headBranchInput . value ) ) {
355- const savedHeadBranch = sanitizeBranchPart ( savedConfig . headBranch )
369+ const savedHeadBranch = sanitizeBranchPart ( savedDraftConfig . headBranch )
356370 headBranchInput . value =
357371 savedHeadBranch && ! isAutoGeneratedHeadBranch ( savedHeadBranch )
358372 ? savedHeadBranch
@@ -363,15 +377,15 @@ export const createGitHubPrDrawer = ({
363377 if ( prTitleInput instanceof HTMLInputElement ) {
364378 if ( resetAll || ! toSafeText ( prTitleInput . value ) ) {
365379 prTitleInput . value =
366- toSafeText ( savedConfig . prTitle ) || toDefaultPrTitle ( repository )
380+ toSafeText ( savedDraftConfig . prTitle ) || toDefaultPrTitle ( repository )
367381 }
368382 }
369383
370384 if ( prBodyInput instanceof HTMLTextAreaElement ) {
371385 if ( resetAll || ! toSafeText ( prBodyInput . value ) ) {
372386 prBodyInput . value =
373- typeof savedConfig . prBody === 'string' && savedConfig . prBody
374- ? savedConfig . prBody
387+ typeof savedDraftConfig . prBody === 'string' && savedDraftConfig . prBody
388+ ? savedDraftConfig . prBody
375389 : toDefaultPrBody ( { componentFilePath, stylesFilePath } )
376390 }
377391 }
@@ -512,7 +526,12 @@ export const createGitHubPrDrawer = ({
512526 signal : abortController . signal ,
513527 } )
514528 . then ( result => {
515- persistCurrentPaths ( )
529+ clearRepositoryPrDraftFields ( {
530+ repositoryFullName : repositoryLabel ,
531+ componentFilePath : componentPathValidation . value ,
532+ stylesFilePath : stylesPathValidation . value ,
533+ baseBranch : values . baseBranch ,
534+ } )
516535 const url = result . pullRequest . htmlUrl
517536 setStatus (
518537 url ? `Pull request opened: ${ url } ` : 'Pull request opened successfully.' ,
@@ -522,7 +541,6 @@ export const createGitHubPrDrawer = ({
522541 url,
523542 pullRequestNumber : result . pullRequest . number ,
524543 } )
525- clearRepositoryPrConfig ( repositoryLabel )
526544 resetOnNextOpen = true
527545 setOpen ( false )
528546 } )
@@ -534,7 +552,12 @@ export const createGitHubPrDrawer = ({
534552 const message =
535553 error instanceof Error ? error . message : 'Failed to open pull request.'
536554 setStatus ( `Open PR failed: ${ message } ` , 'error' )
537- clearRepositoryPrConfig ( repositoryLabel )
555+ clearRepositoryPrDraftFields ( {
556+ repositoryFullName : repositoryLabel ,
557+ componentFilePath : componentPathValidation . value ,
558+ stylesFilePath : stylesPathValidation . value ,
559+ baseBranch : values . baseBranch ,
560+ } )
538561 resetOnNextOpen = true
539562 } )
540563 . finally ( ( ) => {
0 commit comments