Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : add run feature for trello provider #592

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions api/dvmodel.proto
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ message Topic {
enum Driver {
UnknownDriver = 0;
GitHub = 1;
//GitLab = 2;
//Trello = 3;
Trello = 2;
//GitLab = 3;

//Jira = 4;
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/depviz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ var (
serverShutdownTimeout = serverFlags.Duration("shutdowm-timeout", 6*time.Second, "shutdown timeout") // nolint:gomnd
serverCORSAllowedOrigins = serverFlags.String("cors-allowed-origins", "*", "allowed CORS origins")
serverGitHubToken = serverFlags.String("github-token", "", "GitHub token")
serverTrelloToken = serverFlags.String("trello-token", "", "Trello token")
serverTrelloApiKey = serverFlags.String("trello-apikey", "", "Trello ApiKey")
serverNoAutoUpdate = serverFlags.Bool("no-auto-update", false, "don't auto-update projects in background")
serverGodmode = serverFlags.Bool("godmode", false, "enable dangerous API calls")
serverWithPprof = serverFlags.Bool("with-pprof", false, "enable pprof endpoints")
Expand All @@ -69,6 +71,8 @@ var (
runNoGraph = runFlags.Bool("no-graph", false, "don't generate graph (pull only)")
runResync = runFlags.Bool("resync", false, "resync already synced content")
runGitHubToken = runFlags.String("github-token", "", "GitHub token")
runTrelloToken = runFlags.String("trello-token", "", "Trello token")
runTrelloApikey = runFlags.String("trello-apikey", "", "Trello ApiKey")
runNoPert = runFlags.Bool("no-pert", false, "disable PERT computing")
runFormat = runFlags.String("format", "dot", "output format")
runVertical = runFlags.Bool("vertical", false, "vertical mode")
Expand Down Expand Up @@ -270,6 +274,8 @@ func execRun(ctx context.Context, args []string) error {
NoPull: *runNoPull,
Format: *runFormat,
Resync: *runResync,
TrelloToken: *runTrelloToken,
TrelloApiKey: *runTrelloApikey,
GitHubToken: *runGitHubToken,
ShowClosed: *runShowClosed,
HideIsolated: *runHideIsolated,
Expand Down Expand Up @@ -314,6 +320,8 @@ func execServer(ctx context.Context, args []string) error {
Realm: *serverRealm,
Godmode: *serverGodmode,
GitHubToken: *serverGitHubToken,
TrelloToken: *serverTrelloToken,
TrelloApiKey: *serverTrelloApiKey,
NoAutoUpdate: *serverNoAutoUpdate,
AutoUpdateTargets: targets,
AutoUpdateInterval: *serverAutoUpdateInterval,
Expand Down
6 changes: 6 additions & 0 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 31 additions & 7 deletions internal/dvcore/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"moul.io/depviz/v3/internal/dvparser"
"moul.io/depviz/v3/internal/dvstore"
"moul.io/depviz/v3/internal/githubprovider"
"moul.io/depviz/v3/internal/trelloprovider"
"moul.io/graphman"
"moul.io/graphman/viz"
"moul.io/multipmuri"
Expand All @@ -30,9 +31,10 @@ type RunOpts struct {

// pull

GitHubToken string
GitHubToken string
TrelloToken string
TrelloApiKey string
// GitLabToken string
// TrelloToken string
// JiraToken string
Resync bool

Expand Down Expand Up @@ -61,7 +63,7 @@ func Run(h *cayley.Handle, args []string, opts RunOpts) error {
}

if !opts.NoPull {
_, err := PullAndSave(targets, h, opts.Schema, opts.GitHubToken, opts.Resync, opts.Logger)
_, err := PullAndSave(targets, h, opts.Schema, opts.GitHubToken, opts.TrelloToken, opts.TrelloApiKey, opts.Resync, opts.Logger)
if err != nil {
return fmt.Errorf("pull: %w", err)
}
Expand All @@ -76,7 +78,7 @@ func Run(h *cayley.Handle, args []string, opts RunOpts) error {
WithoutPRs: opts.HidePRs,
WithoutExternalDeps: opts.HideExternalDeps,
}
tasks, err := dvstore.LoadTasks(h, opts.Schema, filters, opts.Logger)
tasks, err := dvstore.LoadTasks(h, opts.Schema, opts.TrelloToken, opts.TrelloApiKey, filters, opts.Logger)
if err != nil {
return fmt.Errorf("load tasks: %w", err)
}
Expand Down Expand Up @@ -152,8 +154,8 @@ func Run(h *cayley.Handle, args []string, opts RunOpts) error {
return nil
}

func PullAndSave(targets []multipmuri.Entity, h *cayley.Handle, schema *schema.Config, githubToken string, resync bool, logger *zap.Logger) (bool, error) {
batches := pullBatches(targets, h, githubToken, resync, logger)
func PullAndSave(targets []multipmuri.Entity, h *cayley.Handle, schema *schema.Config, githubToken string, trelloToken string, trelloApiKey string, resync bool, logger *zap.Logger) (bool, error) {
batches := pullBatches(targets, h, githubToken, trelloToken, trelloApiKey, resync, logger)
if len(batches) > 0 {
err := saveBatches(h, schema, batches)
if err != nil {
Expand All @@ -164,7 +166,7 @@ func PullAndSave(targets []multipmuri.Entity, h *cayley.Handle, schema *schema.C
return false, nil
}

func pullBatches(targets []multipmuri.Entity, h *cayley.Handle, githubToken string, resync bool, logger *zap.Logger) []dvmodel.Batch {
func pullBatches(targets []multipmuri.Entity, h *cayley.Handle, githubToken string, trelloToken string, trelloApiKey string, resync bool, logger *zap.Logger) []dvmodel.Batch {
// FIXME: handle the special '@me' target
var (
wg sync.WaitGroup
Expand Down Expand Up @@ -198,6 +200,16 @@ func pullBatches(targets []multipmuri.Entity, h *cayley.Handle, githubToken stri

githubprovider.FetchRepo(ctx, repo, githubToken, out, ghOpts)
}(target)
case multipmuri.TrelloProvider:
go func(board multipmuri.Entity) {
defer wg.Done()

ghOpts := trelloprovider.Opts{
Logger: logger.Named("trello"),
}

trelloprovider.FetchCard(ctx, board, trelloToken, trelloApiKey, target.LocalID()[1:], out, ghOpts)
}(target)
default:
// FIXME: clean context-based exit
panic(fmt.Sprintf("unsupported provider: %v", provider))
Expand Down Expand Up @@ -307,6 +319,18 @@ func graphmanPertConfig(tasks []dvmodel.Task, opts RunOpts) *graphman.PertConfig
// FIXME: styling
},
)
case dvmodel.Task_Card:
config.States = append(
config.States,
graphman.PertState{
ID: string(task.ID),
Title: task.Title,
DependsOn: dependsOn,
// FIXME: auto estimate (PERT)
// FIXME: DependsOn: milestone.DependsOn
// FIXME: styling
},
)
default:
opts.Logger.Warn("unsupported task kind", zap.Stringer("kind", task.Kind))
}
Expand Down
Loading