- move application tasks into coda;
This commit is contained in:
parent
ec5d95586c
commit
abee9880e1
|
|
@ -33,85 +33,65 @@ 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")
|
var (
|
||||||
if err != nil {
|
git, gitBuild *domain.Git
|
||||||
return "", err
|
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
|
if gitBuild == nil {
|
||||||
issue, err := yt.CreateIssue(projectID, name, "")
|
gitBuildResult = "cannot create git"
|
||||||
if err != nil {
|
} else {
|
||||||
return "", err
|
gitBuildResult = fmt.Sprintf("ssh://%s/%s.git", gitBuild.SshUrl, gitBuild.FullName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue != nil {
|
if cloud == nil {
|
||||||
var (
|
cloudResult = "cannot create folder"
|
||||||
git, gitBuild *domain.Git
|
} else {
|
||||||
cloud *domain.Folder
|
cloudResult = cloud.PrivateURL
|
||||||
)
|
|
||||||
|
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return issue.Key, nil
|
|
||||||
|
wc.iCoda.CreateApp(domain.CodaApplication{
|
||||||
|
ID: appKey,
|
||||||
|
Summary: strings.TrimSpace(name),
|
||||||
|
Git: gitResult,
|
||||||
|
GitBuild: gitBuildResult,
|
||||||
|
Folder: cloudResult,
|
||||||
|
})
|
||||||
|
|
||||||
|
return appKey, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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!",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue