Skip to content

Commit

Permalink
MAJOR fix for for personal projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mms-gianni committed Mar 3, 2021
1 parent 7452ed4 commit ff69851
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@ Manage your github projects with your git cli
## Installation
Generate a token here : https://github.com/settings/tokens (You need to be loged in)

To export the Github username is optional. But it requred to access your personal profile projects.
### Mac
```
echo 'export GITHUB_TOKEN="asdfasdfasdfasdfasdfasdfasdfasdfasdf"' >> ~/.zshrc
echo 'export GITHUB_USERNAME="change-me-to-your-username"' >> ~/.zshrc
curl https://raw.githubusercontent.com/mms-gianni/git-project/master/cmd/git-project/git-project.mac.64bit -o /usr/local/bin/git-project
chmod +x /usr/local/bin/git-project
```

### Linux
```
echo 'export GITHUB_TOKEN="asdfasdfasdfasdfasdfasdfasdfasdfasdf"' >> ~/.bashrc
echo 'export GITHUB_USERNAME="change-me-to-your-username"' >> ~/.bashrc
curl https://raw.githubusercontent.com/mms-gianni/git-project/master/cmd/git-project/git-project.linux.64bit -o /usr/local/bin/git-project
chmod +x /usr/local/bin/git-project
```

### Windows
It works also on Windows. But since i have no windows in my basement, I have no idea how to install it (Help welcome :D )

You find older releases here : https://github.com/mms-gianni/git-project/releases

## Quick start

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

### Create a repository related project
Expand Down
2 changes: 1 addition & 1 deletion commands/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func cmdOpen() *clif.Command {
NewArgument("project", "Name of the new Project", "", false, false).
NewOption("description", "d", "Description", "", false, false).
NewFlag("public", "p", "Make this project public (Organisations only)", false).
NewFlag("profile", "u", "Open it in your user profile", false)
NewFlag("profile", "U", "Open it in your user profile", false)
}

func init() {
Expand Down
24 changes: 12 additions & 12 deletions common/githubcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type CardslistItem struct {
func Cleanup(c *clif.Command, out clif.Output) {
client := login(c)

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

cards := getCards(client, project)
for _, card := range cards {
Expand All @@ -51,7 +51,7 @@ func Cleanup(c *clif.Command, out clif.Output) {
func CloseProject(c *clif.Command, in clif.Input, out clif.Output) {
client := login(c)

selectedProject := selectProject(client, in, c.Argument("project").String())
selectedProject := selectProject(client, in, c.Argument("project").String(), c.Option("username").String())

state := "closed"
project, _, err := client.Projects.UpdateProject(ctx, selectedProject.GetID(), &github.ProjectOptions{State: &state})
Expand Down Expand Up @@ -150,9 +150,9 @@ func GetStatus(c *clif.Command, out clif.Output) []CardslistItem {

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

item := 0
Expand All @@ -177,7 +177,7 @@ func GetStatus(c *clif.Command, out clif.Output) []CardslistItem {
func MoveCard(c *clif.Command, out clif.Output, in clif.Input) {
client := login(c)

selectedProject := selectProject(client, in, c.Argument("project").String())
selectedProject := selectProject(client, in, c.Argument("project").String(), c.Option("username").String())

var selectedCard *github.ProjectCard
cards := getCards(client, selectedProject)
Expand All @@ -201,7 +201,7 @@ func MoveCard(c *clif.Command, out clif.Output, 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())
selectedProject := selectProject(client, in, c.Argument("project").String(), c.Option("username").String())

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

Expand Down Expand Up @@ -254,10 +254,10 @@ func selectCardByNote(cards []*github.ProjectCard, searchedCard string) *github.
return nil
}

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

userprojects := getProjects(client)
userprojects := getProjects(client, username)
for key, project := range userprojects {
choices[strconv.Itoa(key)] = project.GetName()
if project.GetName() == preselectedProject {
Expand All @@ -269,8 +269,8 @@ func selectProject(client *github.Client, in clif.Input, preselectedProject stri
return userprojects[selectedNr]
}

func getProjectByName(client *github.Client, projectname string) *github.Project {
userprojects := getProjects(client)
func getProjectByName(client *github.Client, projectname string, username string) *github.Project {
userprojects := getProjects(client, username)
for _, project := range userprojects {
if project.GetName() == projectname {
return project
Expand All @@ -279,11 +279,11 @@ func getProjectByName(client *github.Client, projectname string) *github.Project
return nil
}

func getProjects(client *github.Client) []*github.Project {
func getProjects(client *github.Client, username string) []*github.Project {

// https://pkg.go.dev/github.com/google/go-github/v33/github#OrganizationsService.ListProjects
// https://pkg.go.dev/github.com/google/go-github/v33/github#Project
userprojects, _, _ := client.Users.ListProjects(ctx, "mms-gianni", nil)
userprojects, _, _ := client.Users.ListProjects(ctx, username, nil)

_, repo := GetGitdir()

Expand Down
5 changes: 4 additions & 1 deletion main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
func addDefaultOptions(cli *clif.Cli) {
githubtoken := clif.NewOption("githubtoken", "t", "Private Github Token", "", true, false).
SetEnv("GITHUB_TOKEN")
cli.AddDefaultOptions(githubtoken)

githubusername := clif.NewOption("username", "u", "Github username", "", false, false).
SetEnv("GITHUB_USERNAME")
cli.AddDefaultOptions(githubtoken, githubusername)
}

func main() {
Expand Down

0 comments on commit ff69851

Please sign in to comment.