A CLI for tangled.sh

auth: save cookies after resp

Cookies could be expired, so we save them if we have them

authored by rockorager.dev and committed by Tangled dea05b77 10085aae

Changed files
+8 -3
auth
pr
+5 -2
auth/client.go
··· 30 30 return &http.Client{Jar: jar}, nil 31 31 } 32 32 33 - // saveCookies serializes the cookies and saves them to the system keyring 34 - func saveCookies(cookies []*http.Cookie, host string, handle string) error { 33 + // SaveCookies serializes the cookies and saves them to the system keyring 34 + func SaveCookies(cookies []*http.Cookie, host string, handle string) error { 35 + if len(cookies) == 0 { 36 + return nil 37 + } 35 38 data, err := json.Marshal(cookies) 36 39 if err != nil { 37 40 return err
+1 -1
auth/login.go
··· 59 59 return fmt.Errorf("authenticating: %w", err) 60 60 } 61 61 62 - if err := saveCookies(cookies, "tangled.sh", handle); err != nil { 62 + if err := SaveCookies(cookies, knit.DefaultHost, handle); err != nil { 63 63 return err 64 64 } 65 65
+2
pr/create.go
··· 140 140 return err 141 141 } 142 142 defer resp.Body.Close() 143 + auth.SaveCookies(resp.Cookies(), knit.DefaultHost, handle) 143 144 144 145 if resp.StatusCode != http.StatusOK { 145 146 return fmt.Errorf("unexpected status code: %d", resp.StatusCode) ··· 147 148 148 149 stop() 149 150 wg.Wait() 151 + fmt.Printf("\x1b[32m✔\x1b[m PR created!\r\n") 150 152 151 153 return nil 152 154 }