Skip to content

Commit

Permalink
cleanup and success messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mms-gianni committed Mar 3, 2021
1 parent 8fe338a commit 48e7394
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 43 deletions.
2 changes: 1 addition & 1 deletion commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion commands/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion commands/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion commands/create.go → commands/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
76 changes: 37 additions & 39 deletions common/githubcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<success> Archived <" + card.GetNote() + "> in <" + project.GetName() + "> project<reset>\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<success> project <" + project.GetName() + "> has been sucessfully closed<reset>\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"

Expand All @@ -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()
Expand All @@ -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<success> project <" + project.GetName() + "> has been sucessfully opened<reset>\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 := ""
Expand All @@ -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<success> project <" + project.GetName() + "> has been sucessfully opened<reset>\n\n")
}
}

}
Expand All @@ -156,7 +161,6 @@ func GetStatus(c *clif.Command, out clif.Output) []CardslistItem {
cards := getCards(client, project)
out.Printf("\n<subline>List: " + project.GetName() + "<reset>\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,
Expand All @@ -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() == "" {
Expand All @@ -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<success> added Card <" + card.GetNote() + "> sucessfully to <" + selectedProject.GetName() + "> project<reset>\n\n")
}

}
func selectColumn(client *github.Client, in clif.Input, project *github.Project) *github.ProjectColumn {
Expand Down Expand Up @@ -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...)
Expand All @@ -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 {
Expand Down

0 comments on commit 48e7394

Please sign in to comment.