aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/export.go
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-07-06 00:23:19 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-07-06 00:23:19 +0200
commit6323c7b10663024f03d6c8c641852c702a5d8a04 (patch)
tree4ef7d6a44284f52d51587c5186cccd2b002adb51 /bridge/github/export.go
parent3e181168eadb1d6a13e67583c16219200d052fcc (diff)
downloadgit-bug-6323c7b10663024f03d6c8c641852c702a5d8a04.tar.gz
[bridge/github] ignore imported bugs from other repositories
Diffstat (limited to 'bridge/github/export.go')
-rw-r--r--bridge/github/export.go42
1 files changed, 18 insertions, 24 deletions
diff --git a/bridge/github/export.go b/bridge/github/export.go
index c4ca42da..b4351bdb 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -28,9 +28,6 @@ var (
type githubExporter struct {
conf core.Configuration
- // export only bugs tagged with one of these origins
- onlyOrigins []string
-
// cache identities clients
identityClient map[string]*githubv4.Client
@@ -59,23 +56,6 @@ func (ge *githubExporter) Init(conf core.Configuration) error {
return nil
}
-// allowOrigin verify that origin is allowed to get exported.
-// if the exporter was initialized with no specified origins, it will return
-// true for all origins
-func (ge *githubExporter) allowOrigin(origin string) bool {
- if len(ge.onlyOrigins) == 0 {
- return true
- }
-
- for _, o := range ge.onlyOrigins {
- if origin == o {
- return true
- }
- }
-
- return false
-}
-
// getIdentityClient return a githubv4 API client configured with the access token of the given identity.
// if no client were found it will initialize it from the known tokens map and cache it for next use
func (ge *githubExporter) getIdentityClient(id string) (*githubv4.Client, error) {
@@ -175,22 +155,36 @@ func (ge *githubExporter) exportBug(b *cache.BugCache, since time.Time, out chan
author := snapshot.Author
// skip bug if origin is not allowed
- origin, ok := createOp.GetMetadata(keyOrigin)
- if ok && !ge.allowOrigin(origin) {
+ origin, ok := snapshot.GetCreateMetadata(keyOrigin)
+ if ok && origin != target {
out <- core.NewExportNothing(b.Id(), fmt.Sprintf("issue tagged with origin: %s", origin))
return
}
// get github bug ID
- githubID, ok := createOp.GetMetadata(keyGithubId)
+ githubID, ok := snapshot.GetCreateMetadata(keyGithubId)
if ok {
- githubURL, ok := createOp.GetMetadata(keyGithubUrl)
+ githubURL, ok := snapshot.GetCreateMetadata(keyGithubUrl)
if !ok {
// if we find github ID, github URL must be found too
err := fmt.Errorf("expected to find github issue URL")
out <- core.NewExportError(err, b.Id())
}
+ // extract owner and project
+ owner, project, err := splitURL(githubURL)
+ if err != nil {
+ err := fmt.Errorf("bad project url: %v", err)
+ out <- core.NewExportError(err, b.Id())
+ return
+ }
+
+ // ignore issue comming from other repositories
+ if owner != ge.conf[keyOwner] && project != ge.conf[keyProject] {
+ out <- core.NewExportNothing(b.Id(), fmt.Sprintf("skipping issue from url:%s", githubURL))
+ return
+ }
+
out <- core.NewExportNothing(b.Id(), "bug already exported")
// will be used to mark operation related to a bug as exported
bugGithubID = githubID