aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-10-07 18:27:23 +0200
committerMichael Muré <batolettre@gmail.com>2018-10-07 18:27:23 +0200
commit7cb7994cdae848053487d00c1730d1e865fb8623 (patch)
treebc9be185e81479d8d3e5b0fc636daea011a64e4c /bridge/github
parent03202fed493539c8d1fdcad7254687f951d0ca4a (diff)
downloadgit-bug-7cb7994cdae848053487d00c1730d1e865fb8623.tar.gz
github: also pull users email
Diffstat (limited to 'bridge/github')
-rw-r--r--bridge/github/config.go9
-rw-r--r--bridge/github/import.go31
-rw-r--r--bridge/github/import_query.go16
3 files changed, 51 insertions, 5 deletions
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)"`
}