From 48e7394678ee95ff95be079e3fb0a2c4d5f34175 Mon Sep 17 00:00:00 2001 From: mms-gianni Date: Wed, 3 Mar 2021 17:22:40 +0100 Subject: [PATCH] cleanup and success messages --- commands/add.go | 2 +- commands/clean.go | 2 +- commands/close.go | 2 +- commands/{create.go => open.go} | 2 +- common/githubcommands.go | 76 ++++++++++++++++----------------- 5 files changed, 41 insertions(+), 43 deletions(-) rename commands/{create.go => open.go} (93%) diff --git a/commands/add.go b/commands/add.go index 6683032..fedea8e 100644 --- a/commands/add.go +++ b/commands/add.go @@ -7,7 +7,7 @@ import ( func cmdAdd() *clif.Command { cb := func(c *clif.Command, out clif.Output, in clif.Input) { - githubcommands.CreateCard(c, in) + githubcommands.CreateCard(c, in, out) } return clif.NewCommand("add", "Add a new card", cb). diff --git a/commands/clean.go b/commands/clean.go index 07b5c0e..6149035 100644 --- a/commands/clean.go +++ b/commands/clean.go @@ -7,7 +7,7 @@ import ( func cmdClean() *clif.Command { cb := func(c *clif.Command, out clif.Output, in clif.Input) { - githubcommands.Cleanup(c) + githubcommands.Cleanup(c, out) } return clif.NewCommand("clean", "Archive all cards in the 'done' column", cb) diff --git a/commands/close.go b/commands/close.go index 5601f5e..d157244 100644 --- a/commands/close.go +++ b/commands/close.go @@ -7,7 +7,7 @@ import ( func cmdClose() *clif.Command { cb := func(c *clif.Command, out clif.Output, in clif.Input) { - githubcommands.CloseProject(c, in) + githubcommands.CloseProject(c, in, out) } return clif.NewCommand("close", "Close a project", cb). diff --git a/commands/create.go b/commands/open.go similarity index 93% rename from commands/create.go rename to commands/open.go index 598e05b..7af1ea7 100644 --- a/commands/create.go +++ b/commands/open.go @@ -8,7 +8,7 @@ import ( func cmdOpen() *clif.Command { cb := func(c *clif.Command, out clif.Output, in clif.Input) { - githubcommands.OpenProject(c, in) + githubcommands.OpenProject(c, in, out) } return clif.NewCommand("open", "Open a new project", cb). diff --git a/common/githubcommands.go b/common/githubcommands.go index 6e1a6b4..1de7324 100644 --- a/common/githubcommands.go +++ b/common/githubcommands.go @@ -28,7 +28,7 @@ type CardslistItem struct { project *github.Project } -func Cleanup(c *clif.Command) { +func Cleanup(c *clif.Command, out clif.Output) { client := login(c) for _, project := range getProjects(client) { @@ -38,32 +38,34 @@ func Cleanup(c *clif.Command) { if card.GetColumnName() == "done" { fmt.Println("Archived", card.GetNote(), "in", project.GetName()) archived := true - client.Projects.UpdateProjectCard(ctx, card.GetID(), &github.ProjectCardOptions{Archived: &archived}) - + _, _, err := client.Projects.UpdateProjectCard(ctx, card.GetID(), &github.ProjectCardOptions{Archived: &archived}) + if err == nil { + out.Printf("\n Archived <" + card.GetNote() + "> in <" + project.GetName() + "> project\n\n") + } } } } } -func CloseProject(c *clif.Command, in clif.Input) { +func CloseProject(c *clif.Command, in clif.Input, out clif.Output) { client := login(c) selectedProject := selectProject(client, in, c.Argument("project").String()) - /* - if c.Argument("name").String() == "" { - selectedProject = selectProject(client, in) - } - */ state := "closed" - client.Projects.UpdateProject(ctx, selectedProject.GetID(), &github.ProjectOptions{State: &state}) + project, _, err := client.Projects.UpdateProject(ctx, selectedProject.GetID(), &github.ProjectOptions{State: &state}) + + if err == nil { + out.Printf("\n project <" + project.GetName() + "> has been sucessfully closed\n\n") + } } -func OpenProject(c *clif.Command, in clif.Input) { + +func OpenProject(c *clif.Command, in clif.Input, out clif.Output) { _, repo := GetGitdir() if repo == nil { - OpenPersonalProject(c, in) + OpenPersonalProject(c, in, out) } else { space := "2" @@ -77,21 +79,18 @@ func OpenProject(c *clif.Command, in clif.Input) { }) } if space == "1" { - OpenPersonalProject(c, in) + OpenPersonalProject(c, in, out) } else { - OpenRepoProject(c, in, repo) + OpenRepoProject(c, in, out, repo) } } } -func OpenRepoProject(c *clif.Command, in clif.Input, repo *git.Repository) { +func OpenRepoProject(c *clif.Command, in clif.Input, out clif.Output, repo *git.Repository) { client := login(c) repositorydetails := getRepodetails(repo) - /* - fmt.Println("Owner: ", repositorydetails.owner) - fmt.Println("Repositoryname:", repositorydetails.name) - */ + name := "" if c.Argument("project").String() != "" { name = c.Argument("project").String() @@ -108,12 +107,15 @@ func OpenRepoProject(c *clif.Command, in clif.Input, repo *git.Repository) { } project, _, projectErr := client.Repositories.CreateProject(ctx, repositorydetails.owner, repositorydetails.name, &github.ProjectOptions{Name: &name, Body: &body, Public: &public}) if projectErr == nil { - client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "open"}) - client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "done"}) + _, _, openColumnErr := client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "open"}) + _, _, doneColumnErr := client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "done"}) + if projectErr == nil && openColumnErr == nil && doneColumnErr == nil { + out.Printf("\n project <" + project.GetName() + "> has been sucessfully opened\n\n") + } } } -func OpenPersonalProject(c *clif.Command, in clif.Input) { +func OpenPersonalProject(c *clif.Command, in clif.Input, out clif.Output) { client := login(c) name := "" @@ -134,8 +136,11 @@ func OpenPersonalProject(c *clif.Command, in clif.Input) { public = true } client.Projects.UpdateProject(ctx, project.GetID(), &github.ProjectOptions{Body: &body, Public: &public}) - client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "open"}) - client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "done"}) + _, _, openColumnErr := client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "open"}) + _, _, doneColumnErr := client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "done"}) + if projectErr == nil && openColumnErr == nil && doneColumnErr == nil { + out.Printf("\n project <" + project.GetName() + "> has been sucessfully opened\n\n") + } } } @@ -156,7 +161,6 @@ func GetStatus(c *clif.Command, out clif.Output) []CardslistItem { cards := getCards(client, project) out.Printf("\nList: " + project.GetName() + "\n") for _, card := range cards { - //fmt.Println(" <"+card.GetColumnName()+">", " ", card.GetNote()) out.Printf(strconv.Itoa(item) + "| <" + card.GetColumnName() + "> " + card.GetNote() + "\n") cardslist = append(cardslist, CardslistItem{ id: item, @@ -174,11 +178,6 @@ func MoveCard(c *clif.Command, out clif.Output, in clif.Input) { client := login(c) selectedProject := selectProject(client, in, c.Argument("project").String()) - /* - if c.Argument("project").String() == "" { - selectedProject = selectProject(client, in) - } - */ var selectedCard *github.ProjectCard if c.Option("card").String() == "" { @@ -198,17 +197,20 @@ func MoveCard(c *clif.Command, out clif.Output, in clif.Input) { } -func CreateCard(c *clif.Command, in clif.Input) { +func CreateCard(c *clif.Command, in clif.Input, out clif.Output) { client := login(c) selectedProject := selectProject(client, in, c.Argument("project").String()) projectColumns, _, _ := client.Projects.ListProjectColumns(ctx, selectedProject.GetID(), nil) - fmt.Println(projectColumns[0].GetID(), projectColumns[0].GetName()) message := in.Ask("What is the task", nil) - fmt.Println(message) - client.Projects.CreateProjectCard(ctx, projectColumns[0].GetID(), &github.ProjectCardOptions{Note: message}) + + card, _, cardErr := client.Projects.CreateProjectCard(ctx, projectColumns[0].GetID(), &github.ProjectCardOptions{Note: message}) + + if cardErr == nil { + out.Printf("\n added Card <" + card.GetNote() + "> sucessfully to <" + selectedProject.GetName() + "> project\n\n") + } } func selectColumn(client *github.Client, in clif.Input, project *github.Project) *github.ProjectColumn { @@ -270,10 +272,7 @@ func getProjects(client *github.Client) []*github.Project { if repo != nil { repositorydetails := getRepodetails(repo) - /* - fmt.Println("Owner: ", repositorydetails.owner) - fmt.Println("Repositoryname:", repositorydetails.name) - */ + repoprojects, _, _ := client.Repositories.ListProjects(ctx, repositorydetails.owner, repositorydetails.name, nil) userprojects = append(userprojects, repoprojects...) @@ -288,7 +287,6 @@ func getCards(client *github.Client, project *github.Project) []*github.ProjectC projectColumns, _, _ := client.Projects.ListProjectColumns(ctx, project.GetID(), nil) for _, column := range projectColumns { - // fmt.Println(column.GetName()) cards, _, _ := client.Projects.ListProjectCards(ctx, column.GetID(), nil) for _, card := range cards {