-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathmaniphest.go
More file actions
57 lines (50 loc) · 1.41 KB
/
maniphest.go
File metadata and controls
57 lines (50 loc) · 1.41 KB
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
package resolvers
import (
"github.com/etcinit/gonduit/requests"
"github.com/etcinit/phabulous/app/factories"
"github.com/jacobstr/confer"
)
// TaskResolver resolves Maniphest tasks to Slack channels.
type TaskResolver struct {
Config *confer.Config `inject:""`
Factory *factories.GonduitFactory `inject:""`
}
// Resolve resolves the channel the message about a task should be posted on.
func (c *TaskResolver) Resolve(phid string) ([]string, error) {
conduit, err := c.Factory.Make()
var retVal []string
if err != nil {
return retVal, err
}
tasks, err := conduit.ManiphestQuery(
requests.ManiphestQueryRequest{
PHIDs: []string{phid},
},
)
if err != nil {
return retVal, err
}
task := tasks.Get(phid)
if len(task.ProjectPHIDs) < 1 {
return retVal, nil
}
channelMap := c.Config.GetStringMapString("channels.projects")
defaultChannel := c.Config.GetString("channels.feed")
matches := 0
for _, projectPHID := range task.ProjectPHIDs {
projects, err := conduit.ProjectQuery(requests.ProjectQueryRequest{
PHIDs: []string{projectPHID},
})
if err != nil {
return retVal, err
}
if channelName, ok := channelMap[projects.Data[projectPHID].ID]; ok == true {
retVal = append(retVal, channelName)
matches += 1
}
}
if (matches == 0) {
retVal = append(retVal, defaultChannel)
}
return retVal, nil
}