Skip to content

Commit

Permalink
fix some move shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
mms-gianni committed Mar 3, 2021
1 parent 689abea commit 5f25854
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ You find older releases here : https://github.com/mms-gianni/git-project/release

### Create your first personl project in your profile
```
git project create -u
git project open -u
```

### Create a repository related project
```
cd your-project
git project create
git project open
```

### Add a new task to a project
Expand Down Expand Up @@ -75,10 +75,15 @@ git project list
```

```
git project help create
git project help open
```

### create a personal list with one shot
```
git project create shoppinglist -p -d "helps me to remember what to buy"
```

### move a card arround
```
git project move shoppinglist -c milk -d done
```
2 changes: 1 addition & 1 deletion commands/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func cmdMove() *clif.Command {
return clif.NewCommand("move", "Move a card to anoter column", cb).
NewArgument("project", "Name of the project", "", false, false).
NewOption("card", "c", "Selected cards", "", false, false).
NewOption("destinateion", "d", "destination column", "closed", false, false)
NewOption("destination", "d", "Destination column", "", false, false)
}

func init() {
Expand Down
26 changes: 19 additions & 7 deletions common/githubcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,15 @@ func MoveCard(c *clif.Command, out clif.Output, in clif.Input) {
selectedProject := selectProject(client, in, c.Argument("project").String())

var selectedCard *github.ProjectCard
cards := getCards(client, selectedProject)
if c.Option("card").String() == "" {
selectedCard = selectCard(client, in, selectedProject)
selectedCard = selectCard(cards, in)
} else {
selectedCard = selectCardByNote(cards, c.Option("card").String())
}

var selectedColumn *github.ProjectColumn
if c.Option("card").String() == "" {
selectedColumn = selectColumn(client, in, selectedProject)
}
selectedColumn = selectColumn(client, in, selectedProject, c.Option("destination").String())

_, err := client.Projects.MoveProjectCard(ctx, selectedCard.GetID(), &github.ProjectCardMoveOptions{Position: "bottom", ColumnID: selectedColumn.GetID()})

Expand All @@ -213,22 +214,24 @@ func CreateCard(c *clif.Command, in clif.Input, out clif.Output) {
}

}
func selectColumn(client *github.Client, in clif.Input, project *github.Project) *github.ProjectColumn {
func selectColumn(client *github.Client, in clif.Input, project *github.Project, searchColumn string) *github.ProjectColumn {
choices := make(map[string]string)

columns, _, _ := client.Projects.ListProjectColumns(ctx, project.GetID(), nil)
for key, column := range columns {
choices[strconv.Itoa(key)] = "<" + column.GetName() + ">"
if column.GetName() == searchColumn {
return column
}
}

selectedNr, _ := strconv.Atoi(in.Choose("Select column to move the card", choices))
return columns[selectedNr]
}

func selectCard(client *github.Client, in clif.Input, project *github.Project) *github.ProjectCard {
func selectCard(cards []*github.ProjectCard, in clif.Input) *github.ProjectCard {
choices := make(map[string]string)

cards := getCards(client, project)
for key, card := range cards {
choices[strconv.Itoa(key)] = "<" + card.GetColumnName() + "> " + card.GetNote()
}
Expand All @@ -237,6 +240,15 @@ func selectCard(client *github.Client, in clif.Input, project *github.Project) *
return cards[selectedNr]
}

func selectCardByNote(cards []*github.ProjectCard, searchedCard string) *github.ProjectCard {
for _, card := range cards {
if card.GetNote() == searchedCard {
return card
}
}
return nil
}

func selectProject(client *github.Client, in clif.Input, preselectedProject string) *github.Project {
choices := make(map[string]string)

Expand Down

0 comments on commit 5f25854

Please sign in to comment.