Skip to content

Commit

Permalink
refactor: rename pkg/repo to pkg/issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ahamidullah committed Dec 13, 2018
1 parent 5223319 commit 05fe300
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 65 deletions.
18 changes: 9 additions & 9 deletions cmd/cmd_airtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/spf13/viper"
"go.uber.org/zap"
"moul.io/depviz/pkg/airtabledb"
"moul.io/depviz/pkg/repo"
"moul.io/depviz/pkg/issues"
)

type airtableOptions struct {
Expand All @@ -26,7 +26,7 @@ type airtableOptions struct {
DestroyInvalidRecords bool `mapstructure:"airtable-destroy-invalid-records"`
TableNames []string

Targets []repo.Target `mapstructure:"targets"`
Targets []issues.Target `mapstructure:"targets"`
}

func (opts airtableOptions) String() string {
Expand Down Expand Up @@ -87,7 +87,7 @@ func (cmd *airtableCommand) airtableSyncCommand() *cobra.Command {
RunE: func(_ *cobra.Command, args []string) error {
opts := cmd.opts
var err error
if opts.Targets, err = repo.ParseTargets(args); err != nil {
if opts.Targets, err = issues.ParseTargets(args); err != nil {
return errors.Wrap(err, "invalid targets")
}
return airtableSync(&opts)
Expand All @@ -108,20 +108,20 @@ func airtableSync(opts *airtableOptions) error {
// prepare
//

issues, err := repo.LoadIssues(db, nil)
loadedIssues, err := issues.Load(db, nil)
if err != nil {
return errors.Wrap(err, "failed to load issues")
}
issues = issues.FilterByTargets(opts.Targets)
zap.L().Debug("fetch db entries", zap.Int("count", len(issues)))
loadedIssues = loadedIssues.FilterByTargets(opts.Targets)
zap.L().Debug("fetch db entries", zap.Int("count", len(loadedIssues)))

issueFeatures := make([]map[string]repo.IssueFeature, airtabledb.NumTables)
issueFeatures := make([]map[string]issues.IssueFeature, airtabledb.NumTables)
for i, _ := range issueFeatures {
issueFeatures[i] = make(map[string]repo.IssueFeature)
issueFeatures[i] = make(map[string]issues.IssueFeature)
}

// Parse the loaded issues into the issueFeature map.
for _, issue := range issues {
for _, issue := range loadedIssues {
// providers
issueFeatures[airtabledb.ProviderIndex][issue.Repository.Provider.ID] = issue.Repository.Provider

Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"moul.io/depviz/pkg/repo"
"moul.io/depviz/pkg/issues"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -53,7 +53,7 @@ func (cmd *dbCommand) dbDumpCommand() *cobra.Command {
}

func dbDump(opts *dbOptions) error {
issues := []*repo.Issue{}
issues := []*issues.Issue{}
if err := db.Find(&issues).Error; err != nil {
return err
}
Expand Down
38 changes: 19 additions & 19 deletions cmd/cmd_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"html"
"io"
"math"
"moul.io/depviz/pkg/repo"
"os"
"sort"
"strings"
Expand All @@ -17,19 +16,20 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"
"moul.io/depviz/pkg/issues"
)

type graphOptions struct {
Output string `mapstructure:"output"`
DebugGraph bool `mapstructure:"debug-graph"`
NoCompress bool `mapstructure:"no-compress"`
DarkTheme bool `mapstructure:"dark-theme"`
ShowClosed bool `mapstructure:"show-closed"`
ShowOrphans bool `mapstructure:"show-orphans"`
ShowPRs bool `mapstructure:"show-prs"`
Preview bool `mapstructure:"preview"`
Format string `mapstructure:"format"`
Targets repo.Targets `mapstructure:"targets"`
Output string `mapstructure:"output"`
DebugGraph bool `mapstructure:"debug-graph"`
NoCompress bool `mapstructure:"no-compress"`
DarkTheme bool `mapstructure:"dark-theme"`
ShowClosed bool `mapstructure:"show-closed"`
ShowOrphans bool `mapstructure:"show-orphans"`
ShowPRs bool `mapstructure:"show-prs"`
Preview bool `mapstructure:"preview"`
Format string `mapstructure:"format"`
Targets issues.Targets `mapstructure:"targets"`
// FocusMode
// NoExternal
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func (cmd *graphCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Com
RunE: func(_ *cobra.Command, args []string) error {
opts := cmd.opts
var err error
if opts.Targets, err = repo.ParseTargets(args); err != nil {
if opts.Targets, err = issues.ParseTargets(args); err != nil {
return errors.Wrap(err, "invalid targets")
}
return graph(&opts)
Expand All @@ -81,7 +81,7 @@ func (cmd *graphCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Com

func graph(opts *graphOptions) error {
zap.L().Debug("graph", zap.Stringer("opts", *opts))
issues, err := repo.LoadIssues(db, nil)
issues, err := issues.Load(db, nil)
if err != nil {
return errors.Wrap(err, "failed to load issues")
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func graph(opts *graphOptions) error {
return nil
}

func isIssueHidden(issue *repo.Issue, opts *graphOptions) bool {
func isIssueHidden(issue *issues.Issue, opts *graphOptions) bool {
if issue.IsHidden {
return true
}
Expand All @@ -132,7 +132,7 @@ func isIssueHidden(issue *repo.Issue, opts *graphOptions) bool {
return false
}

func graphviz(issues repo.Issues, opts *graphOptions) (string, error) {
func graphviz(issues issues.Issues, opts *graphOptions) (string, error) {
for _, issue := range issues {
if isIssueHidden(issue, opts) {
continue
Expand Down Expand Up @@ -339,7 +339,7 @@ func graphviz(issues repo.Issues, opts *graphOptions) (string, error) {
return g.String(), nil
}

func AddNodeToGraph(g *gographviz.Graph, i *repo.Issue, parent string) error {
func AddNodeToGraph(g *gographviz.Graph, i *issues.Issue, parent string) error {
attrs := map[string]string{}
attrs["label"] = GraphNodeTitle(i)
//attrs["xlabel"] = ""
Expand Down Expand Up @@ -376,7 +376,7 @@ func AddNodeToGraph(g *gographviz.Graph, i *repo.Issue, parent string) error {
)
}

func AddEdgesToGraph(g *gographviz.Graph, i *repo.Issue, opts *graphOptions, existingNodes map[string]bool) error {
func AddEdgesToGraph(g *gographviz.Graph, i *issues.Issue, opts *graphOptions, existingNodes map[string]bool) error {
if isIssueHidden(i, opts) {
return nil
}
Expand Down Expand Up @@ -416,11 +416,11 @@ func AddEdgesToGraph(g *gographviz.Graph, i *repo.Issue, opts *graphOptions, exi
return nil
}

func GraphNodeName(i *repo.Issue) string {
func GraphNodeName(i *issues.Issue) string {
return fmt.Sprintf(`%s#%s`, i.Path()[1:], i.Number())
}

func GraphNodeTitle(i *repo.Issue) string {
func GraphNodeTitle(i *issues.Issue) string {
title := fmt.Sprintf("%s: %s", GraphNodeName(i), i.Title)
title = strings.Replace(title, "|", "-", -1)
title = strings.Replace(html.EscapeString(wrap(title, 20)), "\n", "<br/>", -1)
Expand Down
10 changes: 5 additions & 5 deletions cmd/cmd_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"
"moul.io/depviz/pkg/repo"
"moul.io/depviz/pkg/issues"
)

type pullOptions struct {
Expand All @@ -18,7 +18,7 @@ type pullOptions struct {
GitlabToken string `mapstructure:"gitlab-token"`
// includeExternalDeps bool

Targets repo.Targets `mapstructure:"targets"`
Targets issues.Targets `mapstructure:"targets"`
}

func (opts pullOptions) String() string {
Expand Down Expand Up @@ -49,7 +49,7 @@ func (cmd *pullCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Comm
RunE: func(_ *cobra.Command, args []string) error {
opts := cmd.opts
var err error
if opts.Targets, err = repo.ParseTargets(args); err != nil {
if opts.Targets, err = issues.ParseTargets(args); err != nil {
return errors.Wrap(err, "invalid targets")
}
return pullAndCompute(&opts)
Expand All @@ -62,11 +62,11 @@ func (cmd *pullCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Comm
func pullAndCompute(opts *pullOptions) error {
zap.L().Debug("pull", zap.Stringer("opts", *opts))
if os.Getenv("DEPVIZ_NOPULL") != "1" {
if err := repo.PullAndCompute(opts.GithubToken, opts.GitlabToken, db, opts.Targets); err != nil {
if err := issues.PullAndCompute(opts.GithubToken, opts.GitlabToken, db, opts.Targets); err != nil {
return errors.Wrap(err, "failed to pull")
}
} else {
if err := repo.Compute(db); err != nil {
if err := issues.Compute(db); err != nil {
return errors.Wrap(err, "failed to compute")
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"encoding/json"
"moul.io/depviz/pkg/repo"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"moul.io/depviz/pkg/issues"
)

type runOptions struct {
Expand Down Expand Up @@ -47,11 +47,11 @@ func (cmd *runCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Comma
opts.GraphOptions = dc["graph"].(*graphCommand).opts
opts.PullOptions = dc["pull"].(*pullCommand).opts

targets, err := repo.ParseTargets(args)
targets, err := issues.ParseTargets(args)
if err != nil {
return errors.Wrap(err, "invalid targets")
}
additionalPulls, err := repo.ParseTargets(opts.AdditionalPulls)
additionalPulls, err := issues.ParseTargets(opts.AdditionalPulls)
if err != nil {
return errors.Wrap(err, "invalid targets")
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/cmd_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"path/filepath"
"strings"
"time"
"moul.io/depviz/pkg/repo"

"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
Expand All @@ -20,6 +19,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"moul.io/depviz/pkg/issues"
)

type webOptions struct {
Expand Down Expand Up @@ -63,7 +63,7 @@ func (cmd *webCommand) NewCobraCommand(dc map[string]DepvizCommand) *cobra.Comma
}

func webListIssues(w http.ResponseWriter, r *http.Request) {
issues, err := repo.LoadIssues(db, nil)
issues, err := issues.Load(db, nil)
if err != nil {
render.Render(w, r, ErrRender(err))
return
Expand All @@ -84,15 +84,15 @@ func webListIssues(w http.ResponseWriter, r *http.Request) {
}

func webGraphviz(r *http.Request) (string, error) {
targets, err := repo.ParseTargets(strings.Split(r.URL.Query().Get("targets"), ","))
targets, err := issues.ParseTargets(strings.Split(r.URL.Query().Get("targets"), ","))
if err != nil {
return "", err
}
opts := &graphOptions{
Targets: targets,
ShowClosed: r.URL.Query().Get("show-closed") == "1",
}
issues, err := repo.LoadIssues(db, nil)
issues, err := issues.Load(db, nil)
if err != nil {
return "", err
}
Expand Down
26 changes: 13 additions & 13 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/spf13/viper"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"moul.io/depviz/pkg/repo"
"moul.io/depviz/pkg/issues"
"moul.io/zapgorm"
)

Expand Down Expand Up @@ -57,13 +57,13 @@ func newRootCommand() *cobra.Command {
rootCmd.PersistentFlags().StringVarP(&dbPath, "db-path", "", "$HOME/.depviz.db", "database path")

// Add commands here.
cmds := map[string]DepvizCommand {
"pull": &pullCommand{},
"db": &dbCommand{},
cmds := map[string]DepvizCommand{
"pull": &pullCommand{},
"db": &dbCommand{},
"airtable": &airtableCommand{},
"graph": &graphCommand{},
"run": &runCommand{},
"web": &webCommand{},
"graph": &graphCommand{},
"run": &runCommand{},
"web": &webCommand{},
}

rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -118,12 +118,12 @@ func newRootCommand() *cobra.Command {
db.SingularTable(true)
db.LogMode(verbose)
if err := db.AutoMigrate(
repo.Issue{},
repo.Label{},
repo.Account{},
repo.Milestone{},
repo.Repository{},
repo.Provider{},
issues.Issue{},
issues.Label{},
issues.Account{},
issues.Milestone{},
issues.Repository{},
issues.Provider{},
).Error; err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/repo/github.go → pkg/issues/github.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repo
package issues

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/repo/gitlab.go → pkg/issues/gitlab.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repo
package issues

import (
"fmt"
Expand Down
8 changes: 4 additions & 4 deletions pkg/repo/issue.go → pkg/issues/issue.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repo
package issues

import (
"fmt"
Expand Down Expand Up @@ -66,7 +66,7 @@ func PullAndCompute(githubToken, gitlabToken string, db *gorm.DB, t Targets) err

// Compute loads issues from the given database, computes their fields, and stores the issues back into the database.
func Compute(db *gorm.DB) error {
issues, err := LoadIssues(db, nil)
issues, err := Load(db, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -183,8 +183,8 @@ func Compute(db *gorm.DB) error {
return nil
}

// LoadIssues returns the issues stored in the database.
func LoadIssues(db *gorm.DB, targets []Target) (Issues, error) {
// Load returns the issues stored in the database.
func Load(db *gorm.DB, targets []Target) (Issues, error) {
query := db.Model(Issue{}).Order("created_at")
if len(targets) > 0 {
return nil, fmt.Errorf("not implemented")
Expand Down
2 changes: 1 addition & 1 deletion pkg/repo/issue_test.go → pkg/issues/issue_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repo
package issues

import "fmt"

Expand Down
2 changes: 1 addition & 1 deletion pkg/repo/models.go → pkg/issues/models.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repo
package issues

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion pkg/repo/target.go → pkg/issues/target.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repo
package issues

import (
"fmt"
Expand Down
Loading

0 comments on commit 05fe300

Please sign in to comment.