rename shortname, key;
This commit is contained in:
parent
cd3f414ee0
commit
b50d98d961
|
|
@ -41,17 +41,19 @@ func (wc *WorkflowController) ProjectCreate(ctx context.Context, project domain.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
project.ShortName = fmt.Sprintf(
|
project.Key = fmt.Sprintf(
|
||||||
"%s-%d",
|
"%s-%d",
|
||||||
appconfig.TicketKey.String,
|
appconfig.TicketKey.String,
|
||||||
appconfig.TicketID.Int32,
|
appconfig.TicketID.Int32,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Set ID from the DB raw:
|
||||||
project.ID = string(appconfig.TicketID.Int32)
|
project.ID = string(appconfig.TicketID.Int32)
|
||||||
|
|
||||||
projectRow, err := qtx.CreateTicket(ctx, db.CreateTicketParams{
|
projectRow, err := qtx.CreateTicket(ctx, db.CreateTicketParams{
|
||||||
Key: pgtype.Text{String: project.ShortName, Valid: true},
|
Key: pgtype.Text{String: project.Key, Valid: true},
|
||||||
Channelid: pgtype.Text{String: project.ChannelID, Valid: true},
|
Channelid: pgtype.Text{String: project.ChannelID, Valid: true},
|
||||||
|
Title: pgtype.Text{String: project.Name, Valid: true},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback(ctx)
|
tx.Rollback(ctx)
|
||||||
|
|
@ -75,12 +77,12 @@ func (wc *WorkflowController) GetProjectByChannelID(ctx context.Context, id stri
|
||||||
} else {
|
} else {
|
||||||
proj = domain.Project{
|
proj = domain.Project{
|
||||||
ID: string(dbTicket.ID),
|
ID: string(dbTicket.ID),
|
||||||
ShortName: dbTicket.Key.String,
|
Key: dbTicket.Key.String,
|
||||||
Name: dbTicket.Key.String,
|
Name: dbTicket.Key.String,
|
||||||
ChannelID: dbTicket.Channelid.String,
|
ChannelID: dbTicket.Channelid.String,
|
||||||
ProjectGit: dbTicket.ProjectGit.String,
|
ProjectGit: dbTicket.ProjectGit.String,
|
||||||
BuildGit: dbTicket.BuildGit.String,
|
BuildGit: dbTicket.BuildGit.String,
|
||||||
Cloud: dbTicket.Folder.String,
|
Folder: dbTicket.Folder.String,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &proj, nil
|
return &proj, nil
|
||||||
|
|
@ -108,11 +110,11 @@ func (wc *WorkflowController) InitProjectInChannel(ctx context.Context, channelI
|
||||||
|
|
||||||
return &domain.Project{
|
return &domain.Project{
|
||||||
ID: string(dbTicket.ID),
|
ID: string(dbTicket.ID),
|
||||||
ShortName: dbTicket.Key.String,
|
Key: dbTicket.Key.String,
|
||||||
Name: dbTicket.Key.String,
|
Name: dbTicket.Key.String,
|
||||||
ChannelID: dbTicket.Channelid.String,
|
ChannelID: dbTicket.Channelid.String,
|
||||||
ProjectGit: dbTicket.ProjectGit.String,
|
ProjectGit: dbTicket.ProjectGit.String,
|
||||||
BuildGit: dbTicket.BuildGit.String,
|
BuildGit: dbTicket.BuildGit.String,
|
||||||
Cloud: dbTicket.Folder.String,
|
Folder: dbTicket.Folder.String,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package controller
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"ticket-pimp/internal/domain"
|
"ticket-pimp/internal/domain"
|
||||||
"ticket-pimp/internal/storage/db"
|
"ticket-pimp/internal/storage/db"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -42,12 +41,11 @@ func (wc *WorkflowController) WriteTaskToDB(t *domain.Task) (*domain.Task, error
|
||||||
|
|
||||||
// InitTask
|
// InitTask
|
||||||
/*
|
/*
|
||||||
Runs the following:
|
Runs the following:
|
||||||
- Use WriteTaskToDB method to make a new task row in the db;
|
- Use WriteTaskToDB method to make a new task row in the db;
|
||||||
- init new discord bot instance;
|
- init new discord bot instance;
|
||||||
-
|
|
||||||
|
|
||||||
Possible errors:
|
Possible errors:
|
||||||
- db record couldn't be created;
|
- db record couldn't be created;
|
||||||
- bot couldn't be inited;
|
- bot couldn't be inited;
|
||||||
- bot session couldn't be started;
|
- bot session couldn't be started;
|
||||||
|
|
@ -61,14 +59,7 @@ func (wc *WorkflowController) InitTask(t *domain.Task) (*domain.Task, error) {
|
||||||
return nil, fmt.Errorf("unable to create task at the db: %v", err)
|
return nil, fmt.Errorf("unable to create task at the db: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Инициализируем новый клиент дискорда
|
s, err := discordgo.New("Bot " + wc.conf.Discord.Token)
|
||||||
// [ ] Нездоровое получение параметров клиента из os..
|
|
||||||
var (
|
|
||||||
token = os.Getenv("DISCORD_TOKEN")
|
|
||||||
forumChannelID = os.Getenv("TASKS_CHANNEL")
|
|
||||||
)
|
|
||||||
|
|
||||||
s, err := discordgo.New("Bot " + token)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return task, fmt.Errorf("unable to create discord session: %v", err)
|
return task, fmt.Errorf("unable to create discord session: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -100,9 +91,10 @@ func (wc *WorkflowController) InitTask(t *domain.Task) (*domain.Task, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
th, err := s.ForumThreadStartComplex(
|
th, err := s.ForumThreadStartComplex(
|
||||||
forumChannelID,
|
wc.conf.Discord.IsTaskForum,
|
||||||
&discordgo.ThreadStart{
|
&discordgo.ThreadStart{
|
||||||
Name: fmt.Sprintf("Task ID: %d, by %s", task.ID, task.Creator),
|
Name: fmt.Sprintf("Task ID: %d, by %s", task.ID, task.Creator),
|
||||||
|
AppliedTags: []string{"Не начат"},
|
||||||
},
|
},
|
||||||
&msg,
|
&msg,
|
||||||
)
|
)
|
||||||
|
|
@ -126,25 +118,34 @@ func (wc *WorkflowController) UpdateTasksMessageID(ctx context.Context, msgID st
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WorkflowController) UpdateTask(id string, opt int, user string) (*TaskConvertable, error) {
|
// UpdateTask
|
||||||
|
/*
|
||||||
|
- updates task by message Id
|
||||||
|
- with an action:
|
||||||
|
0 for 'in progress' state;
|
||||||
|
1 for 'done' state;
|
||||||
|
- and assignee..
|
||||||
|
*/
|
||||||
|
func (wc *WorkflowController) UpdateTask(messageId string, opt int, assignee string) (*TaskConvertable, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
dbtask db.Task
|
dbtask db.Task
|
||||||
)
|
)
|
||||||
|
|
||||||
switch opt {
|
switch opt {
|
||||||
case 0:
|
case 0:
|
||||||
dbtask, err = wc.q.StartTask(context.TODO(), db.StartTaskParams{
|
dbtask, err = wc.q.StartTask(context.TODO(), db.StartTaskParams{
|
||||||
UpdatedAt: pgtype.Timestamptz{Time: time.Now(), InfinityModifier: 0, Valid: true},
|
UpdatedAt: pgtype.Timestamptz{Time: time.Now(), InfinityModifier: 0, Valid: true},
|
||||||
Assignee: pgtype.Text{String: user, Valid: true},
|
Assignee: pgtype.Text{String: assignee, Valid: true},
|
||||||
Messageid: pgtype.Text{String: id, Valid: true},
|
Messageid: pgtype.Text{String: messageId, Valid: true},
|
||||||
})
|
})
|
||||||
return &TaskConvertable{&dbtask}, err
|
return &TaskConvertable{&dbtask}, err
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
dbtask, err = wc.q.CloseTask(context.TODO(), db.CloseTaskParams{
|
dbtask, err = wc.q.CloseTask(context.TODO(), db.CloseTaskParams{
|
||||||
DeletedAt: pgtype.Timestamptz{Time: time.Now(), InfinityModifier: 0, Valid: true},
|
DeletedAt: pgtype.Timestamptz{Time: time.Now(), InfinityModifier: 0, Valid: true},
|
||||||
Assignee: pgtype.Text{String: user, Valid: true},
|
Assignee: pgtype.Text{String: assignee, Valid: true},
|
||||||
Messageid: pgtype.Text{String: id, Valid: true},
|
Messageid: pgtype.Text{String: messageId, Valid: true},
|
||||||
})
|
})
|
||||||
return &TaskConvertable{&dbtask}, err
|
return &TaskConvertable{&dbtask}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue