aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-06-21 23:25:23 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-06-24 21:29:57 +0200
commit07492fb72a4af565d607432c681143d77f102515 (patch)
tree9b0bcca038cb4ecb2f73f76525f62358bc9a4c99 /bridge
parent1d42814166f783766a1b81e926c93c21244289dc (diff)
downloadgit-bug-07492fb72a4af565d607432c681143d77f102515.tar.gz
[bridge/github] importer: tag imported issues with origin metadata
[bridge/github] exporter: correct export signature and cache maps
Diffstat (limited to 'bridge')
-rw-r--r--bridge/github/export.go26
-rw-r--r--bridge/github/github.go2
-rw-r--r--bridge/github/import.go3
3 files changed, 17 insertions, 14 deletions
diff --git a/bridge/github/export.go b/bridge/github/export.go
index e7611360..658ef484 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -15,7 +15,6 @@ import (
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
)
@@ -23,11 +22,11 @@ import (
type githubExporter struct {
conf core.Configuration
- // a map containing
- tokens map[string]string
+ // cache identities clients
+ identityClient map[string]*githubv4.Client
- // clients
- clients map[string]*githubv4.Client
+ // map identity with their tokens
+ identityToken map[string]string
// github repository ID
repositoryID string
@@ -44,20 +43,20 @@ type githubExporter struct {
func (ge *githubExporter) Init(conf core.Configuration) error {
//TODO: initialize with multiple tokens
ge.conf = conf
- ge.tokens = make(map[string]string)
- ge.clients = make(map[string]*githubv4.Client)
+ ge.identityToken = make(map[string]string)
+ ge.identityClient = make(map[string]*githubv4.Client)
ge.cachedIDs = make(map[string]string)
ge.cachedLabels = make(map[string]string)
return nil
}
func (ge *githubExporter) getIdentityClient(id string) (*githubv4.Client, error) {
- client, ok := ge.clients[id]
+ client, ok := ge.identityClient[id]
if ok {
return client, nil
}
- token, ok := ge.tokens[id]
+ token, ok := ge.identityToken[id]
if !ok {
return nil, fmt.Errorf("unknown identity token")
}
@@ -72,7 +71,7 @@ func (ge *githubExporter) ExportAll(repo *cache.RepoCache, since time.Time) erro
return err
}
- ge.tokens[user.Id()] = ge.conf[keyToken]
+ ge.identityToken[user.Id()] = ge.conf[keyToken]
// get repository node id
ge.repositoryID, err = getRepositoryNodeID(
@@ -102,10 +101,10 @@ bugLoop:
// if identity participated in a bug
for _, p := range snapshot.Participants {
- for userId := range ge.tokens {
+ for userId := range ge.identityToken {
if p.Id() == userId {
// try to export the bug and it associated events
- if err := ge.exportBug(b, user.Identity, since); err != nil {
+ if err := ge.exportBug(b, since); err != nil {
return err
}
@@ -119,7 +118,7 @@ bugLoop:
}
// exportBug publish bugs and related events
-func (ge *githubExporter) exportBug(b *cache.BugCache, user identity.Interface, since time.Time) error {
+func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time) error {
snapshot := b.Snapshot()
var bugGithubID string
@@ -148,6 +147,7 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, user identity.Interface,
bugGithubURL = githubURL
} else {
+ // check that we have a token for operation author
client, err := ge.getIdentityClient(author.Id())
if err != nil {
// if bug is still not exported and user cannot author bug stop the execution
diff --git a/bridge/github/github.go b/bridge/github/github.go
index 46004dc8..176bdd84 100644
--- a/bridge/github/github.go
+++ b/bridge/github/github.go
@@ -17,7 +17,7 @@ func init() {
type Github struct{}
func (*Github) Target() string {
- return "github"
+ return target
}
func (*Github) NewImporter() core.Importer {
diff --git a/bridge/github/import.go b/bridge/github/import.go
index 6cfd022e..d07f0499 100644
--- a/bridge/github/import.go
+++ b/bridge/github/import.go
@@ -16,6 +16,7 @@ import (
)
const (
+ keyOrigin = "origin"
keyGithubId = "github-id"
keyGithubUrl = "github-url"
keyGithubLogin = "github-login"
@@ -113,6 +114,7 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline
cleanText,
nil,
map[string]string{
+ keyOrigin: target,
keyGithubId: parseId(issue.Id),
keyGithubUrl: issue.Url.String(),
})
@@ -147,6 +149,7 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline
cleanText,
nil,
map[string]string{
+ keyOrigin: target,
keyGithubId: parseId(issue.Id),
keyGithubUrl: issue.Url.String(),
},