package controller import ( "fmt" "strings" "sync" "ticket-pimp/internal/domain" "ticket-pimp/internal/services" ) type WorkflowController struct { iGit services.IGit iCloud services.ICloud iYouTrack services.IYouTrack additionalYT services.IYouTrack iCoda services.ICoda } func NewWorkflowController( git services.IGit, cloud services.ICloud, devyt services.IYouTrack, farmyt services.IYouTrack, coda services.ICoda, ) *WorkflowController { return &WorkflowController{ iGit: git, iCloud: cloud, iYouTrack: devyt, additionalYT: farmyt, iCoda: coda, } } type IWorkflowController interface { Workflow(name string) (string, error) } func (wc *WorkflowController) Workflow(name string) (string, error) { // coda := wc.iCoda yt := wc.iYouTrack 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 ) 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 }