From dc6109844f3cb2cb5253fb74a352142985a142d0 Mon Sep 17 00:00:00 2001 From: naudachu Date: Tue, 22 Aug 2023 15:34:54 +0500 Subject: [PATCH] add coda webhook usage; add apline version to dockerfile; --- Dockerfile | 2 +- bot/controller/ticket-workflow.go | 25 +++++++++++++++++++------ bot/domain/coda.go | 10 ++++++++++ bot/ext/coda.go | 14 +++++++++++++- 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 bot/domain/coda.go diff --git a/Dockerfile b/Dockerfile index 53054ac..fa96389 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:alpine as app-builder +FROM golang:1.20-alpine as app-builder WORKDIR $GOPATH/src/ticket-pimp/ COPY . . RUN apk add git diff --git a/bot/controller/ticket-workflow.go b/bot/controller/ticket-workflow.go index fcbb5f1..fdfe5a2 100644 --- a/bot/controller/ticket-workflow.go +++ b/bot/controller/ticket-workflow.go @@ -3,10 +3,12 @@ package controller import ( "fmt" "sync" - d "ticket-pimp/bot/domain" + "ticket-pimp/bot/domain" ) func (wc *WorkflowController) Workflow(name string) (string, error) { + coda := wc.iCoda + yt := wc.iYouTrack projectID, err := yt.GetProjectIDByName("APP") @@ -23,30 +25,41 @@ func (wc *WorkflowController) Workflow(name string) (string, error) { if issue != nil { var ( - git, gitBuild *d.Git - cloud *d.Folder + git, gitBuild *domain.Git + cloud *domain.Folder ) var wg sync.WaitGroup wg.Add(3) - go func(ref **d.Git) { + go func(ref **domain.Git) { defer wg.Done() *ref, _ = wc.CreateRepo(issue.Key) }(&git) - go func(ref **d.Git) { + go func(ref **domain.Git) { defer wg.Done() *ref, _ = wc.CreateRepo(issue.Key + "-build") }(&gitBuild) - go func(ref **d.Folder) { + 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, diff --git a/bot/domain/coda.go b/bot/domain/coda.go new file mode 100644 index 0000000..361bb0d --- /dev/null +++ b/bot/domain/coda.go @@ -0,0 +1,10 @@ +package domain + +type CodaIssue struct { + ID string `json:"id"` + Summary string `json:"summary"` + URL string `json:"url"` + Git string `json:"git"` + GitBuild string `json:"git-build"` + Folder string `json:"folder"` +} diff --git a/bot/ext/coda.go b/bot/ext/coda.go index 5af59d3..1522fcb 100644 --- a/bot/ext/coda.go +++ b/bot/ext/coda.go @@ -1,7 +1,9 @@ package ext import ( + "fmt" "log" + "ticket-pimp/bot/domain" "time" ) @@ -11,13 +13,14 @@ type Coda struct { type ICoda interface { ListDocs() + CreateTask(task domain.CodaIssue) } func NewCodaClient() *Coda { client := NewClient(). SetTimeout(5 * time.Second). - SetCommonBearerAuthToken("f54477f0-98ca-4285-844f-9fa2ef34475d"). + SetCommonBearerAuthToken("0d5a6853-8bb1-4208-9014-318094f5b21c"). SetBaseURL("https://coda.io/apis/v1") return &Coda{ @@ -47,3 +50,12 @@ func (c *Coda) ListDocs() { log.Print(resp) } + +func (c *Coda) CreateTask(task domain.CodaIssue) { + resp, _ := c.R(). + SetBody(task). + SetContentType("application/json"). + Post("/docs/Ic3IZpQ3Wk/hooks/automation/grid-auto-NlUwM7F7Cr") + + fmt.Print(resp) +}