-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchoice.go
85 lines (72 loc) · 1.88 KB
/
choice.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"encoding/json"
"io"
"os"
"github.com/bwmarrin/discordgo"
)
type UserInfo struct {
DiscordID string `json:"discordID"`
JiraID string `json:"jiraID"`
}
type Projects struct {
ID string `json:"id"`
IssueTypes []IssueTypes `json:"issue_types"`
}
type IssueTypes struct {
ID string `json:"id"`
Name string `json:"name"`
}
func buildAssigneeChoices() []*discordgo.ApplicationCommandOptionChoice {
jsonFile, err := os.Open("users.json")
if err != nil {
panic(err)
}
defer jsonFile.Close()
byteValue, err := io.ReadAll(jsonFile)
if err != nil {
panic(err)
}
var users map[string]UserInfo
json.Unmarshal(byteValue, &users)
index := 0
choices := make([]*discordgo.ApplicationCommandOptionChoice, len(users))
for name, info := range users {
choices[index] = &discordgo.ApplicationCommandOptionChoice{
Name: name,
Value: info.JiraID,
}
index++
}
return choices
}
func buildIssueTypesAndProjectChoices() ([]*discordgo.ApplicationCommandOptionChoice, []*discordgo.ApplicationCommandOptionChoice) {
jsonFile, err := os.Open("projects.json")
if err != nil {
panic(err)
}
defer jsonFile.Close()
byteValue, err := io.ReadAll(jsonFile)
if err != nil {
panic(err)
}
var projects map[string]Projects
json.Unmarshal(byteValue, &projects)
var issueTypeChoices []*discordgo.ApplicationCommandOptionChoice
projectNameChoices := make([]*discordgo.ApplicationCommandOptionChoice, len(projects))
index := 0
for projectName, project := range projects {
projectNameChoices[index] = &discordgo.ApplicationCommandOptionChoice{
Name: projectName,
Value: project.ID,
}
for _, issueType := range project.IssueTypes {
issueTypeChoices = append(issueTypeChoices, &discordgo.ApplicationCommandOptionChoice{
Name: issueType.Name,
Value: issueType.ID,
})
}
index++
}
return issueTypeChoices, projectNameChoices
}