diff --git a/Dockerfile b/Dockerfile index f69a1c9..9b75311 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,6 @@ RUN apk add git RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install -ldflags '-extldflags "-static"' -tags timetzdata ./cmd/main.go FROM scratch -# the test program: COPY --from=app-builder /go/bin/main /ticket-pimp COPY --from=app-builder /go/src/ticket-pimp/cmd/prod.env / # the tls certificates: diff --git a/discord/discord.go b/discord/discord.go index c2db60a..911569d 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -12,12 +12,12 @@ import ( "github.com/bwmarrin/discordgo" ) -func initBotWith(token string) (*discordgo.Session, error) { +func initBotWith(token string) *discordgo.Session { discord, err := discordgo.New("Bot " + token) if err != nil { - return nil, err + log.Fatalf("unable to create discord session: %v", err) } - return discord, nil + return discord } type DiscordOptions struct { @@ -28,10 +28,7 @@ type DiscordOptions struct { func Run(conf domain.Config, opts DiscordOptions) error { token := conf.Discord.Token - session, err := initBotWith(token) - if err != nil { - return err - } + session := initBotWith(token) router := handler.InitRouter(*opts.Controller) @@ -41,7 +38,6 @@ func Run(conf domain.Config, opts DiscordOptions) error { } session.AddHandler(func(s *discordgo.Session, i *discordgo.InteractionCreate) { - if h, ok := commandHandlers[i.ApplicationCommandData().Name]; ok { h(s, i) } @@ -73,7 +69,7 @@ func Run(conf domain.Config, opts DiscordOptions) error { log.Println("Removing commands...") for _, h := range cmds { - err = session.ApplicationCommandDelete(session.State.User.ID, "", h.ID) + err := session.ApplicationCommandDelete(session.State.User.ID, "", h.ID) if err != nil { log.Panicf("Cannot delete '%v' command: %v", h.Name, err) } diff --git a/discord/handler/handle_folder.go b/discord/handler/handle_folder.go new file mode 100644 index 0000000..fd69214 --- /dev/null +++ b/discord/handler/handle_folder.go @@ -0,0 +1,100 @@ +package handler + +import ( + "context" + "fmt" + "log" + "strconv" + + "github.com/bwmarrin/discordgo" +) + +func (h *router) CreateFolderHandler(nameMinLenght int) route { + const ( + nameOption string = "folder_name" + ) + return route{ + + Command: discordgo.ApplicationCommand{ + Name: "folder", + Description: "Command for cloud folder creation", + Options: []*discordgo.ApplicationCommandOption{ + { + Type: discordgo.ApplicationCommandOptionString, + Name: nameOption, + Description: "Type the folder's name", + Required: false, + MinLength: &nameMinLenght, + }, + }, + }, + + Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { + initialResponse := discordgo.InteractionResponse{ + // Ignore type for now, they will be discussed in "responses" + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Flags: discordgo.MessageFlagsEphemeral, + Content: "..folder is going to be created", + Title: "πŸ“‚ Folder creation", + }, + } + + s.InteractionRespond(i.Interaction, &initialResponse) + + var result string = "unexpected result" + + options := i.ApplicationCommandData().Options + + optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options)) + for _, opt := range options { + optionMap[opt.Name] = opt + } + + var str string = "" + + dchan, err := s.Channel(i.ChannelID) + + if err != nil { + log.Printf("error while identifying channel: %v", err) + } + + if dchan.ParentID == strconv.Itoa(1150719794853716028) { + log.Println("yes, channel is from `Projects`") + project, err := h.controller.GetProjectByChannelID(context.TODO(), i.ChannelID) + if err != nil { + result = fmt.Sprintf("unable to retrieve project from db, error: %v", err) + } else { + switch { + case project == nil: + if option, ok := optionMap[nameOption]; ok { + str = option.StringValue() + } else { + str = "Π’Ρ‹, Π»ΠΈΠ±ΠΎ Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π΅ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΎΡ€ΠΈΡŽ создавай, Π»ΠΈΠ±ΠΎ имя напиши, Π±Π»Π΅Ρ‚!" + } + default: + str = project.ShortName + } + + resp := h.controller.ICloud.CreateFolder(str) + if resp.ErrMessage != nil { + result = fmt.Sprintf("Command executed w/ errors: ``` %v``` \n But check this link: %s\n", resp.ErrMessage, resp.Folder.PrivateURL) + } else { + result = fmt.Sprintf("πŸ“‚ Folder was created: %s", resp.Folder.PrivateURL) + } + } + + _, err = s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{ + Content: result, + }) + + if err != nil { + s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{ + Content: fmt.Sprintf("Something went wrong: %v", err), + }) + return + } + } + }, + } +} diff --git a/discord/handler/handle_ping.go b/discord/handler/handle_ping.go new file mode 100644 index 0000000..b44b88c --- /dev/null +++ b/discord/handler/handle_ping.go @@ -0,0 +1,30 @@ +package handler + +import ( + "log" + + "github.com/bwmarrin/discordgo" +) + +func (h *router) Ping() route { + return route{ + Command: discordgo.ApplicationCommand{ + Name: "ping", + Description: "pongs in a reply", + }, + Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { + log.Println("ok, I'm here..") + + err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Content: "`pong`", + Title: "Pong reply", + }, + }) + if err != nil { + log.Println(err) + } + }, + } +} diff --git a/discord/handler/handle_repo.go b/discord/handler/handle_repo.go new file mode 100644 index 0000000..a62d7fa --- /dev/null +++ b/discord/handler/handle_repo.go @@ -0,0 +1,109 @@ +package handler + +import ( + "context" + "fmt" + + "github.com/bwmarrin/discordgo" +) + +func (h *router) CreateRepoHandler(repoNameMinLength int) route { + const ( + projectRepo = "project_repo" + buildRepo = "build_repo" + ) + + return route{ + Command: discordgo.ApplicationCommand{ + Name: "repo", + Description: "Command for repository creation", + Options: []*discordgo.ApplicationCommandOption{ + { + Type: discordgo.ApplicationCommandOptionString, + Name: "repo_type", + Description: "The type of repo", + Required: true, + Choices: []*discordgo.ApplicationCommandOptionChoice{ + { + Name: "Unity project repo", + Value: projectRepo, + }, + { + Name: "XCode build repo", + Value: buildRepo, + }, + }, + }, + { + Type: discordgo.ApplicationCommandOptionString, + Name: "repo_name", + Description: "Type the repository's name", + Required: false, + MinLength: &repoNameMinLength, + }, + }, + }, + Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { + var result string + // Access options in the order provided by the user. + options := i.ApplicationCommandData().Options + + // Or convert the slice into a map + optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options)) + for _, opt := range options { + optionMap[opt.Name] = opt + } + + var str string = "" + + project, err := h.controller.GetProjectByChannelID(context.TODO(), i.ChannelID) + if err != nil { + result = fmt.Sprintf("unable to retrieve project from db, error: %v", err) + } else { + var suffix string + if option, ok := optionMap["repo_type"]; ok { + switch option.Value { + case projectRepo: + suffix = "" + case buildRepo: + suffix = "-build" + } + } + + if project == nil { + if option, ok := optionMap["repo_name"]; ok { + str = option.StringValue() + } else { + str = "" + } + } else { + str = project.ShortName + } + + if str == "" { + result = "Π’Ρ‹, Π»ΠΈΠ±ΠΎ Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π΅ Ρ€Π΅ΠΏΠΎ создавай, Π»ΠΈΠ±ΠΎ имя напиши, Π±Π»Π΅Ρ‚!" + } else { + str = str + suffix + + // var g *domain.Git + + g, err := h.controller.IGit.CreateRepo(str) + if err != nil { + result = fmt.Sprintf("error while repo creation: %v", err) + } else { + result = "πŸš€ " + g.HtmlUrl + " was created" + } + } + } + + resp := &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Content: result, + }, + } + + s.InteractionRespond(i.Interaction, resp) + }, + } +} diff --git a/discord/handler/handle_ticket.go b/discord/handler/handle_ticket.go new file mode 100644 index 0000000..1d1d0f6 --- /dev/null +++ b/discord/handler/handle_ticket.go @@ -0,0 +1,78 @@ +package handler + +import ( + "context" + "fmt" + "log" + "ticket-pimp/internal/domain" + + "github.com/bwmarrin/discordgo" +) + +func (h *router) CreateTicketHandler(repoNameMinLength int) route { + return route{ + Command: discordgo.ApplicationCommand{ + Name: "project", + Description: "Create new development ticket", + Options: []*discordgo.ApplicationCommandOption{ + { + Type: discordgo.ApplicationCommandOptionString, + Name: "project_name", + Description: "Temporary project name", + Required: true, + MinLength: &repoNameMinLength, + }, + }, + }, + Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { + var result string + // Access options in the order provided by the user. + options := i.ApplicationCommandData().Options + + // Or convert the slice into a map + optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options)) + for _, opt := range options { + optionMap[opt.Name] = opt + } + + if option, ok := optionMap["project_name"]; ok { + dchan, err := s.GuildChannelCreate(i.GuildID, option.StringValue(), discordgo.ChannelTypeGuildText) + if err != nil { + result = fmt.Sprintf("chan creation problem: %v\n", err) + } else { + p, err := h.controller.ProjectCreate(context.TODO(), domain.Project{ + ChannelID: dchan.ID, + }) + if err != nil { + result = fmt.Sprintf("unable to create project: %v\n", err) + } else { + edit := discordgo.ChannelEdit{ + Name: p.ShortName, + ParentID: "1150719794853716028", + } + + dchan, err = s.ChannelEdit(dchan.ID, &edit) + if err != nil { + result = fmt.Sprintf("channel created, but unable to edit: %v\n", err) + + } else { + _, err = s.ChannelMessageSend(dchan.ID, "Hello!") + if err != nil { + log.Printf("message send problem: %v\n", err) + } + result = dchan.ID + } + } + } + } + + s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + // Ignore type for now, they will be discussed in "responses" + Type: discordgo.InteractionResponseChannelMessageWithSource, + Data: &discordgo.InteractionResponseData{ + Content: result, + }, + }) + }, + } +} diff --git a/discord/handler/handler.go b/discord/handler/handler.go index b954eee..b1421c8 100644 --- a/discord/handler/handler.go +++ b/discord/handler/handler.go @@ -1,11 +1,7 @@ package handler import ( - "context" - "fmt" - "log" "ticket-pimp/internal/controller" - "ticket-pimp/internal/domain" "github.com/bwmarrin/discordgo" ) @@ -21,10 +17,10 @@ func InitRouter(wc controller.WorkflowController) *router { var r router r.Routes = append( r.Routes, - // r.CreateRepoHandler(3), + r.CreateRepoHandler(3), r.CreateFolderHandler(3), r.Ping(), - // r.CreateTicketHandler(3), + r.CreateTicketHandler(3), ) r.controller = wc @@ -35,284 +31,3 @@ type route struct { Command discordgo.ApplicationCommand Handler func(s *discordgo.Session, i *discordgo.InteractionCreate) } - -func (h *router) Ping() route { - return route{ - Command: discordgo.ApplicationCommand{ - Name: "ping", - Description: "pongs in a reply", - }, - Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - log.Println("ok, I'm here..") - - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseDeferredMessageUpdate, - Data: &discordgo.InteractionResponseData{ - Content: "`pong`", - Title: "Pong reply", - }, - }) - }, - } -} - -func (h *router) CreateFolderHandler(nameMinLenght int) route { - const ( - nameOption string = "folder_name" - ) - return route{ - Command: discordgo.ApplicationCommand{ - Name: "folder", - Description: "Command for cloud folder creation", - Options: []*discordgo.ApplicationCommandOption{ - { - Type: discordgo.ApplicationCommandOptionString, - Name: nameOption, - Description: "Type the folder's name", - Required: false, - MinLength: &nameMinLenght, - }, - }, - }, - Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - var result string - - resp := discordgo.InteractionResponse{ - - Type: discordgo.InteractionResponseUpdateMessage, - Data: &discordgo.InteractionResponseData{ - Content: "Folder is going to be created..", - }, - } - err := s.InteractionRespond(i.Interaction, &resp) - if err != nil { - log.Println(err) - return - } - - options := i.ApplicationCommandData().Options - - optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options)) - for _, opt := range options { - optionMap[opt.Name] = opt - } - - var str string = "" - - project, err := h.controller.GetProjectByChannelID(context.TODO(), i.ChannelID) - if err != nil { - result = fmt.Sprintf("unable to retrieve project from db, error: %v", err) - } else { - if project == nil { - if option, ok := optionMap[nameOption]; ok { - str = option.StringValue() - } else { - str = "" - } - } else { - str = project.ShortName - } - - if str == "" { - result = "Π’Ρ‹, Π»ΠΈΠ±ΠΎ Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π΅ Π΄ΠΈΡ€Π΅ΠΊΡ‚ΠΎΡ€ΠΈΡŽ создавай, Π»ΠΈΠ±ΠΎ имя напиши, Π±Π»Π΅Ρ‚!" - } else { - - f, err := h.controller.ICloud.CreateFolder(str) - if err != nil { - result = fmt.Sprintf("error while cloud folder creation: %v", err) - } else { - result = fmt.Sprint(f.PrivateURL) - } - } - } - - // resp = discordgo.InteractionResponse{ - // // Ignore type for now, they will be discussed in "responses" - // Type: discordgo.InteractionResponseUpdateMessage, - // Data: &discordgo.InteractionResponseData{ - // Content: result, - // Title: "πŸ“‚ Folder was created", - // }, - // } - - webhookEdit := discordgo.WebhookEdit{ - Content: &result, - } - s.InteractionResponseEdit(i.Interaction, &webhookEdit) - - // discerr := s.InteractionRespond(i.Interaction, &resp) - // if discerr != nil { - // log.Println(discerr) - // } - }, - } -} - -func (h *router) CreateRepoHandler(repoNameMinLength int) route { - const ( - projectRepo = "project_repo" - buildRepo = "build_repo" - ) - - return route{ - Command: discordgo.ApplicationCommand{ - Name: "repo", - Description: "Command for repository creation", - Options: []*discordgo.ApplicationCommandOption{ - { - Type: discordgo.ApplicationCommandOptionString, - Name: "repo_type", - Description: "The type of repo", - Required: true, - Choices: []*discordgo.ApplicationCommandOptionChoice{ - { - Name: "Unity project repo", - Value: projectRepo, - }, - { - Name: "XCode build repo", - Value: buildRepo, - }, - }, - }, - { - Type: discordgo.ApplicationCommandOptionString, - Name: "repo_name", - Description: "Type the repository's name", - Required: false, - MinLength: &repoNameMinLength, - }, - }, - }, - Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - var result string - // Access options in the order provided by the user. - options := i.ApplicationCommandData().Options - - // Or convert the slice into a map - optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options)) - for _, opt := range options { - optionMap[opt.Name] = opt - } - - var str string = "" - - project, err := h.controller.GetProjectByChannelID(context.TODO(), i.ChannelID) - if err != nil { - result = fmt.Sprintf("unable to retrieve project from db, error: %v", err) - } else { - var suffix string - if option, ok := optionMap["repo_type"]; ok { - switch option.Value { - case projectRepo: - suffix = "" - case buildRepo: - suffix = "-build" - } - } - - if project == nil { - if option, ok := optionMap["repo_name"]; ok { - str = option.StringValue() - } else { - str = "" - } - } else { - str = project.ShortName - } - - if str == "" { - result = "Π’Ρ‹, Π»ΠΈΠ±ΠΎ Π² ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π΅ Ρ€Π΅ΠΏΠΎ создавай, Π»ΠΈΠ±ΠΎ имя напиши, Π±Π»Π΅Ρ‚!" - } else { - str = str + suffix - - // var g *domain.Git - - g, err := h.controller.IGit.CreateRepo(str) - if err != nil { - result = fmt.Sprintf("error while repo creation: %v", err) - } else { - result = "πŸš€ " + g.HtmlUrl + " was created" - } - } - } - - resp := &discordgo.InteractionResponse{ - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: result, - }, - } - - s.InteractionRespond(i.Interaction, resp) - }, - } -} - -func (h *router) CreateTicketHandler(repoNameMinLength int) route { - return route{ - Command: discordgo.ApplicationCommand{ - Name: "project", - Description: "Create new development ticket", - Options: []*discordgo.ApplicationCommandOption{ - { - Type: discordgo.ApplicationCommandOptionString, - Name: "project_name", - Description: "Temporary project name", - Required: true, - MinLength: &repoNameMinLength, - }, - }, - }, - Handler: func(s *discordgo.Session, i *discordgo.InteractionCreate) { - var result string - // Access options in the order provided by the user. - options := i.ApplicationCommandData().Options - - // Or convert the slice into a map - optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options)) - for _, opt := range options { - optionMap[opt.Name] = opt - } - - if option, ok := optionMap["project_name"]; ok { - dchan, err := s.GuildChannelCreate(i.GuildID, option.StringValue(), discordgo.ChannelTypeGuildText) - if err != nil { - result = fmt.Sprintf("chan creation problem: %v\n", err) - } else { - p, err := h.controller.ProjectCreate(context.TODO(), domain.Project{ - ChannelID: dchan.ID, - }) - if err != nil { - result = fmt.Sprintf("unable to create project: %v\n", err) - } else { - edit := discordgo.ChannelEdit{ - Name: p.ShortName, - ParentID: "1150719794853716028", - } - - dchan, err = s.ChannelEdit(dchan.ID, &edit) - if err != nil { - result = fmt.Sprintf("channel created, but unable to edit: %v\n", err) - - } else { - _, err = s.ChannelMessageSend(dchan.ID, "Hello!") - if err != nil { - log.Printf("message send problem: %v\n", err) - } - result = dchan.ID - } - } - } - } - - s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ - // Ignore type for now, they will be discussed in "responses" - Type: discordgo.InteractionResponseChannelMessageWithSource, - Data: &discordgo.InteractionResponseData{ - Content: result, - }, - }) - }, - } -} diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 93a86d1..a804b29 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -61,7 +61,8 @@ func (wc *WorkflowController) FullProjectInit(name, key, id string) (string, err go func(ref **domain.Folder) { defer wg.Done() - *ref, _ = wc.ICloud.CreateFolder(appKey) + + *ref = wc.ICloud.CreateFolder(appKey).Folder }(&cloud) wg.Wait() diff --git a/internal/helpers/error_message.go b/internal/helpers/error_message.go new file mode 100644 index 0000000..970e15c --- /dev/null +++ b/internal/helpers/error_message.go @@ -0,0 +1,5 @@ +package helpers + +type ErrorMessage struct { + Message string `json:"message"` +} diff --git a/internal/helpers/helpers.go b/internal/helpers/helpers.go index 8a12bfd..9c600e0 100644 --- a/internal/helpers/helpers.go +++ b/internal/helpers/helpers.go @@ -7,7 +7,7 @@ import ( "strings" ) -func GitNaming(input string) string { +func ValidNaming(input string) string { // Remove leading and trailing whitespace input = strings.TrimSpace(input) diff --git a/internal/helpers/helpers_test.go b/internal/helpers/helpers_test.go index 3e877a4..53e8112 100644 --- a/internal/helpers/helpers_test.go +++ b/internal/helpers/helpers_test.go @@ -18,7 +18,7 @@ var tests = []test{ func TestGitNaming(t *testing.T) { for _, test := range tests { - if output := GitNaming(test.arg); output != test.expected { + if output := ValidNaming(test.arg); output != test.expected { t.Errorf("Output %q not equal to expected %q", output, test.expected) } } diff --git a/internal/services/cloud.go b/internal/services/cloud.go index 8c61a6f..2b3946a 100644 --- a/internal/services/cloud.go +++ b/internal/services/cloud.go @@ -2,7 +2,9 @@ package services import ( "fmt" + "log" "strconv" + "strings" "ticket-pimp/internal/domain" "ticket-pimp/internal/helpers" "time" @@ -14,7 +16,7 @@ type Cloud struct { } type ICloud interface { - CreateFolder(name string) (*domain.Folder, error) + CreateFolder(name string) Response } func NewCloud(conf domain.CloudConfig) *Cloud { @@ -32,40 +34,76 @@ func NewCloud(conf domain.CloudConfig) *Cloud { } } -func (c *Cloud) CreateFolder(name string) (*domain.Folder, error) { +type Response struct { + Folder *domain.Folder + ErrMessage error +} + +func (c *Cloud) CreateFolder(name string) Response { + var R Response + rootDir := c.Config.RootDir user := c.Config.User davPath := "/remote.php/dav/files/" parentPath := "/apps/files/?dir=" - name = helpers.GitNaming(name) + name = helpers.ValidNaming(name) - cloud := domain.Folder{ + R.Folder = &domain.Folder{ Title: name, PrivateURL: "", } + // cloud := domain.Folder{ + // Title: name, + // PrivateURL: "", + // } + requestPath := davPath + user + rootDir + name - cloud.PathTo = parentPath + rootDir + name + R.Folder.PathTo = parentPath + rootDir + name - resp, _ := c.R(). + var errMessage helpers.ErrorMessage + + resp, err := c.R(). + SetErrorResult(&errMessage). Send("MKCOL", requestPath) + if err != nil { // Error handling. + log.Println("error:", err) + + // Π₯Сровая ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ошибки: + // error while cloud folder creation: bad response, raw content: + // + // + // Sabre\DAV\Exception\MethodNotAllowed + // The resource you tried to create already exists + // + if strings.Contains(err.Error(), "already exists") { + R.Folder.PrivateURL = c.BaseURL + R.Folder.PathTo + R.ErrMessage = err + // Try to set short URL to the d entity + if err := c.setPrivateURL(requestPath, R.Folder); err != nil { + R.ErrMessage = err + return R + } + return R + } + return R + } + if resp.IsSuccessState() { // Set stupid URL to the d entity - cloud.PrivateURL = c.BaseURL + cloud.PathTo + R.Folder.PrivateURL = c.BaseURL + R.Folder.PathTo // Try to set short URL to the d entity - if err := c.setPrivateURL(requestPath, &cloud); err != nil { - return &cloud, err + if err := c.setPrivateURL(requestPath, R.Folder); err != nil { + return R } - } else { - fmt.Println(resp.Status) } - return &cloud, nil + return R } func (c *Cloud) setPrivateURL(requestPath string, cloud *domain.Folder) error { diff --git a/internal/services/git.go b/internal/services/git.go index 01388d6..0f1c1a7 100644 --- a/internal/services/git.go +++ b/internal/services/git.go @@ -55,7 +55,7 @@ type gitCreateRequest struct { } func (gb *Git) newRepo(name string) (*domain.Git, error) { - name = helpers.GitNaming(name) + name = helpers.ValidNaming(name) payload := gitCreateRequest{ Name: name, diff --git a/telegram/handler/handle_folder.go b/telegram/handler/handle_folder.go index 460d7af..fa88377 100644 --- a/telegram/handler/handle_folder.go +++ b/telegram/handler/handle_folder.go @@ -17,10 +17,10 @@ func (h *Handler) NewFolderHandler(ctx context.Context, mu *tgb.MessageUpdate) e return errors.New("empty command provided") } - cloud, err := h.cloud.CreateFolder(str) + resp := h.cloud.CreateFolder(str) - if err != nil { - answer := errorAnswer(err.Error()) + if resp.ErrMessage != nil { + answer := errorAnswer(resp.ErrMessage.Error()) h.LogMessage(ctx, mu, answer) return mu.Answer(answer).ParseMode(tg.HTML).DoVoid(ctx) } @@ -28,7 +28,7 @@ func (h *Handler) NewFolderHandler(ctx context.Context, mu *tgb.MessageUpdate) e answer := tg.HTML.Text( tg.HTML.Line( "✨ Shiny folder", - tg.HTML.Link(cloud.Title, cloud.PrivateURL), + tg.HTML.Link(resp.Folder.Title, resp.Folder.PrivateURL), "has been created!", ), ) diff --git a/telegram/telegram.go b/telegram/telegram.go index 521012d..83f6403 100644 --- a/telegram/telegram.go +++ b/telegram/telegram.go @@ -45,6 +45,7 @@ func Run(ctx context.Context, opts TelegramOptions) error { // Message(h.NewFolderHandler, tgb.TextHasPrefix("/folder")). Message(h.FarmTaskHandler, tgb.TextHasPrefix("/task")) + log.Print("Success init. Start poller.") return tgb.NewPoller( router, client,