jira.go

 1// Package jira contains the Jira bridge implementation
 2package jira
 3
 4import (
 5	"sort"
 6
 7	"github.com/MichaelMure/git-bug/bridge/core"
 8)
 9
10func init() {
11	core.Register(&Jira{})
12}
13
14// Jira Main object for the bridge
15type Jira struct{}
16
17// Target returns "jira"
18func (*Jira) Target() string {
19	return target
20}
21
22// NewImporter returns the jira importer
23func (*Jira) NewImporter() core.Importer {
24	return &jiraImporter{}
25}
26
27// NewExporter returns the jira exporter
28func (*Jira) NewExporter() core.Exporter {
29	return &jiraExporter{}
30}
31
32// stringInSlice returns true if needle is found in haystack
33func stringInSlice(needle string, haystack []string) bool {
34	for _, match := range haystack {
35		if match == needle {
36			return true
37		}
38	}
39	return false
40}
41
42// Given two string slices, return three lists containing:
43// 1. elements found only in the first input list
44// 2. elements found only in the second input list
45// 3. elements found in both input lists
46func setSymmetricDifference(
47	setA, setB []string) ([]string, []string, []string) {
48	sort.Strings(setA)
49	sort.Strings(setB)
50
51	maxLen := len(setA) + len(setB)
52	onlyA := make([]string, 0, maxLen)
53	onlyB := make([]string, 0, maxLen)
54	both := make([]string, 0, maxLen)
55
56	idxA := 0
57	idxB := 0
58
59	for idxA < len(setA) && idxB < len(setB) {
60		if setA[idxA] < setB[idxB] {
61			// In the first set, but not the second
62			onlyA = append(onlyA, setA[idxA])
63			idxA++
64		} else if setA[idxA] > setB[idxB] {
65			// In the second set, but not the first
66			onlyB = append(onlyB, setB[idxB])
67			idxB++
68		} else {
69			// In both
70			both = append(both, setA[idxA])
71			idxA++
72			idxB++
73		}
74	}
75
76	for ; idxA < len(setA); idxA++ {
77		// Leftovers in the first set, not the second
78		onlyA = append(onlyA, setA[idxA])
79	}
80
81	for ; idxB < len(setB); idxB++ {
82		// Leftovers in the second set, not the first
83		onlyB = append(onlyB, setB[idxB])
84	}
85
86	return onlyA, onlyB, both
87}