diff --git a/bot/controller/controller.go b/bot/controller/controller.go
index 8d90272..21226aa 100644
--- a/bot/controller/controller.go
+++ b/bot/controller/controller.go
@@ -33,85 +33,65 @@ func NewWorkflowController(
}
type IWorkflowController interface {
- Workflow(name string) (string, error)
+ Workflow(name, key, id string) (string, error)
}
-func (wc *WorkflowController) Workflow(name string) (string, error) {
- // coda := wc.iCoda
+func (wc *WorkflowController) Workflow(name, key, id string) (string, error) {
- yt := wc.iYouTrack
+ appKey := fmt.Sprintf("%s-%s", key, id)
- projectID, err := yt.GetProjectIDByName("tst")
- if err != nil {
- return "", err
+ var (
+ git, gitBuild *domain.Git
+ cloud *domain.Folder
+ )
+
+ var wg sync.WaitGroup
+ wg.Add(3)
+
+ go func(ref **domain.Git) {
+ defer wg.Done()
+ *ref, _ = wc.iGit.CreateRepo(appKey)
+ }(&git)
+
+ go func(ref **domain.Git) {
+ defer wg.Done()
+ *ref, _ = wc.iGit.CreateRepo(appKey + "-build")
+ }(&gitBuild)
+
+ go func(ref **domain.Folder) {
+ defer wg.Done()
+ *ref, _ = wc.iCloud.CreateFolder(appKey)
+ }(&cloud)
+
+ wg.Wait()
+
+ var gitResult, gitBuildResult, cloudResult string
+
+ if git == nil {
+ gitResult = "cannot create git"
+ } else {
+ gitResult = git.HtmlUrl
}
- // Create an issue at the available project with the provided name
- issue, err := yt.CreateIssue(projectID, name, "")
- if err != nil {
- return "", err
+ if gitBuild == nil {
+ gitBuildResult = "cannot create git"
+ } else {
+ gitBuildResult = fmt.Sprintf("ssh://%s/%s.git", gitBuild.SshUrl, gitBuild.FullName)
}
- if issue != nil {
- var (
- git, gitBuild *domain.Git
- cloud *domain.Folder
- )
-
- var wg sync.WaitGroup
- wg.Add(3)
-
- go func(ref **domain.Git) {
- defer wg.Done()
- *ref, _ = wc.iGit.CreateRepo(issue.Key)
- }(&git)
-
- go func(ref **domain.Git) {
- defer wg.Done()
- *ref, _ = wc.iGit.CreateRepo(issue.Key + "-build")
- }(&gitBuild)
-
- go func(ref **domain.Folder) {
- defer wg.Done()
- *ref, _ = wc.iCloud.CreateFolder(issue.Key + " - " + issue.Summary)
- }(&cloud)
-
- wg.Wait()
-
- var gitResult, gitBuildResult, cloudResult string
-
- if git == nil {
- gitResult = "cannot create git"
- } else {
- gitResult = git.HtmlUrl
- }
-
- if gitBuild == nil {
- gitBuildResult = "cannot create git"
- } else {
- gitBuildResult = fmt.Sprintf("ssh://%s/%s.git", gitBuild.SshUrl, gitBuild.FullName)
- }
-
- if cloud == nil {
- cloudResult = "cannot create folder"
- } else {
- cloudResult = cloud.PrivateURL
- }
-
- wc.iCoda.CreateApp(domain.CodaApplication{
- ID: issue.Key,
- Summary: strings.TrimSpace(name),
- Git: gitResult,
- GitBuild: gitBuildResult,
- Folder: cloudResult,
- })
-
- yt.UpdateIssue(
- issue,
- cloudResult,
- gitResult,
- gitBuildResult,
- )
+ if cloud == nil {
+ cloudResult = "cannot create folder"
+ } else {
+ cloudResult = cloud.PrivateURL
}
- return issue.Key, nil
+
+ wc.iCoda.CreateApp(domain.CodaApplication{
+ ID: appKey,
+ Summary: strings.TrimSpace(name),
+ Git: gitResult,
+ GitBuild: gitBuildResult,
+ Folder: cloudResult,
+ })
+
+ return appKey, nil
}
diff --git a/bot/handler/application.go b/bot/handler/application.go
index b44b9d7..e9fb9ab 100644
--- a/bot/handler/application.go
+++ b/bot/handler/application.go
@@ -3,7 +3,7 @@ package handler
import (
"context"
"errors"
- "fmt"
+ "strconv"
"strings"
"github.com/mr-linch/go-tg"
@@ -18,7 +18,7 @@ func (h *Handler) DevelopmentTaskHandler(ctx context.Context, mu *tgb.MessageUpd
return errors.New("empty command provided")
}
- issueKeyStr, err := h.workflow.Workflow(str)
+ issueKeyStr, err := h.workflow.Workflow(str, h.key, h.id)
if err != nil {
answer := errorAnswer(err.Error())
@@ -26,6 +26,12 @@ func (h *Handler) DevelopmentTaskHandler(ctx context.Context, mu *tgb.MessageUpd
return mu.Answer(answer).ParseMode(tg.HTML).DoVoid(ctx)
}
+ i, err := strconv.Atoi(h.id)
+ if err != nil {
+ return errors.New("problem with conversion id to int")
+ }
+ h.id = strconv.Itoa(i + 1)
+
answer := newTicketAnswer(issueKeyStr)
h.LogMessage(ctx, mu, answer)
return mu.Answer(answer).ParseMode(tg.HTML).DoVoid(ctx)
@@ -35,8 +41,8 @@ func newTicketAnswer(name string) string {
return tg.HTML.Text(
tg.HTML.Line(
"🤘 Ticket ",
- tg.HTML.Link(name, fmt.Sprintf("https://marlerino.youtrack.cloud/issue/%s", name)),
- "has been created!",
+ name,
+ " has been created!",
),
)
}
diff --git a/bot/handler/handler.go b/bot/handler/handler.go
index 15496fb..985046b 100644
--- a/bot/handler/handler.go
+++ b/bot/handler/handler.go
@@ -10,6 +10,8 @@ type Handler struct {
git services.IGit
cloud services.ICloud
coda services.ICoda
+ key string
+ id string
}
func NewHandler(
diff --git a/bot/handler/init.go b/bot/handler/init.go
index e681606..c01ad4c 100644
--- a/bot/handler/init.go
+++ b/bot/handler/init.go
@@ -6,6 +6,7 @@ import (
"log"
"os"
"strconv"
+ "strings"
"github.com/mr-linch/go-tg"
"github.com/mr-linch/go-tg/tgb"
@@ -15,7 +16,7 @@ func (h *Handler) LogMessage(ctx context.Context, mu *tgb.MessageUpdate, msg str
env := os.Getenv("TGSPAM")
id, err := strconv.ParseInt(env, 10, 64)
- if err == nil {
+ if err != nil {
log.Println("fatal while parsing chatID")
}
@@ -29,8 +30,18 @@ func (h *Handler) Init(ctx context.Context, mu *tgb.MessageUpdate) error {
peer := mu.Chat.ID.PeerID()
if mu.From.ID == 2532580 {
+ str := strings.TrimSpace(strings.Replace(mu.Text, "/init", "", 1))
+ params := strings.Split(str, " ")
+ if len(params) != 2 {
+ answer := "invalid params set"
+ return mu.Answer(answer).ReplyToMessageID(msgID).ParseMode(tg.HTML).DoVoid(ctx)
+ }
+
+ h.key = params[0]
+ h.id = params[1]
+
os.Setenv("TGSPAM", peer)
- answer := fmt.Sprintf("this chat (%s) is now a logger chat", peer)
+ answer := fmt.Sprintf("this chat (%s) is now a logger chat and next key is %s", peer, h.key+"-"+h.id)
return mu.Answer(answer).ReplyToMessageID(msgID).ParseMode(tg.HTML).DoVoid(ctx)
}
diff --git a/internal/services/coda.go b/internal/services/coda.go
index 0e1f926..b62b8cb 100644
--- a/internal/services/coda.go
+++ b/internal/services/coda.go
@@ -3,6 +3,7 @@ package services
import (
"fmt"
"log"
+ "os"
"ticket-pimp/internal/domain"
"time"
@@ -56,6 +57,7 @@ func (c *Coda) CreateApp(task domain.CodaApplication) {
resp, _ := c.R().
SetBody(task).
SetContentType("application/json").
+ SetBearerAuthToken(os.Getenv("CODA_TOKEN2")).
Post("/docs/Ic3IZpQ3Wk/hooks/automation/grid-auto-NlUwM7F7Cr")
fmt.Print(resp)