-
Notifications
You must be signed in to change notification settings - Fork 1
/
bridge.go
66 lines (56 loc) · 1.55 KB
/
bridge.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package githubjirabridge
import (
"context"
"log"
"net/http"
"os"
"strings"
"github.com/andygrunwald/go-jira"
"github.com/google/go-github/v42/github"
"github.com/gorilla/mux"
"golang.org/x/oauth2"
)
const (
jiraStubSignature = "Created by github-jira-bridge."
)
var (
router *mux.Router
logger *log.Logger
jiraClient *jira.Client
githubClient *github.Client
jiraStatusToGithubLabels map[string]string
)
func init() {
logger = log.New(os.Stdout, "", log.LstdFlags)
logger.Println("starting up")
router = mux.NewRouter()
router.HandleFunc("/github", handleGithubWebhook).Methods(http.MethodPost)
router.HandleFunc("/jira/issues", handleJiraIssueWebhook).Methods(http.MethodPost)
jiraAuth := jira.BasicAuthTransport{
Username: jiraUsername,
Password: jiraApiToken,
}
var err error
jiraClient, err = jira.NewClient(jiraAuth.Client(), jiraApiURL)
if err != nil {
panic(err)
}
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: githubToken},
)
tc := oauth2.NewClient(ctx, ts)
githubClient = github.NewClient(tc)
jiraStatusToGithubLabels = map[string]string{}
for _, pair := range strings.Split(jiraStatusChangeToGithubLabels, ",") {
if pair == "" {
continue
}
jiraStatusAndGithubLabel := strings.Split(pair, ":")
jiraStatusToGithubLabels[jiraStatusAndGithubLabel[0]] = jiraStatusAndGithubLabel[1]
}
}
// Google Cloud Function entrypoint
func GitHubJiraBridge(w http.ResponseWriter, req *http.Request) {
router.ServeHTTP(w, req)
}