Skip to content

Commit 48e7394

Browse files
committed
cleanup and success messages
1 parent 8fe338a commit 48e7394

File tree

5 files changed

+41
-43
lines changed

5 files changed

+41
-43
lines changed

commands/add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func cmdAdd() *clif.Command {
99
cb := func(c *clif.Command, out clif.Output, in clif.Input) {
10-
githubcommands.CreateCard(c, in)
10+
githubcommands.CreateCard(c, in, out)
1111
}
1212

1313
return clif.NewCommand("add", "Add a new card", cb).

commands/clean.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func cmdClean() *clif.Command {
99
cb := func(c *clif.Command, out clif.Output, in clif.Input) {
10-
githubcommands.Cleanup(c)
10+
githubcommands.Cleanup(c, out)
1111
}
1212

1313
return clif.NewCommand("clean", "Archive all cards in the 'done' column", cb)

commands/close.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func cmdClose() *clif.Command {
99
cb := func(c *clif.Command, out clif.Output, in clif.Input) {
10-
githubcommands.CloseProject(c, in)
10+
githubcommands.CloseProject(c, in, out)
1111
}
1212

1313
return clif.NewCommand("close", "Close a project", cb).

commands/create.go commands/open.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func cmdOpen() *clif.Command {
1010
cb := func(c *clif.Command, out clif.Output, in clif.Input) {
11-
githubcommands.OpenProject(c, in)
11+
githubcommands.OpenProject(c, in, out)
1212
}
1313

1414
return clif.NewCommand("open", "Open a new project", cb).

common/githubcommands.go

+37-39
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type CardslistItem struct {
2828
project *github.Project
2929
}
3030

31-
func Cleanup(c *clif.Command) {
31+
func Cleanup(c *clif.Command, out clif.Output) {
3232
client := login(c)
3333

3434
for _, project := range getProjects(client) {
@@ -38,32 +38,34 @@ func Cleanup(c *clif.Command) {
3838
if card.GetColumnName() == "done" {
3939
fmt.Println("Archived", card.GetNote(), "in", project.GetName())
4040
archived := true
41-
client.Projects.UpdateProjectCard(ctx, card.GetID(), &github.ProjectCardOptions{Archived: &archived})
42-
41+
_, _, err := client.Projects.UpdateProjectCard(ctx, card.GetID(), &github.ProjectCardOptions{Archived: &archived})
42+
if err == nil {
43+
out.Printf("\n<success> Archived <" + card.GetNote() + "> in <" + project.GetName() + "> project<reset>\n\n")
44+
}
4345
}
4446
}
4547

4648
}
4749
}
4850

49-
func CloseProject(c *clif.Command, in clif.Input) {
51+
func CloseProject(c *clif.Command, in clif.Input, out clif.Output) {
5052
client := login(c)
5153

5254
selectedProject := selectProject(client, in, c.Argument("project").String())
53-
/*
54-
if c.Argument("name").String() == "" {
55-
selectedProject = selectProject(client, in)
56-
}
57-
*/
5855

5956
state := "closed"
60-
client.Projects.UpdateProject(ctx, selectedProject.GetID(), &github.ProjectOptions{State: &state})
57+
project, _, err := client.Projects.UpdateProject(ctx, selectedProject.GetID(), &github.ProjectOptions{State: &state})
58+
59+
if err == nil {
60+
out.Printf("\n<success> project <" + project.GetName() + "> has been sucessfully closed<reset>\n\n")
61+
}
6162
}
62-
func OpenProject(c *clif.Command, in clif.Input) {
63+
64+
func OpenProject(c *clif.Command, in clif.Input, out clif.Output) {
6365
_, repo := GetGitdir()
6466

6567
if repo == nil {
66-
OpenPersonalProject(c, in)
68+
OpenPersonalProject(c, in, out)
6769
} else {
6870
space := "2"
6971

@@ -77,21 +79,18 @@ func OpenProject(c *clif.Command, in clif.Input) {
7779
})
7880
}
7981
if space == "1" {
80-
OpenPersonalProject(c, in)
82+
OpenPersonalProject(c, in, out)
8183
} else {
82-
OpenRepoProject(c, in, repo)
84+
OpenRepoProject(c, in, out, repo)
8385
}
8486
}
8587
}
8688

87-
func OpenRepoProject(c *clif.Command, in clif.Input, repo *git.Repository) {
89+
func OpenRepoProject(c *clif.Command, in clif.Input, out clif.Output, repo *git.Repository) {
8890
client := login(c)
8991

9092
repositorydetails := getRepodetails(repo)
91-
/*
92-
fmt.Println("Owner: ", repositorydetails.owner)
93-
fmt.Println("Repositoryname:", repositorydetails.name)
94-
*/
93+
9594
name := ""
9695
if c.Argument("project").String() != "" {
9796
name = c.Argument("project").String()
@@ -108,12 +107,15 @@ func OpenRepoProject(c *clif.Command, in clif.Input, repo *git.Repository) {
108107
}
109108
project, _, projectErr := client.Repositories.CreateProject(ctx, repositorydetails.owner, repositorydetails.name, &github.ProjectOptions{Name: &name, Body: &body, Public: &public})
110109
if projectErr == nil {
111-
client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "open"})
112-
client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "done"})
110+
_, _, openColumnErr := client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "open"})
111+
_, _, doneColumnErr := client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "done"})
112+
if projectErr == nil && openColumnErr == nil && doneColumnErr == nil {
113+
out.Printf("\n<success> project <" + project.GetName() + "> has been sucessfully opened<reset>\n\n")
114+
}
113115
}
114116
}
115117

