71 lines
1.3 KiB
Go
71 lines
1.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
"ticket-pimp/bot/domain"
|
|
)
|
|
|
|
func (wc *WorkflowController) Workflow(name string) (string, error) {
|
|
coda := wc.iCoda
|
|
|
|
yt := wc.iYouTrack
|
|
|
|
projectID, err := yt.GetProjectIDByName("APP")
|
|
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
|
|
)
|
|
|
|
var wg sync.WaitGroup
|
|
wg.Add(3)
|
|
|
|
go func(ref **domain.Git) {
|
|
defer wg.Done()
|
|
*ref, _ = wc.CreateRepo(issue.Key)
|
|
}(&git)
|
|
|
|
go func(ref **domain.Git) {
|
|
defer wg.Done()
|
|
*ref, _ = wc.CreateRepo(issue.Key + "-build")
|
|
}(&gitBuild)
|
|
|
|
go func(ref **domain.Folder) {
|
|
defer wg.Done()
|
|
*ref, _ = wc.CreateFolder(issue.Key + " - " + issue.Summary)
|
|
}(&cloud)
|
|
|
|
wg.Wait()
|
|
|
|
taskDraft := domain.CodaIssue{
|
|
ID: issue.ID,
|
|
Summary: name,
|
|
URL: "",
|
|
Git: git.HtmlUrl,
|
|
GitBuild: fmt.Sprintf("ssh://%s/%s.git", gitBuild.SshUrl, gitBuild.FullName),
|
|
Folder: cloud.PrivateURL,
|
|
}
|
|
|
|
coda.CreateTask(taskDraft)
|
|
|
|
yt.UpdateIssue(
|
|
issue,
|
|
cloud.PrivateURL,
|
|
git.HtmlUrl,
|
|
fmt.Sprintf("ssh://%s/%s.git", gitBuild.SshUrl, gitBuild.FullName))
|
|
}
|
|
return issue.Key, nil
|
|
}
|