- move application tasks into coda;

This commit is contained in:
Volkomurov 2023-09-06 18:58:49 +05:00
parent ec5d95586c
commit abee9880e1
5 changed files with 79 additions and 78 deletions

View File

@ -33,26 +33,13 @@ func NewWorkflowController(
} }
type IWorkflowController interface { type IWorkflowController interface {
Workflow(name string) (string, error) Workflow(name, key, id string) (string, error)
} }
func (wc *WorkflowController) Workflow(name string) (string, error) { func (wc *WorkflowController) Workflow(name, key, id string) (string, error) {
// coda := wc.iCoda
yt := wc.iYouTrack appKey := fmt.Sprintf("%s-%s", key, id)
projectID, err := yt.GetProjectIDByName("tst")
if err != nil {
return "", err
}
// Create an issue at the available project with the provided name
issue, err := yt.CreateIssue(projectID, name, "")
if err != nil {
return "", err
}
if issue != nil {
var ( var (
git, gitBuild *domain.Git git, gitBuild *domain.Git
cloud *domain.Folder cloud *domain.Folder
@ -63,17 +50,17 @@ func (wc *WorkflowController) Workflow(name string) (string, error) {
go func(ref **domain.Git) { go func(ref **domain.Git) {
defer wg.Done() defer wg.Done()
*ref, _ = wc.iGit.CreateRepo(issue.Key) *ref, _ = wc.iGit.CreateRepo(appKey)
}(&git) }(&git)
go func(ref **domain.Git) { go func(ref **domain.Git) {
defer wg.Done() defer wg.Done()
*ref, _ = wc.iGit.CreateRepo(issue.Key + "-build") *ref, _ = wc.iGit.CreateRepo(appKey + "-build")
}(&gitBuild) }(&gitBuild)
go func(ref **domain.Folder) { go func(ref **domain.Folder) {
defer wg.Done() defer wg.Done()
*ref, _ = wc.iCloud.CreateFolder(issue.Key + " - " + issue.Summary) *ref, _ = wc.iCloud.CreateFolder(appKey)
}(&cloud) }(&cloud)
wg.Wait() wg.Wait()
@ -99,19 +86,12 @@ func (wc *WorkflowController) Workflow(name string) (string, error) {
} }
wc.iCoda.CreateApp(domain.CodaApplication{ wc.iCoda.CreateApp(domain.CodaApplication{
ID: issue.Key, ID: appKey,
Summary: strings.TrimSpace(name), Summary: strings.TrimSpace(name),
Git: gitResult, Git: gitResult,
GitBuild: gitBuildResult, GitBuild: gitBuildResult,
Folder: cloudResult, Folder: cloudResult,
}) })
yt.UpdateIssue( return appKey, nil
issue,
cloudResult,
gitResult,
gitBuildResult,
)
}
return issue.Key, nil
} }

View File

@ -3,7 +3,7 @@ package handler
import ( import (
"context" "context"
"errors" "errors"
"fmt" "strconv"
"strings" "strings"
"github.com/mr-linch/go-tg" "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") 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 { if err != nil {
answer := errorAnswer(err.Error()) 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) 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) answer := newTicketAnswer(issueKeyStr)
h.LogMessage(ctx, mu, answer) h.LogMessage(ctx, mu, answer)
return mu.Answer(answer).ParseMode(tg.HTML).DoVoid(ctx) return mu.Answer(answer).ParseMode(tg.HTML).DoVoid(ctx)
@ -35,8 +41,8 @@ func newTicketAnswer(name string) string {
return tg.HTML.Text( return tg.HTML.Text(
tg.HTML.Line( tg.HTML.Line(
"🤘 Ticket ", "🤘 Ticket ",
tg.HTML.Link(name, fmt.Sprintf("https://marlerino.youtrack.cloud/issue/%s", name)), name,
"has been created!", " has been created!",
), ),
) )
} }

View File

@ -10,6 +10,8 @@ type Handler struct {
git services.IGit git services.IGit
cloud services.ICloud cloud services.ICloud
coda services.ICoda coda services.ICoda
key string
id string
} }
func NewHandler( func NewHandler(

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"os" "os"
"strconv" "strconv"
"strings"
"github.com/mr-linch/go-tg" "github.com/mr-linch/go-tg"
"github.com/mr-linch/go-tg/tgb" "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") env := os.Getenv("TGSPAM")
id, err := strconv.ParseInt(env, 10, 64) id, err := strconv.ParseInt(env, 10, 64)
if err == nil { if err != nil {
log.Println("fatal while parsing chatID") 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() peer := mu.Chat.ID.PeerID()
if mu.From.ID == 2532580 { 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) os.Setenv("TGSPAM", peer)
answer := fmt.Sprintf("<i>this chat (%s) is now a logger chat</i>", peer) answer := fmt.Sprintf("<i>this chat (%s) is now a logger chat</i> and next key is %s", peer, h.key+"-"+h.id)
return mu.Answer(answer).ReplyToMessageID(msgID).ParseMode(tg.HTML).DoVoid(ctx) return mu.Answer(answer).ReplyToMessageID(msgID).ParseMode(tg.HTML).DoVoid(ctx)
} }

View File

@ -3,6 +3,7 @@ package services
import ( import (
"fmt" "fmt"
"log" "log"
"os"
"ticket-pimp/internal/domain" "ticket-pimp/internal/domain"
"time" "time"
@ -56,6 +57,7 @@ func (c *Coda) CreateApp(task domain.CodaApplication) {
resp, _ := c.R(). resp, _ := c.R().
SetBody(task). SetBody(task).
SetContentType("application/json"). SetContentType("application/json").
SetBearerAuthToken(os.Getenv("CODA_TOKEN2")).
Post("/docs/Ic3IZpQ3Wk/hooks/automation/grid-auto-NlUwM7F7Cr") Post("/docs/Ic3IZpQ3Wk/hooks/automation/grid-auto-NlUwM7F7Cr")
fmt.Print(resp) fmt.Print(resp)