Skip to content

Commit

Permalink
add board view
Browse files Browse the repository at this point in the history
  • Loading branch information
mms-gianni committed Mar 4, 2021
1 parent 0673b75 commit 7160398
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ You find older releases here : https://github.com/mms-gianni/git-project/release
## Quick start

### Create your first personl project in your profile
Open creates a new project. 2 columns are added by default (open, done). Feel free to change them or add more.
```
git project open -U
```
Expand Down
3 changes: 1 addition & 2 deletions commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ func cmdAdd() *clif.Command {

return clif.NewCommand("add", "Add a new card", cb).
NewArgument("project", "Show only repo", "", false, false).
NewArgument("note", "Note to add", "<empty>", false, false).
NewArgument("status", "Status", "open", false, false)
NewArgument("note", "Note to add", "", false, false)
}

func init() {
Expand Down
19 changes: 19 additions & 0 deletions commands/board.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package commands

import (
githubcommands "github.com/mms-gianni/git-project/common"
"gopkg.in/ukautz/clif.v1"
)

func cmdBoard() *clif.Command {
cb := func(c *clif.Command, out clif.Output) {
githubcommands.GetBoard(c, out)
}

return clif.NewCommand("board", "List projects and cards", cb).
NewArgument("project", "Show only this project", "", false, false)
}

func init() {
Commands = append(Commands, cmdBoard)
}
76 changes: 71 additions & 5 deletions common/githubcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package common
import (
"context"
"fmt"
"os"
"regexp"
"strconv"
"strings"

"github.com/go-git/go-git/v5"
"github.com/google/go-github/v33/github"
"github.com/olekukonko/tablewriter"
"golang.org/x/oauth2"
"gopkg.in/ukautz/clif.v1"
)
Expand All @@ -35,7 +37,7 @@ func Cleanup(c *clif.Command, out clif.Output) {

for _, project := range getProjects(client, c.Option("username").String(), c.Option("organisations").String()) {

cards := getCards(client, project)
cards, _ := getCards(client, project)
for _, card := range cards {
if card.GetColumnName() == "done" {
fmt.Println("Archived", card.GetNote(), "in", project.GetName())
Expand Down Expand Up @@ -160,7 +162,7 @@ func GetStatus(c *clif.Command, out clif.Output) []CardslistItem {
item := 0
var cardslist []CardslistItem
for _, project := range projectslist {
cards := getCards(client, project)
cards, _ := getCards(client, project)
out.Printf("\n<subline>Project: " + project.GetName() + "<reset>\n")
for _, card := range cards {
title := ""
Expand All @@ -184,6 +186,70 @@ func GetStatus(c *clif.Command, out clif.Output) []CardslistItem {
return cardslist
}

func GetBoard(c *clif.Command, out clif.Output) {
client := login(c)

var projectslist []*github.Project
if c.Argument("project").String() == "" {
projectslist = getProjects(client, c.Option("username").String(), c.Option("organisations").String())
} else {
projectslist = append(projectslist, getProjectByName(client, c.Argument("project").String(), c.Option("username").String(), c.Option("organisations").String()))
}

for _, project := range projectslist {
out.Printf("\n\n<important> Project: " + project.GetName() + " <reset>\n")

projectColumns, _, _ := client.Projects.ListProjectColumns(ctx, project.GetID(), nil)

headers := []string{}
columnCardsList := [][]*github.ProjectCard{}

max := 0
for _, column := range projectColumns {
headers = append(headers, column.GetName())
cards, _, _ := client.Projects.ListProjectCards(ctx, column.GetID(), nil)
columnCardsList = append(columnCardsList, cards)
if len(cards) > max {
max = len(cards)
}
}

ntable := tablewriter.NewWriter(os.Stdout)
ntable.SetHeader(headers)
ntable.SetAutoMergeCells(true)
ntable.SetRowLine(true)

//fmt.Println("coumns", len(columnCardsList))

for row := 0; row < max; row++ {
//fmt.Println("row", row)
var cellcontent = []string{}
for cell := 0; cell < len(columnCardsList); cell++ {
//fmt.Println("cell", cell, len(columnCardsList[cell]))

if row < len(columnCardsList[cell]) {
//fmt.Println(columnCardsList[cell][row].GetNote())

title := ""
if columnCardsList[cell][row].GetContentURL() != "" {
issue := getIssueDetails(c, columnCardsList[cell][row].GetContentURL())
title = "Issue #" + strconv.Itoa(issue.GetNumber()) + " : " + issue.GetTitle()
} else {
title = columnCardsList[cell][row].GetNote()
}

cellcontent = append(cellcontent, title)
} else {
//fmt.Println("-")
cellcontent = append(cellcontent, ".")
}
}
ntable.Append(cellcontent)
}
ntable.Render()
}
}

func getIssueDetails(c *clif.Command, issueURL string) *github.Issue {
client := login(c)

Expand All @@ -202,7 +268,7 @@ func MoveCard(c *clif.Command, out clif.Output, in clif.Input) {
selectedProject := selectProject(client, in, c.Argument("project").String(), c.Option("username").String(), c.Option("organisations").String())

var selectedCard *github.ProjectCard
cards := getCards(client, selectedProject)
cards, _ := getCards(client, selectedProject)
if c.Option("card").String() == "" {
selectedCard = selectCard(cards, in)
} else {
Expand Down Expand Up @@ -325,7 +391,7 @@ func getProjects(client *github.Client, username string, organisations string) [
return userprojects
}

func getCards(client *github.Client, project *github.Project) []*github.ProjectCard {
func getCards(client *github.Client, project *github.Project) ([]*github.ProjectCard, []*github.ProjectColumn) {
var cardslist []*github.ProjectCard

projectColumns, _, _ := client.Projects.ListProjectColumns(ctx, project.GetID(), nil)
Expand All @@ -339,5 +405,5 @@ func getCards(client *github.Client, project *github.Project) []*github.ProjectC
}
}

return cardslist
return cardslist, projectColumns
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/google/go-github/v33 v33.0.0
github.com/gosuri/uilive v0.0.4 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/olekukonko/tablewriter v0.0.5
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/ukautz/reflekt v0.0.0-20180611090553-6ce38d64d188 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 h1:LiZB1h0GIcudcDci2bxbqI6DXV8bF8POAnArqvRrIyw=
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0/go.mod h1:F/7q8/HZz+TXjlsoZQQKVYvXTZaFH4QRa3y+j1p7MS0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
Expand Down

0 comments on commit 7160398

Please sign in to comment.