Skip to content

Commit 417e632

Browse files
authored
Merge pull request #56 from arran4/codex/fix-github-repo-creation-and-gitlab-login-errors
Fix repo creation with dev namespace and oauth provider tracking
2 parents b0c5f53 + d27b89a commit 417e632

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

authHandlers.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func LoginWithProvider(w http.ResponseWriter, r *http.Request) error {
8383
http.NotFound(w, r)
8484
return nil
8585
}
86-
http.Redirect(w, r, cfg.AuthCodeURL(""), http.StatusTemporaryRedirect)
86+
http.Redirect(w, r, cfg.AuthCodeURL(providerName), http.StatusTemporaryRedirect)
8787
return nil
8888
}
8989

@@ -99,7 +99,10 @@ func Oauth2CallbackPage(w http.ResponseWriter, r *http.Request) error {
9999
return fmt.Errorf("session error: %w", err)
100100
}
101101

102-
providerName, _ := session.Values["Provider"].(string)
102+
providerName := r.URL.Query().Get("state")
103+
if providerName == "" {
104+
providerName, _ = session.Values["Provider"].(string)
105+
}
103106
p := GetProvider(providerName)
104107
if p == nil {
105108
return fmt.Errorf("unknown provider")

provider_github.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,16 @@ func (p GitHubProvider) CreateBookmarks(ctx context.Context, user string, token
282282
return err
283283
}
284284
}
285-
_, _, err := client.Repositories.CreateFile(ctx, user, RepoName, "bookmarks.txt", &github.RepositoryContentFileOptions{
285+
_, resp, err := client.Repositories.CreateFile(ctx, user, RepoName, "bookmarks.txt", &github.RepositoryContentFileOptions{
286286
Message: SP("Auto create from web"),
287287
Content: []byte(text),
288288
Branch: &branch,
289289
Author: commitAuthor,
290290
Committer: commitAuthor,
291291
})
292+
if resp != nil && resp.StatusCode == http.StatusNotFound {
293+
return ErrRepoNotFound
294+
}
292295
if err != nil {
293296
log.Printf("github CreateBookmarks: %v", err)
294297
return fmt.Errorf("CreateBookmarks: %w", err)

repo.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
package gobookmarks
22

3+
import "strings"
4+
35
var RepoName = GetBookmarksRepoName()
46

57
// GetBookmarksRepoName returns the repository name based on the current
68
// configuration and build mode. When running a development build the name is
79
// suffixed with "-dev". The Namespace value is appended if supplied.
810
func GetBookmarksRepoName() string {
9-
name := "MyBookmarks"
10-
if version == "dev" {
11-
name += "-dev"
11+
ns := Namespace
12+
if strings.EqualFold(version, "dev") {
13+
if ns == "" {
14+
ns = version
15+
}
1216
}
13-
if Namespace != "" {
14-
name += "-" + Namespace
17+
18+
name := "MyBookmarks"
19+
if ns != "" {
20+
name += "-" + ns
1521
}
1622
return name
1723
}

0 commit comments

Comments
 (0)