Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
Refresh with new project fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostman committed Aug 14, 2023
1 parent 0175aad commit 0897143
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bin

# Binaries for programs and plugins
*.exe
*.exe~
Expand Down
46 changes: 46 additions & 0 deletions cmd/gh-project-dump/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"context"
"fmt"
"log"
"os"

"github.com/urfave/cli/v2"
"go.githedgehog.com/gh-tools/pkg/github"
)

func main() {
app := &cli.App{
Name: "gh-project-dump",
Version: "0.0.0", // TODO load proper version using ld flags
Action: func(ctx *cli.Context) error {
gh := github.New()

items, err := gh.GetProjectItems(context.Background(), "PVT_kwDOBvRah84AMA6Y")
if err != nil {
log.Printf("Error getting github items: %#v\n", err)
return err
}
log.Println("Loaded project items:", len(items))

for _, item := range items {
fmt.Println(">>>", item.Milestone(), "<<<", item.Number(), item.Title(), item.Status(), item.Sprint(), item.Assignees(), item.Progress(), item.Component(), item.Estimate(), item.Jira(), item.Resource())
}

return nil
},
Commands: []*cli.Command{
{
Name: "test",
Action: func(ctx *cli.Context) error {
return nil
},
},
},
}

if err := app.Run(os.Args); err != nil {
panic(err) // TODO use log
}
}
51 changes: 49 additions & 2 deletions pkg/github/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ type ProjectItem struct {
Type string
FStatus FSingleSelect `graphql:"status: fieldValueByName(name: \"Status\")"`
FEstimate FNumber `graphql:"estimate: fieldValueByName(name: \"Estimate\")"`
FIteration FIteration `graphql:"iteration: fieldValueByName(name: \"Iteration\")"`
FSprint FIteration `graphql:"iteration: fieldValueByName(name: \"Sprint\")"`
FJira FText `graphql:"jira: fieldValueByName(name: \"Jira\")"`
FMilestone FSingleSelect `graphql:"milestone: fieldValueByName(name: \"DevMilestone\")"`
FProgress FSingleSelect `graphql:"progress: fieldValueByName(name: \"Progress\")"`
FComponent FSingleSelect `graphql:"component: fieldValueByName(name: \"Component\")"`
Content struct {
Issue struct {
Title string
Expand All @@ -82,13 +85,47 @@ func (i ProjectItem) Estimate() float64 {
}

func (i ProjectItem) Sprint() string {
return i.FIteration.V()
return i.FSprint.V()
}

func (i ProjectItem) Jira() string {
return i.FJira.V()
}

func (i ProjectItem) Milestone() string {
return i.FMilestone.V()
}

func (i ProjectItem) Progress() string {
return i.FProgress.V()
}

func (i ProjectItem) ProgressPercentage() float32 {
pr := i.Progress()
if len(pr) == 0 {
return 0
}

switch pr[0] {
case '1':
return 0.1
case '2':
return 0.3
case '4':
return 0.5
case '6':
return 0.7
case '8':
return 0.9
}

return 0
}

func (i ProjectItem) Component() string {
return i.FComponent.V()
}

func (i ProjectItem) Title() string {
return i.Content.Issue.Title
}
Expand Down Expand Up @@ -117,6 +154,16 @@ func (i ProjectItem) Assignee() string {
return i.Content.Issue.Assignees.Nodes[0].Login
}

func (i ProjectItem) Assignees() []string {
assignees := make([]string, len(i.Content.Issue.Assignees.Nodes))

for i, node := range i.Content.Issue.Assignees.Nodes {
assignees[i] = node.Login
}

return assignees
}

func (i ProjectItem) String() string {
return fmt.Sprintf("Issue{%s %s est=%.1f iter=%s jira=%s}",
i.Resource(), i.Status(), i.Estimate(), i.Sprint(), i.Jira())
Expand Down

0 comments on commit 0897143

Please sign in to comment.