diff --git a/bot/handler/handler.go b/bot/handler/handler.go index 985046b..d6c74aa 100644 --- a/bot/handler/handler.go +++ b/bot/handler/handler.go @@ -17,13 +17,11 @@ type Handler struct { func NewHandler( git services.IGit, cloud services.ICloud, - devyt services.IYouTrack, - farmyt services.IYouTrack, coda services.ICoda, ) *Handler { return &Handler{ - workflow: controller.NewWorkflowController(git, cloud, devyt, farmyt, coda), + workflow: controller.NewWorkflowController(git, cloud, coda), git: git, cloud: cloud, coda: coda, diff --git a/cmd/main.go b/cmd/main.go index 75b304f..15fbb6c 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -58,15 +58,6 @@ func runBot(ctx context.Context) error { os.Getenv("CLOUD_PASS"), ) - devYouTrackService := services.NewYT( - os.Getenv("YT_URL"), - os.Getenv("YT_TOKEN"), - ) - - farmYouTrackService := services.NewYT( - os.Getenv("YT_ADDITIONAL_URL"), - os.Getenv("YT_ADDITIONAL_TOKEN"), - ) coda := services.NewCodaClient( os.Getenv("CODA_TOKEN1"), ) @@ -74,8 +65,6 @@ func runBot(ctx context.Context) error { h := handler.NewHandler( gitService, cloudService, - devYouTrackService, - farmYouTrackService, coda, ) diff --git a/internal/services/yt.go b/internal/services/yt.go deleted file mode 100644 index 4db5fda..0000000 --- a/internal/services/yt.go +++ /dev/null @@ -1,146 +0,0 @@ -package services - -import ( - "fmt" - "log" - "time" - - "ticket-pimp/internal/domain" - - "github.com/imroc/req/v3" -) - -type youtrack struct { - *req.Client -} - -type IYouTrack interface { - GetProjectIDByName(searchName string) (string, error) - CreateIssue(projectID, name, description string) (*domain.IssueCreateRequest, error) - UpdateIssue(issue *domain.IssueCreateRequest, folder, git, gitBuild string) (*domain.IssueUpdateRequest, error) -} - -func NewYT(base, token string) *youtrack { - headers := map[string]string{ - "Accept": "application/json", - "Content-Type": "application/json", - } - - client := NewClient(). - SetTimeout(15 * time.Second). - SetCommonHeaders(headers). - SetBaseURL(base). - SetCommonBearerAuthToken(token) - - return &youtrack{ - client, - } -} - -// GetProjects -// provides an array of existing projects; -func (yt *youtrack) getProjects() (*domain.ProjectsList, error) { - - var projects domain.ProjectsList - - resp, _ := yt.R(). - EnableDump(). - SetQueryParam("fields", "id,name,shortName"). - SetSuccessResult(&projects.Projects). - Get("/admin/projects") - - // Check if the request failed; - if resp.Err != nil { - return nil, fmt.Errorf("some problem with YT request. error message: %v", resp.Err) - } - - return &projects, nil -} - -// GetProjects -// provides an array of existing projects; -func (yt *youtrack) GetProjectIDByName(searchName string) (string, error) { - - projects, err := yt.getProjects() - if err != nil { - return "", err - } - - projectID, err := projects.FindProjectByName(searchName) - if err != nil { - return "", err - } - - return projectID, nil -} - -// CreateIssue -// example: newIssue := yt.CreateIssue("0-2", "Summary", "Description"); -func (yt *youtrack) CreateIssue(projectID, name string, description string) (*domain.IssueCreateRequest, error) { - - // Create an issue with the provided:, Project ID, Name, Description; - issue := domain.IssueCreateRequest{ - ProjectID: domain.ProjectID{ - ID: projectID, //"id":"0-2" - }, - Summary: name, - Description: description, - } - - // Push issue to the YT; - resp, _ := yt.R(). - SetQueryParam("fields", "idReadable,id"). - SetBody(&issue). - SetSuccessResult(&issue). - Post("/issues") - - // Check if the request failed; - if resp.Err != nil { - return nil, fmt.Errorf("some problem with YT request. error message: %v", resp.Err) - } - - return &issue, nil -} - -func (yt *youtrack) UpdateIssue(issue *domain.IssueCreateRequest, folder, git, gitBuild string) (*domain.IssueUpdateRequest, error) { - // Set Folder, Git, GitBuild to the Issue: - update := domain.IssueUpdateRequest{ - IssueCreateRequest: *issue, - CustomFields: []domain.CustomField{ - { - Name: "Директория графики", - Type: "SimpleIssueCustomField", - Value: folder, - }, - { - Name: "Репо проекта", - Type: "SimpleIssueCustomField", - Value: git, - }, - { - Name: "Репо iOS сборки", - Type: "SimpleIssueCustomField", - Value: gitBuild, - }, - }, - } - - // Push issue update to YT - resp, _ := yt.R(). - SetBody(&update). - SetSuccessResult(&issue). - Post("/issues/" + issue.Key) - - // Check if the request failed; - if resp.Err != nil { - return nil, fmt.Errorf("some problem with YT request. error message: %v", resp.Err) - } - - if !resp.IsSuccessState() { - log.Print("bad status:", resp.Status) - log.Print(resp.Dump()) - return nil, fmt.Errorf("YouTrack responded with %d", resp.StatusCode) - } - - return &update, nil -}