-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from tigerteufel85/boggy-11/jql-time-support
Boggy 11/jql time support
- Loading branch information
Showing
13 changed files
with
287 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
language: go | ||
|
||
go: | ||
- "1.11" | ||
- "1.12" | ||
- "1.13" | ||
- "1.17" | ||
|
||
env: | ||
- GO111MODULE=on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"github.com/nlopes/slack" | ||
"github.com/tigerteufel85/boggy/bot" | ||
"github.com/tigerteufel85/boggy/client" | ||
"github.com/tigerteufel85/boggy/config" | ||
"github.com/tigerteufel85/boggy/utils" | ||
"gopkg.in/andygrunwald/go-jira.v1" | ||
"strings" | ||
) | ||
|
||
type jiraIssuesSingle struct { | ||
slackClient client.SlackClient | ||
jira *jira.Client | ||
jiraCfg config.JiraConfig | ||
jiraReplies config.ReplyConfig | ||
regex config.RegexConfig | ||
} | ||
|
||
func NewJiraIssuesSingle(slackClient client.SlackClient, jira *jira.Client, jiraCfg config.JiraConfig, jiraReplies config.ReplyConfig, regex config.RegexConfig) *jiraIssuesSingle { | ||
return &jiraIssuesSingle{ | ||
slackClient, | ||
jira, | ||
jiraCfg, | ||
jiraReplies, | ||
regex, | ||
} | ||
} | ||
|
||
func (c *jiraIssuesSingle) GetName() string { | ||
return "jira single" | ||
} | ||
|
||
func (c *jiraIssuesSingle) IsValid(b *bot.Bot, command string) bool { | ||
if !strings.HasPrefix(command, c.GetName()) { | ||
return false | ||
} | ||
|
||
_, err := utils.NewJQL(c.regex, command).BuildJqlQuery(c.jiraCfg) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
func (c *jiraIssuesSingle) Execute(ctx context.Context, b *bot.Bot, eventText string, event *slack.MessageEvent, user bot.User) bool { | ||
if !strings.HasPrefix(eventText, c.GetName()) { | ||
return false | ||
} | ||
|
||
// Create JQL Query | ||
jql := utils.NewJQL(c.regex, eventText) | ||
query, err := jql.BuildJqlQuery(c.jiraCfg) | ||
if err != nil { | ||
c.slackClient.Respond(event, err.Error()) | ||
return true | ||
} | ||
|
||
// Search issues on JIRA | ||
issues, searchResponse, err := c.jira.Issue.Search(query, &jira.SearchOptions{MaxResults: 50, Expand: "names"}) | ||
if err != nil { | ||
auth, _ := c.slackClient.AuthTest() | ||
if user.Name != auth.User { | ||
c.slackClient.Respond(event, err.Error()) | ||
} | ||
return true | ||
} | ||
|
||
if searchResponse.Total == 0 { | ||
return true | ||
} | ||
|
||
// Get all fields | ||
allFields, _, err := c.jira.Field.GetList() | ||
if err != nil { | ||
auth, _ := c.slackClient.AuthTest() | ||
if user.Name != auth.User { | ||
c.slackClient.Respond(event, err.Error()) | ||
} | ||
return true | ||
} | ||
|
||
for _, issue := range issues { | ||
customFields, _, err := c.jira.Issue.GetCustomFields(issue.ID) | ||
if err != nil { | ||
auth, _ := c.slackClient.AuthTest() | ||
if user.Name != auth.User { | ||
c.slackClient.Respond(event, err.Error()) | ||
} | ||
return true | ||
} | ||
|
||
responseText := utils.NewLayout(c.regex, eventText).BuildSimpleTextResponse(c.jiraCfg, issue, customFields, allFields, jql) | ||
|
||
c.slackClient.Respond(event, responseText) | ||
} | ||
|
||
return true | ||
} | ||
|
||
func (c *jiraIssuesSingle) GetHelp() []bot.Help { | ||
return []bot.Help{ | ||
{ | ||
"jira issues single", | ||
"creates a slack response for each crm sale which will start, the placeholders will be replaced respectively", | ||
[]string{ | ||
"jira single <project:crm><issuetype:Campaign><offset-field:Start Time><offset-time:18h><jql>“Campaign Category” = Sale</jql><sort:starttime><title>A sale will start in %component% %date% at %time% : %summary%</title><time:90h>", | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
module github.com/tigerteufel85/boggy | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/imdario/mergo v0.3.7 | ||
github.com/nlopes/slack v0.5.0 | ||
gopkg.in/andygrunwald/go-jira.v1 v1.6.0 | ||
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 | ||
gopkg.in/yaml.v2 v2.2.2 | ||
) | ||
|
||
require ( | ||
github.com/ae6rt/retry v2.0.0+incompatible // indirect | ||
github.com/blend/go-sdk v1.1.1 // indirect | ||
github.com/fatih/structs v1.1.0 // indirect | ||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect | ||
github.com/google/go-querystring v1.0.0 // indirect | ||
github.com/gorilla/websocket v1.4.0 // indirect | ||
github.com/imdario/mergo v0.3.7 | ||
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 // indirect | ||
github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6 // indirect | ||
github.com/nlopes/slack v0.5.0 | ||
github.com/pkg/errors v0.8.1 // indirect | ||
github.com/stretchr/testify v1.3.0 // indirect | ||
github.com/trivago/tgo v1.0.5 // indirect | ||
github.com/wcharczuk/go-chart v2.0.1+incompatible | ||
github.com/xoom/stash v1.3.1 | ||
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2 // indirect | ||
gopkg.in/andygrunwald/go-jira.v1 v1.6.0 | ||
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 | ||
gopkg.in/yaml.v2 v2.2.2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.