diff options
author | Josh Bialkowski <josh.bialkowski@gmail.com> | 2019-11-07 08:01:08 -0800 |
---|---|---|
committer | Josh Bialkowski <josh.bialkowski@gmail.com> | 2019-12-18 07:42:13 -0800 |
commit | eff830bdcb8f979da34fb9e8f782efb1598b4a44 (patch) | |
tree | d0aa7524125b08c863e7ad7683272ab29cf99ad3 /bridge/jira/jira.go | |
parent | e96d8e6771086e20639a16abf6af30f2faa006a0 (diff) | |
download | git-bug-eff830bdcb8f979da34fb9e8f782efb1598b4a44.tar.gz |
Implement jira bridge
Diffstat (limited to 'bridge/jira/jira.go')
-rw-r--r-- | bridge/jira/jira.go | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/bridge/jira/jira.go b/bridge/jira/jira.go new file mode 100644 index 00000000..933c1239 --- /dev/null +++ b/bridge/jira/jira.go @@ -0,0 +1,87 @@ +// Package jira contains the Jira bridge implementation +package jira + +import ( + "sort" + + "github.com/MichaelMure/git-bug/bridge/core" +) + +func init() { + core.Register(&Jira{}) +} + +// Jira Main object for the bridge +type Jira struct{} + +// Target returns "jira" +func (*Jira) Target() string { + return target +} + +// NewImporter returns the jira importer +func (*Jira) NewImporter() core.Importer { + return &jiraImporter{} +} + +// NewExporter returns the jira exporter +func (*Jira) NewExporter() core.Exporter { + return &jiraExporter{} +} + +// stringInSlice returns true if needle is found in haystack +func stringInSlice(needle string, haystack []string) bool { + for _, match := range haystack { + if match == needle { + return true + } + } + return false +} + +// Given two string slices, return three lists containing: +// 1. elements found only in the first input list +// 2. elements found only in the second input list +// 3. elements found in both input lists +func setSymmetricDifference( + setA, setB []string) ([]string, []string, []string) { + sort.Strings(setA) + sort.Strings(setB) + + maxLen := len(setA) + len(setB) + onlyA := make([]string, 0, maxLen) + onlyB := make([]string, 0, maxLen) + both := make([]string, 0, maxLen) + + idxA := 0 + idxB := 0 + + for idxA < len(setA) && idxB < len(setB) { + if setA[idxA] < setB[idxB] { + // In the first set, but not the second + onlyA = append(onlyA, setA[idxA]) + idxA++ + } else if setA[idxA] > setB[idxB] { + // In the second set, but not the first + onlyB = append(onlyB, setB[idxB]) + idxB++ + } else { + // In both + both = append(both, setA[idxA]) + idxA++ + idxB++ + } + } + + for ; idxA < len(setA); idxA++ { + // Leftovers in the first set, not the second + onlyA = append(onlyA, setA[idxA]) + } + + for ; idxB < len(setB); idxB++ { + // Leftovers in the second set, not the first + onlyB = append(onlyB, setB[idxB]) + } + + return onlyA, onlyB, both +} |