From 7cb7994cdae848053487d00c1730d1e865fb8623 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 7 Oct 2018 18:27:23 +0200 Subject: github: also pull users email --- bridge/github/config.go | 9 +++++++-- bridge/github/import.go | 31 +++++++++++++++++++++++++++++-- bridge/github/import_query.go | 16 +++++++++++++++- 3 files changed, 51 insertions(+), 5 deletions(-) (limited to 'bridge') diff --git a/bridge/github/config.go b/bridge/github/config.go index 8aa41638..b881c585 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -29,7 +29,10 @@ func (*Github) Configure(repo repository.RepoCommon) (core.Configuration, error) conf := make(core.Configuration) fmt.Println() - fmt.Println("git-bug will generate an access token in your Github profile. Your credential are not stored and are only used to generate the token. The token is stored in the repository git config.") + fmt.Println("git-bug will now generate an access token in your Github profile. Your credential are not stored and are only used to generate the token. The token is stored in the repository git config.") + fmt.Println() + fmt.Println("The token will have the following scopes:") + fmt.Println(" - user:email: to be able to read public-only users email") // fmt.Println("The token will have the \"repo\" permission, giving it read/write access to your repositories and issues. There is no narrower scope available, sorry :-|") fmt.Println() @@ -120,7 +123,9 @@ func requestTokenWith2FA(note, username, password, otpCode string) (*http.Respon Note string `json:"note"` Fingerprint string `json:"fingerprint"` }{ - // Scopes: []string{"repo"}, + // user:email is requested to be able to read public emails + // - a private email will stay private, even with this token + Scopes: []string{"user:email"}, Note: note, Fingerprint: randomFingerprint(), } diff --git a/bridge/github/import.go b/bridge/github/import.go index ed0135e7..93390408 100644 --- a/bridge/github/import.go +++ b/bridge/github/import.go @@ -565,9 +565,29 @@ func (gi *githubImporter) makePerson(actor *actor) bug.Person { if actor == nil { return gi.ghost } + var name string + var email string + + switch actor.Typename { + case "User": + if actor.User.Name != nil { + name = string(*(actor.User.Name)) + } + email = string(actor.User.Email) + case "Organization": + if actor.Organization.Name != nil { + name = string(*(actor.Organization.Name)) + } + if actor.Organization.Email != nil { + email = string(*(actor.Organization.Email)) + } + case "Bot": + } return bug.Person{ - Name: string(actor.Login), + Name: name, + Email: email, + Login: string(actor.Login), AvatarUrl: string(actor.AvatarUrl), } } @@ -584,9 +604,16 @@ func (gi *githubImporter) fetchGhost() error { return err } + var name string + if q.User.Name != nil { + name = string(*q.User.Name) + } + gi.ghost = bug.Person{ - Name: string(q.User.Login), + Name: name, + Login: string(q.User.Login), AvatarUrl: string(q.User.AvatarUrl), + Email: string(q.User.Email), } return nil diff --git a/bridge/github/import_query.go b/bridge/github/import_query.go index e1dcff64..59799f6a 100644 --- a/bridge/github/import_query.go +++ b/bridge/github/import_query.go @@ -10,8 +10,17 @@ type pageInfo struct { } type actor struct { + Typename githubv4.String `graphql:"__typename"` Login githubv4.String AvatarUrl githubv4.String + User struct { + Name *githubv4.String + Email githubv4.String + } `graphql:"... on User"` + Organization struct { + Name *githubv4.String + Email *githubv4.String + } `graphql:"... on Organization"` } type actorEvent struct { @@ -152,5 +161,10 @@ type commentEditQuery struct { } type userQuery struct { - User actor `graphql:"user(login: $login)"` + User struct { + Login githubv4.String + AvatarUrl githubv4.String + Name *githubv4.String + Email githubv4.String + } `graphql:"user(login: $login)"` } -- cgit