- additional: removed yt mentions
This commit is contained in:
parent
05e18ce182
commit
6f4b9f2743
|
|
@ -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,
|
||||
|
|
|
|||
11
cmd/main.go
11
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,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
Loading…
Reference in New Issue