116-
func OpenPersonalProject(c *clif.Command, in clif.Input) {
118+
func OpenPersonalProject(c *clif.Command, in clif.Input, out clif.Output) {
117119
client := login(c)
118120

119121
name := ""
@@ -134,8 +136,11 @@ func OpenPersonalProject(c *clif.Command, in clif.Input) {
134136
public = true
135137
}
136138
client.Projects.UpdateProject(ctx, project.GetID(), &github.ProjectOptions{Body: &body, Public: &public})
137-
client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "open"})
138-
client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "done"})
139+
_, _, openColumnErr := client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "open"})
140+
_, _, doneColumnErr := client.Projects.CreateProjectColumn(ctx, project.GetID(), &github.ProjectColumnOptions{Name: "done"})
141+
if projectErr == nil && openColumnErr == nil && doneColumnErr == nil {
142+
out.Printf("\n<success> project <" + project.GetName() + "> has been sucessfully opened<reset>\n\n")
143+
}
139144
}
140145

141146
}
@@ -156,7 +161,6 @@ func GetStatus(c *clif.Command, out clif.Output) []CardslistItem {
156161
cards := getCards(client, project)
157162
out.Printf("\n<subline>List: " + project.GetName() + "<reset>\n")
158163
for _, card := range cards {
159-
//fmt.Println(" <"+card.GetColumnName()+">", " ", card.GetNote())
160164
out.Printf(strconv.Itoa(item) + "| <" + card.GetColumnName() + "> " + card.GetNote() + "\n")
161165
cardslist = append(cardslist, CardslistItem{
162166
id: item,
@@ -174,11 +178,6 @@ func MoveCard(c *clif.Command, out clif.Output, in clif.Input) {
174178
client := login(c)
175179

176180
selectedProject := selectProject(client, in, c.Argument("project").String())
177-
/*
178-
if c.Argument("project").String() == "" {
179-
selectedProject = selectProject(client, in)
180-
}
181-
*/
182181

183182
var selectedCard *github.ProjectCard
184183
if c.Option("card").String() == "" {
@@ -198,17 +197,20 @@ func MoveCard(c *clif.Command, out clif.Output, in clif.Input) {
198197

199198
}
200199

201-
func CreateCard(c *clif.Command, in clif.Input) {
200+
func CreateCard(c *clif.Command, in clif.Input, out clif.Output) {
202201
client := login(c)
203202

204203
selectedProject := selectProject(client, in, c.Argument("project").String())
205204

206205
projectColumns, _, _ := client.Projects.ListProjectColumns(ctx, selectedProject.GetID(), nil)
207-
fmt.Println(projectColumns[0].GetID(), projectColumns[0].GetName())
208206

209207
message := in.Ask("What is the task", nil)
210-
fmt.Println(message)
211-
client.Projects.CreateProjectCard(ctx, projectColumns[0].GetID(), &github.ProjectCardOptions{Note: message})
208+
209+
card, _, cardErr := client.Projects.CreateProjectCard(ctx, projectColumns[0].GetID(), &github.ProjectCardOptions{Note: message})
210+
211+
if cardErr == nil {
212+
out.Printf("\n<success> added Card <" + card.GetNote() + "> sucessfully to <" + selectedProject.GetName() + "> project<reset>\n\n")
213+
}
212214

213215
}
214216
func selectColumn(client *github.Client, in clif.Input, project *github.Project) *github.ProjectColumn {
@@ -270,10 +272,7 @@ func getProjects(client *github.Client) []*github.Project {
270272

271273
if repo != nil {
272274
repositorydetails := getRepodetails(repo)
273-
/*
274-
fmt.Println("Owner: ", repositorydetails.owner)
275-
fmt.Println("Repositoryname:", repositorydetails.name)
276-
*/
275+
277276
repoprojects, _, _ := client.Repositories.ListProjects(ctx, repositorydetails.owner, repositorydetails.name, nil)
278277

279278
userprojects = append(userprojects, repoprojects...)
@@ -288,7 +287,6 @@ func getCards(client *github.Client, project *github.Project) []*github.ProjectC
288287
projectColumns, _, _ := client.Projects.ListProjectColumns(ctx, project.GetID(), nil)
289288

290289
for _, column := range projectColumns {
291-
// fmt.Println(column.GetName())
292290
cards, _, _ := client.Projects.ListProjectCards(ctx, column.GetID(), nil)
293291

294292
for _, card := range cards {

0 commit comments

Comments
 (0)