@@ -27,6 +27,16 @@ func BookmarksEditSaveAction(w http.ResponseWriter, r *http.Request) error {
2727 _ , curSha , err := GetBookmarks (r .Context (), login , ref , token )
2828 if err != nil {
2929 if errors .Is (err , ErrRepoNotFound ) {
30+ // attempt to create the repository automatically
31+ if p := providerFromContext (r .Context ()); p != nil {
32+ if err := p .CreateRepo (r .Context (), login , token , repoName ); err == nil {
33+ if err := CreateBookmarks (r .Context (), login , token , branch , text ); err == nil {
34+ http .Redirect (w , r , "/edit?ref=refs/heads/" + branch , http .StatusTemporaryRedirect )
35+ // stop the handler chain so the default redirect isn't executed
36+ return ErrHandled
37+ }
38+ }
39+ }
3040 return renderCreateRepoPrompt (w , r , text , branch , ref , sha , nil )
3141 }
3242 return fmt .Errorf ("GetBookmarks: %w" , err )
@@ -46,7 +56,9 @@ func BookmarksEditSaveAction(w http.ResponseWriter, r *http.Request) error {
4656 if err := CreateBookmarks (r .Context (), login , token , branch , text ); err != nil {
4757 return fmt .Errorf ("createBookmark error: %w" , err )
4858 }
49- return nil
59+ http .Redirect (w , r , "/edit?ref=refs/heads/" + branch , http .StatusTemporaryRedirect )
60+ // skip the chain's final redirect so we stay on the edit page
61+ return ErrHandled
5062 }
5163
5264 if err := UpdateBookmarks (r .Context (), login , token , ref , branch , text , curSha ); err != nil {
0 commit comments