- 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 {
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
}
// 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 (
git, gitBuild *domain.Git
cloud *domain.Folder
@ -63,17 +50,17 @@ func (wc *WorkflowController) Workflow(name string) (string, error) {
go func(ref **domain.Git) {
defer wg.Done()
*ref, _ = wc.iGit.CreateRepo(issue.Key)
*ref, _ = wc.iGit.CreateRepo(appKey)
}(&git)
go func(ref **domain.Git) {
defer wg.Done()
*ref, _ = wc.iGit.CreateRepo(issue.Key + "-build")
*ref, _ = wc.iGit.CreateRepo(appKey + "-build")
}(&gitBuild)
go func(ref **domain.Folder) {
defer wg.Done()
*ref, _ = wc.iCloud.CreateFolder(issue.Key + " - " + issue.Summary)
*ref, _ = wc.iCloud.CreateFolder(appKey)
}(&cloud)
wg.Wait()
@ -99,19 +86,12 @@ func (wc *WorkflowController) Workflow(name string) (string, error) {
}
wc.iCoda.CreateApp(domain.CodaApplication{
ID: issue.Key,
ID: appKey,
Summary: strings.TrimSpace(name),
Git: gitResult,
GitBuild: gitBuildResult,
Folder: cloudResult,
})
yt.UpdateIssue(
issue,
cloudResult,
gitResult,
gitBuildResult,
)
}
return issue.Key, nil
return appKey, nil
}

View File

@ -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,7 +41,7 @@ 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)),
name,
" has been created!",
),
)

View File

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

View File

@ -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("<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)
}

View File

@ -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)