Skip to content
Snippets Groups Projects
Verified Commit cee6aa80 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: commit save point

parent d3a3be22
No related branches found
No related tags found
No related merge requests found
Showing with 182 additions and 99 deletions
......@@ -3,7 +3,7 @@
<module name="requirements-manager" />
<working_directory value="$PROJECT_DIR$/application/source" />
<go_parameters value="-ldflags &quot;-X main.version=1.0.15 -X main.build=20220616123315&quot;" />
<parameters value="gitlab sync -p $PROJECT_DIR$/development/examples/example1" />
<parameters value="gitlab sync -p $PROJECT_DIR$/development/examples/example1/req1/1/test1.md" />
<kind value="DIRECTORY" />
<package value="gitlab.schukai.com/oss/utilities/requirements-manager" />
<directory value="$PROJECT_DIR$/application/source" />
......
......@@ -8,7 +8,7 @@ import (
type logs []string
func buildChangelog(config *Configuration, pageMap map[string]*requirement) (error, string, bool) {
func buildChangelog(pageMap map[string]*requirement) (error, string, bool) {
changelog := make(map[string]logs)
datemap := make(map[string]string)
......@@ -56,14 +56,14 @@ func buildChangelog(config *Configuration, pageMap map[string]*requirement) (err
}
func printChangelog(config *Configuration) error {
func printChangelog() error {
err, pageData := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
err, table, _ := buildChangelog(config, pageData)
err, table, _ := buildChangelog(pageData)
fmt.Println(table)
return err
}
......@@ -9,16 +9,21 @@ import (
"github.com/jessevdk/go-flags"
)
var (
config *Configuration
arguments *commandLineOptions
)
func executeCommand() {
arguments := new(commandLineOptions)
arguments = new(commandLineOptions)
p := flags.NewParser(arguments, flags.Default)
_, err := p.Parse()
if err != nil {
os.Exit(-1)
}
config := NewConfiguration(arguments.Config)
config = NewConfiguration(arguments.Config)
if arguments.Path != "" {
config.Path = arguments.Path
......@@ -42,7 +47,7 @@ func executeCommand() {
subcommand := activeCommand.Active
switch subcommand.Name {
case "print":
err := printChangelog(config)
err := printChangelog()
if err != nil {
printErrorAndExit(2, err.Error())
}
......@@ -51,7 +56,7 @@ func executeCommand() {
subcommand := activeCommand.Active
switch subcommand.Name {
case "print":
err := printPrivacy(config)
err := printPrivacy()
if err != nil {
printErrorAndExit(2, err.Error())
}
......@@ -77,7 +82,7 @@ func executeCommand() {
config.Overview.Template.Latex = arguments.Overview.Print.LatexTemplatePath
}
err := PrintOverview(config, arguments)
err := PrintOverview()
if err != nil {
printErrorAndExit(2, err.Error())
}
......@@ -87,13 +92,13 @@ func executeCommand() {
subcommand := activeCommand.Active
switch subcommand.Name {
case "report":
err := printRequirementReport(config, arguments)
err := printRequirementReport()
if err != nil {
printErrorAndExit(2, err.Error())
}
case "add":
config.Requirement.Template.Add = defaultNewRequirementTemplate
err := addRequirement(config, arguments)
err := addRequirement()
if err != nil {
printErrorAndExit(2, err.Error())
}
......@@ -101,7 +106,7 @@ func executeCommand() {
if len(arguments.Requirements.Print.Columns) > 0 {
config.Requirement.Table.Columns = validateColumns(arguments.Requirements.Print.Columns)
}
err := printRequirements(config)
err := printRequirements()
if err != nil {
printErrorAndExit(2, err.Error())
}
......@@ -111,7 +116,7 @@ func executeCommand() {
subcommand := activeCommand.Active
switch subcommand.Name {
case "print":
err := printTaskTable(config)
err := printTaskTable()
if err != nil {
printErrorAndExit(2, err.Error())
}
......@@ -126,7 +131,7 @@ func executeCommand() {
config.Gitlab.Token = arguments.Issues.Print.GitlabToken
}
err := printIssueTable(config, arguments)
err := printIssueTable()
if err != nil {
printErrorAndExit(2, err.Error())
}
......@@ -135,7 +140,7 @@ func executeCommand() {
subcommand := activeCommand.Active
switch subcommand.Name {
case "print":
err := printItemTable(config)
err := printItemTable()
if err != nil {
printErrorAndExit(2, err.Error())
}
......@@ -152,7 +157,7 @@ func executeCommand() {
config.Gitlab.Token = arguments.Gitlab.GitlabToken
}
syncTasksWithGitlab(config)
syncFilesWithGitlab()
}
}
......
......@@ -31,7 +31,7 @@ type Configuration struct {
Gitlab struct {
Token string `yaml:"Token"`
} `yaml:"Gitlab"`
} `yaml:"GitLab"`
Overview struct {
Template struct {
......
......@@ -4,4 +4,6 @@ import "errors"
var (
noGitRepositoryError = errors.New("no git repository found")
notFoundError = errors.New("not found")
notPermittedError = errors.New("not permitted")
)
package main
import (
"bytes"
"io/ioutil"
"os"
"path"
"path/filepath"
"gopkg.in/yaml.v3"
)
//
......@@ -63,3 +66,35 @@ func collectStructureFromFiles(directory string) (error, map[string]*requirement
return err, pageMap
}
func rewriteFiles(pageData map[string]*requirement) error {
for filename, pd := range pageData {
buf := new(bytes.Buffer)
var encoder = yaml.NewEncoder(buf)
err := encoder.Encode(pd.OriginNode)
if err != nil {
return err
}
encoder.Close()
text := "---\n" + buf.String() + "\n...\n"
text += pd.OriginText
info, err := os.Stat(filename)
if err != nil {
return err
}
mode := info.Mode()
err = os.WriteFile(filename, []byte(text), mode)
if err != nil {
return err
}
}
return nil
}
......@@ -22,10 +22,10 @@ type gitlabContext struct {
project *gitlab.Project
}
func getGitlabContext(config *Configuration) *gitlabContext {
func getGitlabContext() *gitlabContext {
context := &gitlabContext{}
workingPath, err := getGitDirectory(config)
workingPath, err := getGitDirectory()
if err != nil {
printErrorAndExit(2, "Failed to get git directory", err.Error())
}
......@@ -116,9 +116,9 @@ func searchProject(context *gitlabContext) {
}
func enrichIssuesWithGitlab(pageMap map[string]*requirement, config *Configuration) error {
func enrichIssuesWithGitlab(pageMap map[string]*requirement) error {
context := getGitlabContext(config)
context := getGitlabContext()
searchProject(context)
for _, requirement := range pageMap {
......@@ -145,6 +145,95 @@ func enrichIssuesWithGitlab(pageMap map[string]*requirement, config *Configurati
return nil
}
func syncFilesWithGitlab() error {
err, pageData := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
issuesList := []Issue{}
for _, pageData := range pageData {
for _, info := range pageData.Issues {
issuesList = append(issuesList, info)
}
}
context := getGitlabContext()
searchProject(context)
syncIssuesWithGitlab(pageData)
return rewriteFiles(pageData)
}
func syncIssuesWithGitlab(pageData map[string]*requirement) {
for _, pageData := range pageData {
for _, info := range pageData.Issues {
if info.GitlabRemote != nil {
continue
}
if info.GitlabIntern == nil {
continue
}
if info.GitlabIntern.ID == 0 {
issue, err := createIssue(info)
if err != nil {
printErrorAndExit(2, "Failed to create issue %s", err.Error())
}
info.GitlabRemote = issue
}
}
}
}
func createIssue(issue Issue) (*gitlab.Issue, error) {
context := getGitlabContext()
searchProject(context)
//title := *string(issue.GitlabIntern.Title)
createionOptions := gitlab.CreateIssueOptions{
Title: gitlab.String(issue.GitlabIntern.Title),
}
ptr := &createionOptions
gitlabIssue, respose, err := context.client.Issues.CreateIssue(context.project.ID, ptr)
if respose.StatusCode == 401 {
return gitlabIssue, err
}
if respose.StatusCode > 299 {
return gitlabIssue, err
}
return gitlabIssue, err
}
//
// context := getGitlabContext(config)
// searchProject(context)
//
// options := &gitlab.CreateIssueOptions{
// Title: gitlab.String(issue.Title),
// Status: gitlab.String(issue.Status),
// Labels: gitlab.StringSlice(issue.Labels),
// }
//
// i, _, err := context.client.Issues.CreateIssue(context.project.ID, options)
// if err != nil {
// return nil, err
// }
//
// return i, nil
//
//}
//
//
//func getProject(config *Configuration) *gitlab.Project {
//
......
......@@ -3,12 +3,9 @@ package main
import (
"bytes"
"fmt"
"os"
"strings"
"time"
"gopkg.in/yaml.v3"
"github.com/olekukonko/tablewriter"
"github.com/xanzy/go-gitlab"
)
......@@ -43,7 +40,7 @@ func loadIssuesFromGitlab(context *gitlabContext, issueID int) (*gitlab.Issue, e
//err, pageData := collectStructureFromFiles(config.Path)
}
func buildIssueOverviewTable(config *Configuration, pageMap map[string]*requirement, extended bool) (error, string, bool) {
func buildIssueOverviewTable(pageMap map[string]*requirement, extended bool) (error, string, bool) {
buf := new(bytes.Buffer)
has := false
......@@ -141,65 +138,18 @@ func buildIssueOverviewTable(config *Configuration, pageMap map[string]*requirem
return nil, buf.String(), has
}
func printIssueTable(config *Configuration, arguments *commandLineOptions) error {
func printIssueTable() error {
err, pageMap := collectStructureFromFiles(config.Path)
if arguments.Issues.Print.Remote {
enrichIssuesWithGitlab(pageMap, config)
enrichIssuesWithGitlab(pageMap)
if err != nil {
return err
}
}
err, table, _ := buildIssueOverviewTable(config, pageMap, true)
err, table, _ := buildIssueOverviewTable(pageMap, true)
fmt.Println(table)
return nil
}
func syncTasksWithGitlab(config *Configuration) error {
err, pageData := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
issuesList := []Issue{}
for _, pageData := range pageData {
for _, info := range pageData.Issues {
issuesList = append(issuesList, info)
}
}
context := getGitlabContext(config)
searchProject(context)
for filename, pd := range pageData {
buf := new(bytes.Buffer)
var encoder = yaml.NewEncoder(buf)
err := encoder.Encode(pd.OriginNode)
if err != nil {
return err
}
encoder.Close()
text := "---\n" + buf.String() + "\n...\n"
text += pd.OriginText
info, err := os.Stat(filename)
if err != nil {
return err
}
mode := info.Mode()
err = os.WriteFile(filename, []byte(text), mode)
if err != nil {
return err
}
}
return nil
}
......@@ -19,7 +19,7 @@ type Item struct {
ProvidedBy string `yaml:"Provided by"`
}
func buildItemOverviewTable(config *Configuration, pageMap map[string]*requirement, extended bool) (error, string, bool) {
func buildItemOverviewTable(pageMap map[string]*requirement, extended bool) (error, string, bool) {
buf := new(bytes.Buffer)
has := false
......@@ -114,13 +114,13 @@ func buildItemOverviewTable(config *Configuration, pageMap map[string]*requireme
return nil, buf.String(), has
}
func printItemTable(config *Configuration) error {
func printItemTable() error {
err, pageMap := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
err, table, _ := buildItemOverviewTable(config, pageMap, true)
err, table, _ := buildItemOverviewTable(pageMap, true)
fmt.Println(table)
return nil
......
......@@ -30,34 +30,34 @@ type Dataset struct {
CreatedFormat string
}
func PrintOverview(config *Configuration, arguments *commandLineOptions) error {
func PrintOverview() error {
err, pageData := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
err, meta, hasMeta := buildRequirements(config, pageData)
err, meta, hasMeta := buildRequirements(pageData)
if err != nil {
return err
}
err, changelog, hasChangelog := buildChangelog(config, pageData)
err, changelog, hasChangelog := buildChangelog(pageData)
if err != nil {
return err
}
err, privacy, hasPrivacy := buildPrivacy(config, pageData)
err, privacy, hasPrivacy := buildPrivacy(pageData)
if err != nil {
return err
}
err, tasks, hasTasks := buildTasksTable(config, pageData, false)
err, tasks, hasTasks := buildTasksTable(pageData, false)
if err != nil {
return err
}
err, items, hasItems := buildItemOverviewTable(config, pageData, false)
err, items, hasItems := buildItemOverviewTable(pageData, false)
if err != nil {
return err
}
......
......@@ -19,7 +19,7 @@ type Privacy struct {
TOM string `yaml:"TOM"`
}
func buildPrivacy(config *Configuration, pageMap map[string]*requirement) (error, string, bool) {
func buildPrivacy(pageMap map[string]*requirement) (error, string, bool) {
hasPrivacy := false
text := ""
......@@ -82,14 +82,14 @@ func buildPrivacy(config *Configuration, pageMap map[string]*requirement) (error
}
func printPrivacy(config *Configuration) error {
func printPrivacy() error {
err, pageData := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
err, data, _ := buildPrivacy(config, pageData)
err, data, _ := buildPrivacy(pageData)
fmt.Println(data)
return err
}
......@@ -48,7 +48,7 @@ type requirement struct {
LastUpdate time.Time `yaml:"Last Update"`
}
func addRequirement(config *Configuration, arguments *commandLineOptions) error {
func addRequirement() error {
if arguments.Requirements.Add.ID == "" {
printErrorAndExit(2, "the id must not be empty")
......@@ -72,7 +72,7 @@ func addRequirement(config *Configuration, arguments *commandLineOptions) error
return nil
}
func buildRequirements(config *Configuration, pageMap map[string]*requirement) (error, string, bool) {
func buildRequirements(pageMap map[string]*requirement) (error, string, bool) {
hasRequirements := false
......@@ -157,13 +157,13 @@ func buildRequirements(config *Configuration, pageMap map[string]*requirement) (
}
func printRequirements(config *Configuration) error {
func printRequirements() error {
err, pageData := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
err, table, _ := buildRequirements(config, pageData)
err, table, _ := buildRequirements(pageData)
fmt.Println(table)
return err
}
......@@ -185,10 +185,10 @@ func integrateGitlabTimeSpent(pageMap map[string]*requirement) {
}
func buildTimeReport(config *Configuration, arguments *commandLineOptions, pageMap map[string]*requirement) (error, string, string, bool) {
func buildTimeReport(pageMap map[string]*requirement) (error, string, string, bool) {
if arguments.Requirements.Report.Remote {
err := enrichIssuesWithGitlab(pageMap, config)
err := enrichIssuesWithGitlab(pageMap)
if err != nil {
return err, "", "", false
}
......@@ -408,14 +408,14 @@ func buildTable2(pageMap map[string]*requirement) string {
return buf.String()
}
func printRequirementReport(config *Configuration, arguments *commandLineOptions) error {
func printRequirementReport() error {
err, pageData := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
err, table1, table2, _ := buildTimeReport(config, arguments, pageData)
err, table1, table2, _ := buildTimeReport(pageData)
if err != nil {
return err
}
......
......@@ -72,7 +72,7 @@ func findTask(content []byte) []task {
return toDos
}
func buildTasksTable(config *Configuration, pageMap map[string]*requirement, extended bool) (error, string, bool) {
func buildTasksTable(pageMap map[string]*requirement, extended bool) (error, string, bool) {
buf := new(bytes.Buffer)
......@@ -130,13 +130,13 @@ func buildTasksTable(config *Configuration, pageMap map[string]*requirement, ext
return nil, buf.String(), has
}
func printTaskTable(config *Configuration) error {
func printTaskTable() error {
err, pageData := collectStructureFromFiles(config.Path)
if err != nil {
return err
}
err, table, _ := buildTasksTable(config, pageData, true)
err, table, _ := buildTasksTable(pageData, true)
fmt.Println(table)
return nil
......
......@@ -137,7 +137,7 @@ func translateHeaders(columns []string) []string {
}
func getGitDirectory(config *Configuration) (string, error) {
func getGitDirectory() (string, error) {
path := config.Path
......
......@@ -107,6 +107,8 @@ Privacy:
### {{ .Title }} - {{ .ID }}
#### Subheading
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment