diff --git a/auth/client.go b/auth/client.go index 3d85d7c..e8634ff 100644 --- a/auth/client.go +++ b/auth/client.go @@ -30,8 +30,11 @@ func NewClient(host string, handle string) (*http.Client, error) { return &http.Client{Jar: jar}, nil } -// saveCookies serializes the cookies and saves them to the system keyring -func saveCookies(cookies []*http.Cookie, host string, handle string) error { +// SaveCookies serializes the cookies and saves them to the system keyring +func SaveCookies(cookies []*http.Cookie, host string, handle string) error { + if len(cookies) == 0 { + return nil + } data, err := json.Marshal(cookies) if err != nil { return err diff --git a/auth/login.go b/auth/login.go index e988ceb..8321e01 100644 --- a/auth/login.go +++ b/auth/login.go @@ -59,7 +59,7 @@ func Login(cmd *cobra.Command, args []string) error { return fmt.Errorf("authenticating: %w", err) } - if err := saveCookies(cookies, "tangled.sh", handle); err != nil { + if err := SaveCookies(cookies, knit.DefaultHost, handle); err != nil { return err } diff --git a/pr/create.go b/pr/create.go index 4ed261b..8f77a6c 100644 --- a/pr/create.go +++ b/pr/create.go @@ -140,6 +140,7 @@ func Create(cmd *cobra.Command, args []string) error { return err } defer resp.Body.Close() + auth.SaveCookies(resp.Cookies(), knit.DefaultHost, handle) if resp.StatusCode != http.StatusOK { return fmt.Errorf("unexpected status code: %d", resp.StatusCode) @@ -147,6 +148,7 @@ func Create(cmd *cobra.Command, args []string) error { stop() wg.Wait() + fmt.Printf("\x1b[32m✔\x1b[m PR created!\r\n") return nil }