- implemented discord /repo command
This commit is contained in:
parent
a496c1998d
commit
59d9fc567f
216
cmd/main.go
216
cmd/main.go
|
|
@ -8,212 +8,94 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"ticket-pimp/bot/handler"
|
|
||||||
"ticket-pimp/internal/controller"
|
|
||||||
"ticket-pimp/internal/domain"
|
"ticket-pimp/internal/domain"
|
||||||
"ticket-pimp/internal/services"
|
"ticket-pimp/internal/services"
|
||||||
|
|
||||||
discordbot "ticket-pimp/discord-bot"
|
"ticket-pimp/discord"
|
||||||
configDB "ticket-pimp/internal/storage/db/config"
|
"ticket-pimp/telegram"
|
||||||
|
|
||||||
ticketDB "ticket-pimp/internal/storage/db/tickets"
|
ticketDB "ticket-pimp/internal/storage/db/tickets"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/joho/godotenv"
|
|
||||||
"github.com/mr-linch/go-tg"
|
|
||||||
"github.com/mr-linch/go-tg/tgb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Print("started")
|
log.Print("started")
|
||||||
config := env("develop.env")
|
config := domain.InitConfig("develop.env")
|
||||||
// run(config)
|
run(config)
|
||||||
test(config)
|
// test(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test(conf domain.Config) {
|
// func test(conf domain.Config) {
|
||||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill, syscall.SIGTERM)
|
// ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill, syscall.SIGTERM)
|
||||||
defer cancel()
|
// defer cancel()
|
||||||
conn, err := pgx.Connect(
|
|
||||||
ctx,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"postgresql://%s:%s@%s:%s/%s",
|
|
||||||
conf.DB.User,
|
|
||||||
conf.DB.Pass,
|
|
||||||
conf.DB.Host,
|
|
||||||
conf.DB.Port,
|
|
||||||
conf.DB.Name,
|
|
||||||
))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("DB connection failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
q := configDB.New(conn)
|
// conn, err := pgxpool.New(ctx, fmt.Sprintf(
|
||||||
// appconfig, err := q.GetConfig(ctx)
|
// "postgresql://%s:%s@%s:%s/%s",
|
||||||
|
// conf.DB.User,
|
||||||
|
// conf.DB.Pass,
|
||||||
|
// conf.DB.Host,
|
||||||
|
// conf.DB.Port,
|
||||||
|
// conf.DB.Name,
|
||||||
|
// ))
|
||||||
|
|
||||||
// appconfigNew, err := q.SetNewConfig(ctx)
|
// if err != nil {
|
||||||
|
// log.Fatalf("DB connection failed: %v", err)
|
||||||
|
// }
|
||||||
|
|
||||||
// _ = appconfig
|
// q := configDB.New(conn)
|
||||||
// _ = appconfigNew
|
|
||||||
|
|
||||||
appController := controller.NewAppConfig(q)
|
// appController := controller.NewAppConfig(q)
|
||||||
ticketConfig, err := appController.NewKey(ctx)
|
// ticketConfig, err := appController.NewKey(ctx)
|
||||||
_ = ticketConfig
|
// _ = ticketConfig
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
func run(conf domain.Config) {
|
func run(conf domain.Config) {
|
||||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill, syscall.SIGTERM)
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill, syscall.SIGTERM)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
// -- DB connection init -- START
|
||||||
conn, err := pgx.Connect(
|
conn, err := pgx.Connect(
|
||||||
ctx,
|
ctx,
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"postgresql://%s:%s@%s:%s/%s",
|
"postgresql://%s:%s@%s:%s/%s",
|
||||||
conf.DB.User,
|
conf.DB.User, conf.DB.Pass, conf.DB.Host, conf.DB.Port, conf.DB.Name,
|
||||||
conf.DB.Pass,
|
|
||||||
conf.DB.Host,
|
|
||||||
conf.DB.Port,
|
|
||||||
conf.DB.Name,
|
|
||||||
))
|
))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("DB connection failed: %v", err)
|
log.Fatalf("DB connection failed: %v", err)
|
||||||
}
|
}
|
||||||
defer conn.Close(ctx)
|
defer conn.Close(ctx)
|
||||||
|
// -- DB connection init -- END
|
||||||
|
|
||||||
opts := TelegramOptions{
|
ticketsRepo := ticketDB.New(conn)
|
||||||
ticketsRepo: ticketDB.New(conn),
|
gitService := services.NewGit(conf.Git)
|
||||||
gitService: services.NewGit(conf.Git),
|
cloudService := services.NewCloud(conf.Cloud)
|
||||||
cloudService: services.NewCloud(conf.Cloud),
|
codeService := services.NewCodaClient(conf.Coda)
|
||||||
coda: services.NewCodaClient(conf.Coda),
|
|
||||||
appConfig: &conf,
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := runDiscrodBot(conf); err != nil {
|
opts := discord.DiscordOptions{
|
||||||
|
TicketsRepo: ticketsRepo,
|
||||||
|
GitService: gitService,
|
||||||
|
CloudService: cloudService,
|
||||||
|
Coda: codeService,
|
||||||
|
AppConfig: &conf,
|
||||||
|
}
|
||||||
|
if err := discord.Run(conf, opts); err != nil {
|
||||||
log.Fatalf("discord bot cannot be runned: %v", err)
|
log.Fatalf("discord bot cannot be runned: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := runTgBot(ctx, opts); err != nil {
|
opts := telegram.TelegramOptions{
|
||||||
|
TicketsRepo: ticketsRepo,
|
||||||
|
GitService: gitService,
|
||||||
|
CloudService: cloudService,
|
||||||
|
Coda: codeService,
|
||||||
|
AppConfig: &conf,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := telegram.Run(ctx, opts); err != nil {
|
||||||
log.Fatalf("telegram bot cannot be runned: %v", err)
|
log.Fatalf("telegram bot cannot be runned: %v", err)
|
||||||
defer os.Exit(1)
|
defer os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// env
|
|
||||||
// env function reads provided file and setup envirmental variables;
|
|
||||||
func env(envFilePath string) domain.Config {
|
|
||||||
err := godotenv.Load(envFilePath)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Error while loading env file")
|
|
||||||
}
|
|
||||||
|
|
||||||
return domain.Config{
|
|
||||||
Git: domain.GitConfig{
|
|
||||||
BaseUrl: os.Getenv("GIT_BASE_URL"),
|
|
||||||
Token: os.Getenv("GIT_TOKEN"),
|
|
||||||
User: os.Getenv("GIT_USER"),
|
|
||||||
},
|
|
||||||
Cloud: domain.CloudConfig{
|
|
||||||
BaseUrl: os.Getenv("CLOUD_BASE_URL"),
|
|
||||||
User: os.Getenv("CLOUD_USER"),
|
|
||||||
Pass: os.Getenv("CLOUD_PASS"),
|
|
||||||
RootDir: os.Getenv("ROOTDIR"),
|
|
||||||
},
|
|
||||||
Coda: domain.CodaConfig{
|
|
||||||
Farm: os.Getenv("CODA_TOKEN1"),
|
|
||||||
Develop: os.Getenv("CODA_TOKEN2"),
|
|
||||||
},
|
|
||||||
DB: domain.DBConfig{
|
|
||||||
Host: os.Getenv("DB_HOST"),
|
|
||||||
Port: os.Getenv("DB_PORT"),
|
|
||||||
Name: os.Getenv("DB_NAME"),
|
|
||||||
User: os.Getenv("DB_USER"),
|
|
||||||
Pass: os.Getenv("DB_PASS"),
|
|
||||||
SslMode: os.Getenv("SSLMODE"),
|
|
||||||
},
|
|
||||||
Telegram: domain.TelegramConfig{
|
|
||||||
Token: os.Getenv("TG_API"),
|
|
||||||
},
|
|
||||||
Discord: domain.DiscordConfig{
|
|
||||||
Token: os.Getenv("DISCORD_TOKEN"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func runDiscrodBot(conf domain.Config) error {
|
|
||||||
token := conf.Discord.Token
|
|
||||||
|
|
||||||
dbot, err := discordbot.NewDiscordBot(token)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
createRepoHandler := discordbot.CreateRepoHandler(3)
|
|
||||||
|
|
||||||
dbot.Session.AddHandler(createRepoHandler.Handler)
|
|
||||||
|
|
||||||
if err := dbot.Session.Open(); err != nil {
|
|
||||||
return fmt.Errorf("cannot open the session: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("Adding commands...")
|
|
||||||
cmd, err := dbot.Session.ApplicationCommandCreate(dbot.Session.State.User.ID, "", &createRepoHandler.Command)
|
|
||||||
if err != nil {
|
|
||||||
log.Panicf("Cannot create '%v' command: %v", createRepoHandler.Command.Name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer dbot.Session.Close()
|
|
||||||
stop := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(stop, os.Interrupt)
|
|
||||||
<-stop
|
|
||||||
log.Println("Graceful shutdown")
|
|
||||||
|
|
||||||
log.Println("Removing commands...")
|
|
||||||
err = dbot.Session.ApplicationCommandDelete(dbot.Session.State.User.ID, "", cmd.ID)
|
|
||||||
if err != nil {
|
|
||||||
log.Panicf("Cannot delete '%v' command: %v", cmd.Name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type TelegramOptions struct {
|
|
||||||
ticketsRepo *ticketDB.Queries
|
|
||||||
gitService *services.Git
|
|
||||||
cloudService *services.Cloud
|
|
||||||
coda *services.Coda
|
|
||||||
appConfig *domain.Config
|
|
||||||
}
|
|
||||||
|
|
||||||
// runTgBot ...
|
|
||||||
// ..function creates new Telegram BOT instance
|
|
||||||
// ..throw env variables through bot's handlers
|
|
||||||
// ..setup tg bot router;
|
|
||||||
// and finally returns tgb.Poller
|
|
||||||
func runTgBot(ctx context.Context, opts TelegramOptions) error {
|
|
||||||
|
|
||||||
log.Print("Start telegram bot init..")
|
|
||||||
client := tg.New(opts.appConfig.Telegram.Token)
|
|
||||||
|
|
||||||
h := handler.NewHandler(
|
|
||||||
opts.gitService,
|
|
||||||
opts.cloudService,
|
|
||||||
opts.coda,
|
|
||||||
opts.ticketsRepo,
|
|
||||||
)
|
|
||||||
|
|
||||||
router := tgb.NewRouter().
|
|
||||||
Message(h.Init, tgb.Command("init")).
|
|
||||||
Message(h.PingHandler, tgb.Command("ping")).
|
|
||||||
Message(h.DevelopmentTaskHandler, tgb.TextHasPrefix("/new")).
|
|
||||||
Message(h.NewRepoHandler, tgb.TextHasPrefix("/repo")).
|
|
||||||
Message(h.NewFolderHandler, tgb.TextHasPrefix("/folder")).
|
|
||||||
Message(h.FarmTaskHandler, tgb.TextHasPrefix("/task"))
|
|
||||||
|
|
||||||
return tgb.NewPoller(
|
|
||||||
router,
|
|
||||||
client,
|
|
||||||
).Run(ctx)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
package discord
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"ticket-pimp/discord/handler"
|
||||||
|
"ticket-pimp/internal/domain"
|
||||||
|
"ticket-pimp/internal/services"
|
||||||
|
|
||||||
|
tickets "ticket-pimp/internal/storage/db/tickets"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func initBotWith(token string) (*discordgo.Session, error) {
|
||||||
|
discord, err := discordgo.New("Bot " + token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return discord, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type DiscordOptions struct {
|
||||||
|
TicketsRepo *tickets.Queries
|
||||||
|
GitService *services.Git
|
||||||
|
CloudService *services.Cloud
|
||||||
|
Coda *services.Coda
|
||||||
|
AppConfig *domain.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func Run(conf domain.Config, opts DiscordOptions) error {
|
||||||
|
token := conf.Discord.Token
|
||||||
|
|
||||||
|
session, err := initBotWith(token)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
router := handler.InitRouter(opts.GitService)
|
||||||
|
|
||||||
|
for _, h := range router.Routes {
|
||||||
|
session.AddHandler(h.Handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := session.Open(); err != nil {
|
||||||
|
return fmt.Errorf("cannot open the session: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Adding commands...")
|
||||||
|
var cmds []*discordgo.ApplicationCommand
|
||||||
|
for _, h := range router.Routes {
|
||||||
|
cmd, err := session.ApplicationCommandCreate(session.State.User.ID, "", &h.Command)
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Cannot create '%v' command: %v", h.Command.Name, err)
|
||||||
|
}
|
||||||
|
cmds = append(cmds, cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Following commands added:")
|
||||||
|
log.Println(cmds)
|
||||||
|
defer session.Close()
|
||||||
|
stop := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(stop, os.Interrupt)
|
||||||
|
<-stop
|
||||||
|
log.Println("Graceful shutdown")
|
||||||
|
|
||||||
|
log.Println("Removing commands...")
|
||||||
|
for _, h := range cmds {
|
||||||
|
err = session.ApplicationCommandDelete(session.State.User.ID, "", h.ID)
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Cannot delete '%v' command: %v", h.Name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -1,32 +1,46 @@
|
||||||
package discordbot
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"ticket-pimp/internal/domain"
|
||||||
|
"ticket-pimp/internal/services"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiscordBot struct {
|
type router struct {
|
||||||
Session *discordgo.Session
|
Routes []route
|
||||||
|
|
||||||
|
git services.IGit
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDiscordBot(token string) (*DiscordBot, error) {
|
// Подключение роутов к Discord боту
|
||||||
discord, err := discordgo.New("Bot " + token)
|
func InitRouter(gitService services.IGit) *router {
|
||||||
if err != nil {
|
var r router
|
||||||
return nil, err
|
r.Routes = append(
|
||||||
}
|
r.Routes,
|
||||||
return &DiscordBot{
|
r.CreateRepoHandler(3),
|
||||||
Session: discord,
|
// r.CreateTicketHandler(3),
|
||||||
}, nil
|
)
|
||||||
|
|
||||||
|
r.git = gitService
|
||||||
|
|
||||||
|
return &r
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommandHandler struct {
|
type route struct {
|
||||||
Command discordgo.ApplicationCommand
|
Command discordgo.ApplicationCommand
|
||||||
Handler func(s *discordgo.Session, i *discordgo.InteractionCreate)
|
Handler func(s *discordgo.Session, i *discordgo.InteractionCreate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateRepoHandler(repoNameMinLength int) CommandHandler {
|
func (h *router) CreateRepoHandler(repoNameMinLength int) route {
|
||||||
return CommandHandler{
|
const (
|
||||||
|
projectRepo = "project_repo"
|
||||||
|
buildRepo = "build_repo"
|
||||||
|
)
|
||||||
|
|
||||||
|
return route{
|
||||||
Command: discordgo.ApplicationCommand{
|
Command: discordgo.ApplicationCommand{
|
||||||
Name: "repo",
|
Name: "repo",
|
||||||
Description: "Command for repository creation",
|
Description: "Command for repository creation",
|
||||||
|
|
@ -39,11 +53,11 @@ func CreateRepoHandler(repoNameMinLength int) CommandHandler {
|
||||||
Choices: []*discordgo.ApplicationCommandOptionChoice{
|
Choices: []*discordgo.ApplicationCommandOptionChoice{
|
||||||
{
|
{
|
||||||
Name: "Unity project repo",
|
Name: "Unity project repo",
|
||||||
Value: "project_repo",
|
Value: projectRepo,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "XCode build repo",
|
Name: "XCode build repo",
|
||||||
Value: "build_repo",
|
Value: buildRepo,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -66,41 +80,44 @@ func CreateRepoHandler(repoNameMinLength int) CommandHandler {
|
||||||
optionMap[opt.Name] = opt
|
optionMap[opt.Name] = opt
|
||||||
}
|
}
|
||||||
|
|
||||||
// This example stores the provided arguments in an []interface{}
|
var str string = ""
|
||||||
// which will be used to format the bot's response
|
|
||||||
margs := make([]interface{}, 0, len(options))
|
|
||||||
msgformat := "You learned how to use command options! " +
|
|
||||||
"Take a look at the value(s) you entered:\n"
|
|
||||||
|
|
||||||
if option, ok := optionMap["repo_type"]; ok {
|
|
||||||
// Option values must be type asserted from interface{}.
|
|
||||||
// Discordgo provides utility functions to make this simple.
|
|
||||||
margs = append(margs, option.StringValue())
|
|
||||||
msgformat += "> string-option: %s\n"
|
|
||||||
}
|
|
||||||
if option, ok := optionMap["repo_name"]; ok {
|
if option, ok := optionMap["repo_name"]; ok {
|
||||||
// Option values must be type asserted from interface{}.
|
str = option.StringValue()
|
||||||
// Discordgo provides utility functions to make this simple.
|
if option, ok := optionMap["repo_type"]; ok {
|
||||||
margs = append(margs, option.StringValue())
|
switch option.Value {
|
||||||
msgformat += "> string-option: %s\n"
|
case projectRepo:
|
||||||
|
|
||||||
|
case buildRepo:
|
||||||
|
str += "-build"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
var g *domain.Git
|
||||||
|
var result string
|
||||||
|
|
||||||
|
g, err := h.git.CreateRepo(str)
|
||||||
|
if err != nil {
|
||||||
|
result = fmt.Sprintf("error while repo creation: %v", err)
|
||||||
|
} else {
|
||||||
|
result = "🚀 " + g.HtmlUrl + " was created"
|
||||||
|
}
|
||||||
|
|
||||||
|
discerr := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
// Ignore type for now, they will be discussed in "responses"
|
// Ignore type for now, they will be discussed in "responses"
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Data: &discordgo.InteractionResponseData{
|
||||||
Content: fmt.Sprintf(
|
Content: result,
|
||||||
msgformat,
|
|
||||||
margs...,
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
log.Println(discerr)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTicketHandler(repoNameMinLength int) CommandHandler {
|
func (h *router) CreateTicketHandler(repoNameMinLength int) route {
|
||||||
return CommandHandler{
|
return route{
|
||||||
Command: discordgo.ApplicationCommand{
|
Command: discordgo.ApplicationCommand{
|
||||||
Name: "new",
|
Name: "new",
|
||||||
Description: "Create new development ticket",
|
Description: "Create new development ticket",
|
||||||
|
|
@ -130,13 +147,7 @@ func CreateTicketHandler(repoNameMinLength int) CommandHandler {
|
||||||
msgformat := "You learned how to use command options! " +
|
msgformat := "You learned how to use command options! " +
|
||||||
"Take a look at the value(s) you entered:\n"
|
"Take a look at the value(s) you entered:\n"
|
||||||
|
|
||||||
if option, ok := optionMap["repo_type"]; ok {
|
if option, ok := optionMap["project_name"]; ok {
|
||||||
// Option values must be type asserted from interface{}.
|
|
||||||
// Discordgo provides utility functions to make this simple.
|
|
||||||
margs = append(margs, option.StringValue())
|
|
||||||
msgformat += "> string-option: %s\n"
|
|
||||||
}
|
|
||||||
if option, ok := optionMap["repo_name"]; ok {
|
|
||||||
// Option values must be type asserted from interface{}.
|
// Option values must be type asserted from interface{}.
|
||||||
// Discordgo provides utility functions to make this simple.
|
// Discordgo provides utility functions to make this simple.
|
||||||
margs = append(margs, option.StringValue())
|
margs = append(margs, option.StringValue())
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
FROM adoptopenjdk/openjdk11-openj9
|
|
||||||
|
|
||||||
ARG GITBUCKET_HOME
|
|
||||||
|
|
||||||
# create home
|
|
||||||
RUN mkdir -p $GITBUCKET_HOME
|
|
||||||
|
|
||||||
# mark volumes
|
|
||||||
VOLUME $GITBUCKET_HOME/repositories
|
|
||||||
VOLUME $GITBUCKET_HOME/data
|
|
||||||
VOLUME $GITBUCKET_HOME/gist
|
|
||||||
VOLUME $GITBUCKET_HOME/plugins
|
|
||||||
|
|
||||||
# Port for web page and Port for SSH access to git repository (Optional)
|
|
||||||
EXPOSE 8080 8443 29418
|
|
||||||
|
|
||||||
COPY server-WIN-DOMAIN-CA.cer /
|
|
||||||
COPY SSLPoke.java /
|
|
||||||
|
|
||||||
# ADD https://github.com/gitbucket/gitbucket/releases/download/4.38.4/gitbucket.war $GITBUCKET_HOME/gitbucket.war
|
|
||||||
COPY gitbucket.war $GITBUCKET_HOME
|
|
||||||
|
|
||||||
RUN keytool -importcert -file /server-WIN-DOMAIN-CA.cer -alias "server-WIN-DOMAIN-CA" -cacerts -storepass changeit -noprompt
|
|
||||||
|
|
||||||
# set environment
|
|
||||||
WORKDIR $GITBUCKET_HOME
|
|
||||||
|
|
||||||
CMD ["sh", "-c", "java $JAVA_OPTS -jar $GITBUCKET_HOME/gitbucket.war"]
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
import javax.net.ssl.SSLParameters;
|
|
||||||
import javax.net.ssl.SSLSocket;
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
/** Establish a SSL connection to a host and port, writes a byte and
|
|
||||||
* prints the response. See
|
|
||||||
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
|
|
||||||
*/
|
|
||||||
public class SSLPoke {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
if (args.length != 2) {
|
|
||||||
System.out.println("Usage: "+SSLPoke.class.getName()+" <host> <port>");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
|
|
||||||
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1]));
|
|
||||||
|
|
||||||
SSLParameters sslparams = new SSLParameters();
|
|
||||||
sslparams.setEndpointIdentificationAlgorithm("HTTPS");
|
|
||||||
sslsocket.setSSLParameters(sslparams);
|
|
||||||
|
|
||||||
InputStream in = sslsocket.getInputStream();
|
|
||||||
OutputStream out = sslsocket.getOutputStream();
|
|
||||||
|
|
||||||
// Write a test byte to get a reaction :)
|
|
||||||
out.write(1);
|
|
||||||
|
|
||||||
while (in.available() > 0) {
|
|
||||||
System.out.print(in.read());
|
|
||||||
}
|
|
||||||
System.out.println("Successfully connected");
|
|
||||||
|
|
||||||
} catch (Exception exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
version: "3"
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
mysql:
|
|
||||||
driver: local
|
|
||||||
|
|
||||||
services:
|
|
||||||
gitbucket:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
args:
|
|
||||||
GITBUCKET_HOME: /mnt/gitbucket
|
|
||||||
container_name: gitbucket_server
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- ${HTTP_PORT}:8080
|
|
||||||
- ${HTTPS_PORT}:8443
|
|
||||||
# Optional for SSH:
|
|
||||||
- ${SSH_PORT}:29418
|
|
||||||
depends_on:
|
|
||||||
mariadb:
|
|
||||||
condition: service_healthy
|
|
||||||
environment:
|
|
||||||
- JAVA_OPTS=-Dcom.sun.net.ssl.checkRevocation=false -Dcom.sun.security.enableAIAcaIssuers=true -Docsp.enable=fase -Dtrust_all_cert=true -Djdk.tls.client.protocols=TLSv1.2 -Dcom.sun.net.ssl.enableECC=false
|
|
||||||
- GITBUCKET_HOME=/mnt/gitbucket
|
|
||||||
- GITBUCKET_CONNECTORS=http
|
|
||||||
- GITBUCKET_HOST=0.0.0.0
|
|
||||||
- GITBUCKET_PORT=8080
|
|
||||||
- GITBUCKET_SECUREPORT=8443
|
|
||||||
- GITBUCKET_REDIRECTHTTPS=false
|
|
||||||
- GITBUCKET_PREFIX=/
|
|
||||||
- GITBUCKET_MAXFILESIZE=4294967296
|
|
||||||
- GITBUCKET_UPLOADTIMEOUT=120000
|
|
||||||
- GITBUCKET_JETTYIDLETIMEOUT=600000
|
|
||||||
- GITBUCKET_DB_URL=jdbc:mariadb://mariadb/gitbucket?useUnicode=true&characterEncoding=utf8
|
|
||||||
- GITBUCKET_DB_USER=gitbucket
|
|
||||||
- GITBUCKET_DB_PASSWORD=gitbucket
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "/usr/bin/healthcheck"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 5
|
|
||||||
volumes:
|
|
||||||
- ../disks/disk1/gitbucket_data/repositories/:/mnt/gitbucket/repositories/
|
|
||||||
- ../disks/disk1/gitbucket_data/data/:/mnt/gitbucket/data/
|
|
||||||
- ../disks/disk1/gitbucket_data/gist/:/mnt/gitbucket/gist/
|
|
||||||
- ../disks/disk1/gitbucket_data/plugins/:/mnt/gitbucket/plugins/
|
|
||||||
|
|
||||||
mariadb:
|
|
||||||
image: mariadb:10.6
|
|
||||||
container_name: gitbucket_mariadb
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- ${DB_PORT}:3306
|
|
||||||
environment:
|
|
||||||
- MYSQL_ROOT_PASSWORD=gitbucket
|
|
||||||
- MYSQL_USER=gitbucket
|
|
||||||
- MYSQL_PASSWORD=gitbucket
|
|
||||||
- MYSQL_DATABASE=gitbucket
|
|
||||||
command: ["--max-allowed-packet=128M", "--innodb-log-file-size=64M"]
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "mysqladmin", "ping", "-u", "root", "--password=gitbucket"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
volumes:
|
|
||||||
- mysql:/var/lib/mysql
|
|
||||||
Binary file not shown.
|
|
@ -1,22 +0,0 @@
|
||||||
-----BEGIN CERTIFICATE-----
|
|
||||||
MIIDuTCCAqGgAwIBAgIQcZXcA798CYtB1LtewpzPijANBgkqhkiG9w0BAQsFADBu
|
|
||||||
MRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxHjAcBgoJkiaJk/IsZAEZFg5tYXJsZXJp
|
|
||||||
bm9ncm91cDEWMBQGCgmSJomT8ixkARkWBnNlcnZlcjEdMBsGA1UEAxMUc2VydmVy
|
|
||||||
LVdJTi1ET01BSU4tQ0EwIBcNMjIwODE1MTI1NTM3WhgPMjEyMjA4MTUxMzA1Mzda
|
|
||||||
MG4xFTATBgoJkiaJk/IsZAEZFgVsb2NhbDEeMBwGCgmSJomT8ixkARkWDm1hcmxl
|
|
||||||
cmlub2dyb3VwMRYwFAYKCZImiZPyLGQBGRYGc2VydmVyMR0wGwYDVQQDExRzZXJ2
|
|
||||||
ZXItV0lOLURPTUFJTi1DQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
|
|
||||||
AMBJwWymu7Csp+y8EMiPNo5drsQE58+enNCk13OIemQON5LZwY++BnvIrHvnaCof
|
|
||||||
Cdb9U2QyWV+Iehv/lNXcBkT6dJCTxUVmn6rXMmwNnBJmGuy0D6APIEPVBO3S7+/R
|
|
||||||
E4az8ikpVezbqAw/LiSyVMEQFaAEK8RlleBScLw9gpXmcWKljCrO/z+2wO1EGI3z
|
|
||||||
a1+qFLynQLeyusRj6rvo0U4RTyXdKaA++Ojhx3DV1NopHoSJ7CqXR728ubWK0fvY
|
|
||||||
0JGMg2ijS1cle7yC96+9ZSjdtktI/9M+8SG/tbpXcpW1bzGM0wCWOos1hLehks7V
|
|
||||||
c1pBEuVGSKSdtyF/FK2C7YUCAwEAAaNRME8wCwYDVR0PBAQDAgGGMA8GA1UdEwEB
|
|
||||||
/wQFMAMBAf8wHQYDVR0OBBYEFL+/yzfaRM/Rcrc9oYEzZf3STypqMBAGCSsGAQQB
|
|
||||||
gjcVAQQDAgEAMA0GCSqGSIb3DQEBCwUAA4IBAQA7j2n9ZeKDwbmWCM2P1F9+6EZ8
|
|
||||||
+RZ+PEdxqs3aDo6S0Ckr/iopHA9PoexKGVEQN6bzaYxb0XTEbpJ89oI299weJF+W
|
|
||||||
63zID/lpEzsaSlTWpuj8KBudVoKsJmwJK2akQ2T3MmSiz7drtFOyh5wl9vhoi2cv
|
|
||||||
H3xhpqOYgh6iRwfwXMLo2YyS4vG6UZtq1GnU/drwVb1gHCoMdz7sFIdxlaw85Ub+
|
|
||||||
dlicykBNu60dbvM/iI0qSG25PerjEoOWZAglrPWpsQ0Zy+ChV0lWSp6FIYHjT3Rj
|
|
||||||
3TUo18LwIUKyorRErOTO4vgYHpqaA/RkAfl0C3cUujMw9eAp1fyd9FH0UcDo
|
|
||||||
-----END CERTIFICATE-----
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
version: "3"
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
mysql:
|
|
||||||
driver: local
|
|
||||||
redis:
|
|
||||||
driver: local
|
|
||||||
|
|
||||||
services:
|
|
||||||
owncloud:
|
|
||||||
image: owncloud/server:${OWNCLOUD_VERSION}
|
|
||||||
container_name: owncloud_server
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- ${HTTP_PORT}:8080
|
|
||||||
depends_on:
|
|
||||||
- mariadb
|
|
||||||
- redis
|
|
||||||
environment:
|
|
||||||
- OWNCLOUD_DOMAIN=${OWNCLOUD_DOMAIN}
|
|
||||||
- OWNCLOUD_TRUSTED_DOMAINS=${OWNCLOUD_TRUSTED_DOMAINS}
|
|
||||||
- OWNCLOUD_DB_TYPE=mysql
|
|
||||||
- OWNCLOUD_DB_NAME=owncloud
|
|
||||||
- OWNCLOUD_DB_USERNAME=owncloud
|
|
||||||
- OWNCLOUD_DB_PASSWORD=owncloud
|
|
||||||
- OWNCLOUD_DB_HOST=mariadb
|
|
||||||
- OWNCLOUD_ADMIN_USERNAME=${ADMIN_USERNAME}
|
|
||||||
- OWNCLOUD_ADMIN_PASSWORD=${ADMIN_PASSWORD}
|
|
||||||
- OWNCLOUD_MYSQL_UTF8MB4=true
|
|
||||||
- OWNCLOUD_REDIS_ENABLED=true
|
|
||||||
- OWNCLOUD_REDIS_HOST=redis
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "/usr/bin/healthcheck"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 5
|
|
||||||
volumes:
|
|
||||||
- ../disks/disk1/owncloud_data/:/mnt/data
|
|
||||||
- ../disks/:/mnt/disks
|
|
||||||
|
|
||||||
mariadb:
|
|
||||||
image: mariadb:10.6 # minimum required ownCloud version is 10.9
|
|
||||||
container_name: owncloud_mariadb
|
|
||||||
restart: always
|
|
||||||
ports:
|
|
||||||
- ${DB_PORT}:3306
|
|
||||||
environment:
|
|
||||||
- MYSQL_ROOT_PASSWORD=owncloud
|
|
||||||
- MYSQL_USER=owncloud
|
|
||||||
- MYSQL_PASSWORD=owncloud
|
|
||||||
- MYSQL_DATABASE=owncloud
|
|
||||||
command: ["--max-allowed-packet=128M", "--innodb-log-file-size=64M"]
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "mysqladmin", "ping", "-u", "root", "--password=owncloud"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
volumes:
|
|
||||||
- mysql:/var/lib/mysql
|
|
||||||
|
|
||||||
redis:
|
|
||||||
image: redis:6
|
|
||||||
container_name: owncloud_redis
|
|
||||||
restart: always
|
|
||||||
command: ["--databases", "1"]
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "redis-cli", "ping"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
volumes:
|
|
||||||
- redis:/data
|
|
||||||
5
go.mod
5
go.mod
|
|
@ -5,7 +5,6 @@ go 1.20
|
||||||
require (
|
require (
|
||||||
github.com/bwmarrin/discordgo v0.27.1
|
github.com/bwmarrin/discordgo v0.27.1
|
||||||
github.com/imroc/req/v3 v3.35.2
|
github.com/imroc/req/v3 v3.35.2
|
||||||
github.com/jackc/pgx v3.6.2+incompatible
|
|
||||||
github.com/jackc/pgx/v5 v5.4.3
|
github.com/jackc/pgx/v5 v5.4.3
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/mr-linch/go-tg v0.9.1
|
github.com/mr-linch/go-tg v0.9.1
|
||||||
|
|
@ -20,9 +19,8 @@ require (
|
||||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||||
github.com/lib/pq v1.10.9 // indirect
|
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
||||||
github.com/onsi/ginkgo/v2 v2.10.0 // indirect
|
github.com/onsi/ginkgo/v2 v2.10.0 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/quic-go/qpack v0.4.0 // indirect
|
github.com/quic-go/qpack v0.4.0 // indirect
|
||||||
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
|
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
|
||||||
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
|
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
|
||||||
|
|
@ -33,6 +31,7 @@ require (
|
||||||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
|
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
|
||||||
golang.org/x/mod v0.10.0 // indirect
|
golang.org/x/mod v0.10.0 // indirect
|
||||||
golang.org/x/net v0.11.0 // indirect
|
golang.org/x/net v0.11.0 // indirect
|
||||||
|
golang.org/x/sync v0.2.0 // indirect
|
||||||
golang.org/x/sys v0.9.0 // indirect
|
golang.org/x/sys v0.9.0 // indirect
|
||||||
golang.org/x/text v0.10.0 // indirect
|
golang.org/x/text v0.10.0 // indirect
|
||||||
golang.org/x/tools v0.9.3 // indirect
|
golang.org/x/tools v0.9.3 // indirect
|
||||||
|
|
|
||||||
12
go.sum
12
go.sum
|
|
@ -27,21 +27,17 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
|
||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
github.com/jackc/pgx v3.6.2+incompatible h1:2zP5OD7kiyR3xzRYMhOcXVvkDZsImVXfj+yIyTQf3/o=
|
|
||||||
github.com/jackc/pgx v3.6.2+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
|
|
||||||
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
|
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
|
||||||
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
|
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
|
||||||
|
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
|
||||||
|
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
|
||||||
github.com/mr-linch/go-tg v0.9.1 h1:4KNe7zwFG6svgM9w6pIcH3R7QWa6hIK8tCisQiFRCpU=
|
github.com/mr-linch/go-tg v0.9.1 h1:4KNe7zwFG6svgM9w6pIcH3R7QWa6hIK8tCisQiFRCpU=
|
||||||
github.com/mr-linch/go-tg v0.9.1/go.mod h1:276w69YW4pEo3ZYta+LQe4v/ut2w2h1ksP4ziBWkK98=
|
github.com/mr-linch/go-tg v0.9.1/go.mod h1:276w69YW4pEo3ZYta+LQe4v/ut2w2h1ksP4ziBWkK98=
|
||||||
github.com/onsi/ginkgo/v2 v2.10.0 h1:sfUl4qgLdvkChZrWCYndY2EAu9BRIw1YphNAzy1VNWs=
|
github.com/onsi/ginkgo/v2 v2.10.0 h1:sfUl4qgLdvkChZrWCYndY2EAu9BRIw1YphNAzy1VNWs=
|
||||||
github.com/onsi/ginkgo/v2 v2.10.0/go.mod h1:UDQOh5wbQUlMnkLfVaIUMtQ1Vus92oM+P2JX1aulgcE=
|
github.com/onsi/ginkgo/v2 v2.10.0/go.mod h1:UDQOh5wbQUlMnkLfVaIUMtQ1Vus92oM+P2JX1aulgcE=
|
||||||
github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU=
|
github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
|
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
|
||||||
|
|
@ -54,7 +50,6 @@ github.com/quic-go/quic-go v0.35.1 h1:b0kzj6b/cQAf05cT0CkQubHM31wiA+xH3IBkxP62po
|
||||||
github.com/quic-go/quic-go v0.35.1/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g=
|
github.com/quic-go/quic-go v0.35.1/go.mod h1:+4CVgVppm0FNjpG3UcX8Joi/frKOH7/ciD5yGcwOO1g=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
|
@ -81,6 +76,8 @@ golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
|
||||||
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
|
||||||
|
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|
@ -108,4 +105,3 @@ google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Git GitConfig
|
Git GitConfig
|
||||||
Cloud CloudConfig
|
Cloud CloudConfig
|
||||||
|
|
@ -48,3 +55,44 @@ type ApplicationConfig struct {
|
||||||
Key string
|
Key string
|
||||||
ID int
|
ID int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitConfig
|
||||||
|
// InitConfig function reads provided file and setup envirmental variables;
|
||||||
|
func InitConfig(envFilePath string) Config {
|
||||||
|
err := godotenv.Load(envFilePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error while loading env file")
|
||||||
|
}
|
||||||
|
|
||||||
|
return Config{
|
||||||
|
Git: GitConfig{
|
||||||
|
BaseUrl: os.Getenv("GIT_BASE_URL"),
|
||||||
|
Token: os.Getenv("GIT_TOKEN"),
|
||||||
|
User: os.Getenv("GIT_USER"),
|
||||||
|
},
|
||||||
|
Cloud: CloudConfig{
|
||||||
|
BaseUrl: os.Getenv("CLOUD_BASE_URL"),
|
||||||
|
User: os.Getenv("CLOUD_USER"),
|
||||||
|
Pass: os.Getenv("CLOUD_PASS"),
|
||||||
|
RootDir: os.Getenv("ROOTDIR"),
|
||||||
|
},
|
||||||
|
Coda: CodaConfig{
|
||||||
|
Farm: os.Getenv("CODA_TOKEN1"),
|
||||||
|
Develop: os.Getenv("CODA_TOKEN2"),
|
||||||
|
},
|
||||||
|
DB: DBConfig{
|
||||||
|
Host: os.Getenv("DB_HOST"),
|
||||||
|
Port: os.Getenv("DB_PORT"),
|
||||||
|
Name: os.Getenv("DB_NAME"),
|
||||||
|
User: os.Getenv("DB_USER"),
|
||||||
|
Pass: os.Getenv("DB_PASS"),
|
||||||
|
SslMode: os.Getenv("SSLMODE"),
|
||||||
|
},
|
||||||
|
Telegram: TelegramConfig{
|
||||||
|
Token: os.Getenv("TG_API"),
|
||||||
|
},
|
||||||
|
Discord: DiscordConfig{
|
||||||
|
Token: os.Getenv("DISCORD_TOKEN"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,19 +49,15 @@ func (gb *Git) CreateRepo(name string) (*domain.Git, error) {
|
||||||
return repo, nil
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type request struct {
|
type gitCreateRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Private bool `json:"private"`
|
Private bool `json:"private"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type permissionRequest struct {
|
|
||||||
Perm string `json:"permission"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gb *Git) newRepo(name string) (*domain.Git, error) {
|
func (gb *Git) newRepo(name string) (*domain.Git, error) {
|
||||||
name = helpers.GitNaming(name)
|
name = helpers.GitNaming(name)
|
||||||
|
|
||||||
payload := request{
|
payload := gitCreateRequest{
|
||||||
Name: name,
|
Name: name,
|
||||||
Private: true,
|
Private: true,
|
||||||
}
|
}
|
||||||
|
|
@ -81,13 +77,16 @@ func (gb *Git) newRepo(name string) (*domain.Git, error) {
|
||||||
return &git, nil
|
return &git, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type gitSetPermissionRequest struct {
|
||||||
|
Perm string `json:"permission"`
|
||||||
|
}
|
||||||
|
|
||||||
func (gb *Git) defaultGroupAsCollaborator(git *domain.Git) (*domain.Git, error) {
|
func (gb *Git) defaultGroupAsCollaborator(git *domain.Git) (*domain.Git, error) {
|
||||||
|
|
||||||
payload := permissionRequest{
|
payload := gitSetPermissionRequest{
|
||||||
Perm: "push",
|
Perm: "push",
|
||||||
}
|
}
|
||||||
|
|
||||||
///orgs/manurlerino/teams/devs/repos/manurlerino/x
|
|
||||||
respURL := "/orgs/mobilerino/teams/devs/repos/mobilerino/" + git.Name
|
respURL := "/orgs/mobilerino/teams/devs/repos/mobilerino/" + git.Name
|
||||||
|
|
||||||
resp, _ := gb.R().
|
resp, _ := gb.R().
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,12 @@ type git struct {
|
||||||
ssh string
|
ssh string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGit(domain *domain.Git) *git {
|
func newGit(g *domain.Git) *git {
|
||||||
return &git{
|
return &git{
|
||||||
name: domain.Name,
|
name: g.Name,
|
||||||
url: domain.HtmlUrl,
|
url: g.HtmlUrl,
|
||||||
git: domain.CloneUrl,
|
git: g.CloneUrl,
|
||||||
ssh: fmt.Sprintf("ssh://%s/%s.git", domain.SshUrl, domain.FullName),
|
ssh: fmt.Sprintf("ssh://%s/%s.git", g.SshUrl, g.FullName),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ticket-pimp/bot/controller"
|
"ticket-pimp/internal/controller"
|
||||||
"ticket-pimp/internal/services"
|
"ticket-pimp/internal/services"
|
||||||
db "ticket-pimp/internal/storage/db/tickets"
|
tickets "ticket-pimp/internal/storage/db/tickets"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
|
|
@ -13,14 +13,14 @@ type Handler struct {
|
||||||
coda services.ICoda
|
coda services.ICoda
|
||||||
key string
|
key string
|
||||||
id string
|
id string
|
||||||
db *db.Queries
|
db *tickets.Queries
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(
|
func NewHandler(
|
||||||
git services.IGit,
|
git services.IGit,
|
||||||
cloud services.ICloud,
|
cloud services.ICloud,
|
||||||
coda services.ICoda,
|
coda services.ICoda,
|
||||||
db *db.Queries,
|
db *tickets.Queries,
|
||||||
) *Handler {
|
) *Handler {
|
||||||
|
|
||||||
return &Handler{
|
return &Handler{
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
package telegram
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"ticket-pimp/internal/domain"
|
||||||
|
"ticket-pimp/internal/services"
|
||||||
|
"ticket-pimp/telegram/handler"
|
||||||
|
|
||||||
|
"github.com/mr-linch/go-tg"
|
||||||
|
"github.com/mr-linch/go-tg/tgb"
|
||||||
|
|
||||||
|
tickets "ticket-pimp/internal/storage/db/tickets"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TelegramOptions struct {
|
||||||
|
TicketsRepo *tickets.Queries
|
||||||
|
GitService *services.Git
|
||||||
|
CloudService *services.Cloud
|
||||||
|
Coda *services.Coda
|
||||||
|
AppConfig *domain.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// runTgBot ...
|
||||||
|
// ..function creates new Telegram BOT instance
|
||||||
|
// ..throw env variables through bot's handlers
|
||||||
|
// ..setup tg bot router;
|
||||||
|
// and finally returns tgb.Poller
|
||||||
|
func Run(ctx context.Context, opts TelegramOptions) error {
|
||||||
|
|
||||||
|
log.Print("Start telegram bot init..")
|
||||||
|
client := tg.New(opts.AppConfig.Telegram.Token)
|
||||||
|
|
||||||
|
h := handler.NewHandler(
|
||||||
|
opts.GitService,
|
||||||
|
opts.CloudService,
|
||||||
|
opts.Coda,
|
||||||
|
opts.TicketsRepo,
|
||||||
|
)
|
||||||
|
|
||||||
|
router := tgb.NewRouter().
|
||||||
|
Message(h.Init, tgb.Command("init")).
|
||||||
|
Message(h.PingHandler, tgb.Command("ping")).
|
||||||
|
Message(h.DevelopmentTaskHandler, tgb.TextHasPrefix("/new")).
|
||||||
|
Message(h.NewRepoHandler, tgb.TextHasPrefix("/repo")).
|
||||||
|
Message(h.NewFolderHandler, tgb.TextHasPrefix("/folder")).
|
||||||
|
Message(h.FarmTaskHandler, tgb.TextHasPrefix("/task"))
|
||||||
|
|
||||||
|
return tgb.NewPoller(
|
||||||
|
router,
|
||||||
|
client,
|
||||||
|
).Run(ctx)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue