-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
127 lines (109 loc) · 3.8 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"fmt"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"time"
"github.com/AlecAivazis/survey/v2"
"github.com/joho/godotenv"
)
const LINE_LENGHT = 110
var costPerHour int
var url string
var token string
var reportDate time.Time
func init() {
if err := godotenv.Load(); err != nil {
fmt.Print("No .env file found")
}
token = "Bearer " + os.Getenv("TOKEN")
url = os.Getenv("URL")
t, _ := strconv.Atoi(os.Getenv("COST"))
costPerHour = t
}
func main() {
fmt.Println(costPerHour, )
reportDate = getDateReport()
reportIds := make(map[string]string)
for _, report := range GetReportsList() {
if report.Name == "Внедрено " + reportDate.Format("2006-01") {
reportIds["Implemented"] = report.Id
}
if report.Name == "Отработано " + reportDate.Format("2006-01") {
reportIds["Spent"] = report.Id
}
}
if len(reportIds) == 0 {
fmt.Println("Отчеты за выбранный период не найдены")
return
}
fmt.Printf("Найдены отчеты: \n - по внедренным задачам - %s/reports/time/%s \n - по отработанному времени - %s/reports/time/%s\n\r", url, reportIds["Implemented"], url, reportIds["Spent"])
reports := make(map[string]Report)
for k, v := range reportIds {
reports[k] = GetReport(v)
}
var repotContent []string
for _, report := range reports {
for _, group := range report.Data.Groups {
if group.Meta.LinkedUser.VisibleName == "Дударек Илья" {
if strings.HasPrefix(report.Name, "Внедрено") {
repotContent = append(repotContent, formatCompleatedReport(group))
} else {
repotContent = append(repotContent, formatSpentReport(group))
}
}
}
}
writeToFile(repotContent)
if isNeedFutureTasks() {
dateNextSprint := reportDate.AddDate(0, 1, 0).Format("06-01")
fmt.Printf("Поиск задач будет осуществляться в спринте %s \n", dateNextSprint)
taskList := GetTaskList(GetTaskIDList(GetCurrentSprintID(dateNextSprint)))
planTasks := []string{}
prompt := &survey.MultiSelect{
Message: "Выберите задачи для добавления их в план на следующий месяц",
Options: taskList,
Help: " ",
}
survey.AskOne(prompt, &planTasks)
priorityTasks := []string{}
prompt = &survey.MultiSelect{
Message: "Выберите приоритетные задачи",
Options: planTasks,
}
survey.AskOne(prompt, &priorityTasks)
sort.Strings(planTasks)
sort.Strings(priorityTasks)
appendToFile(planTasks, priorityTasks)
}
}
func writeToFile(contentList []string) {
createDir("./reports")
fileName := fmt.Sprintf("./reports/%s.txt", reportDate.Format("2006-01"))
createFile(fileName)
err := os.WriteFile(fileName, []byte(strings.Join(contentList, "\n\r\n\r")), 0644)
filePath, _ := filepath.Abs(fileName)
fmt.Printf("Отчеты сформированы %s\n", filePath)
checkError(err, "Ошибка при записи файла")
}
func appendToFile(planTasks, priorityTasks []string) {
plan, priority := futureTaskFormat(filter(planTasks, priorityTasks), priorityTasks)
fileName := fmt.Sprintf("./reports/%s.txt", reportDate.Format("2006-01"))
f, err := os.OpenFile(fileName, os.O_APPEND|os.O_WRONLY, 0600)
checkError(err, "Ошибка при записи файла")
defer f.Close()
_, err = f.WriteString(fmt.Sprintf("\n\r\n\r%s\n\r\n\r%s\n\r", plan, priority))
checkError(err, "Ошибка при записи файла")
}
func filter(origin, target []string) []string {
filtered := []string{}
for _, str := range origin {
if !contains(target, str) {
filtered = append(filtered, str)
}
}
return filtered
}