add coda webhook usage;

add apline version to dockerfile;
This commit is contained in:
naudachu 2023-08-22 15:34:54 +05:00
parent 15cf91aeef
commit dc6109844f
4 changed files with 43 additions and 8 deletions

View File

@ -1,4 +1,4 @@
FROM golang:alpine as app-builder FROM golang:1.20-alpine as app-builder
WORKDIR $GOPATH/src/ticket-pimp/ WORKDIR $GOPATH/src/ticket-pimp/
COPY . . COPY . .
RUN apk add git RUN apk add git

View File

@ -3,10 +3,12 @@ package controller
import ( import (
"fmt" "fmt"
"sync" "sync"
d "ticket-pimp/bot/domain" "ticket-pimp/bot/domain"
) )
func (wc *WorkflowController) Workflow(name string) (string, error) { func (wc *WorkflowController) Workflow(name string) (string, error) {
coda := wc.iCoda
yt := wc.iYouTrack yt := wc.iYouTrack
projectID, err := yt.GetProjectIDByName("APP") projectID, err := yt.GetProjectIDByName("APP")
@ -23,30 +25,41 @@ func (wc *WorkflowController) Workflow(name string) (string, error) {
if issue != nil { if issue != nil {
var ( var (
git, gitBuild *d.Git git, gitBuild *domain.Git
cloud *d.Folder cloud *domain.Folder
) )
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(3) wg.Add(3)
go func(ref **d.Git) { go func(ref **domain.Git) {
defer wg.Done() defer wg.Done()
*ref, _ = wc.CreateRepo(issue.Key) *ref, _ = wc.CreateRepo(issue.Key)
}(&git) }(&git)
go func(ref **d.Git) { go func(ref **domain.Git) {
defer wg.Done() defer wg.Done()
*ref, _ = wc.CreateRepo(issue.Key + "-build") *ref, _ = wc.CreateRepo(issue.Key + "-build")
}(&gitBuild) }(&gitBuild)
go func(ref **d.Folder) { go func(ref **domain.Folder) {
defer wg.Done() defer wg.Done()
*ref, _ = wc.CreateFolder(issue.Key + " - " + issue.Summary) *ref, _ = wc.CreateFolder(issue.Key + " - " + issue.Summary)
}(&cloud) }(&cloud)
wg.Wait() 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( yt.UpdateIssue(
issue, issue,
cloud.PrivateURL, cloud.PrivateURL,

10
bot/domain/coda.go Normal file
View File

@ -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"`
}

View File

@ -1,7 +1,9 @@
package ext package ext
import ( import (
"fmt"
"log" "log"
"ticket-pimp/bot/domain"
"time" "time"
) )
@ -11,13 +13,14 @@ type Coda struct {
type ICoda interface { type ICoda interface {
ListDocs() ListDocs()
CreateTask(task domain.CodaIssue)
} }
func NewCodaClient() *Coda { func NewCodaClient() *Coda {
client := NewClient(). client := NewClient().
SetTimeout(5 * time.Second). SetTimeout(5 * time.Second).
SetCommonBearerAuthToken("f54477f0-98ca-4285-844f-9fa2ef34475d"). SetCommonBearerAuthToken("0d5a6853-8bb1-4208-9014-318094f5b21c").
SetBaseURL("https://coda.io/apis/v1") SetBaseURL("https://coda.io/apis/v1")
return &Coda{ return &Coda{
@ -47,3 +50,12 @@ func (c *Coda) ListDocs() {
log.Print(resp) 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)
}