-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
453 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/pPrecel/PKUP/internal/logo" | ||
"github.com/pPrecel/PKUP/pkg/compose" | ||
"github.com/pPrecel/PKUP/pkg/period" | ||
"github.com/pPrecel/PKUP/pkg/report" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func NewComposeCommand(opts *Options) *cli.Command { | ||
since, until := period.GetCurrentPKUP() | ||
actionsOpts := composeActionOpts{ | ||
Options: opts, | ||
since: *cli.NewTimestamp(since), | ||
until: *cli.NewTimestamp(until), | ||
} | ||
|
||
return &cli.Command{ | ||
Name: "compose", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "config", | ||
DefaultText: ".pkupcompose.yaml", | ||
Destination: &actionsOpts.config, | ||
Action: func(_ *cli.Context, path string) error { | ||
path, err := filepath.Abs(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
actionsOpts.config = path | ||
return nil | ||
}, | ||
}, | ||
&cli.TimestampFlag{ | ||
Name: "since", | ||
Usage: "timestamp used to get commits and render report - foramt " + report.PeriodFormat, | ||
Layout: report.PeriodFormat, | ||
Timezone: time.Local, | ||
Action: func(_ *cli.Context, time *time.Time) error { | ||
actionsOpts.since.SetTimestamp(*time) | ||
return nil | ||
}, | ||
}, | ||
&cli.TimestampFlag{ | ||
Name: "until", | ||
Usage: "timestamp used to get commits and render report - foramt " + report.PeriodFormat, | ||
Layout: report.PeriodFormat, | ||
Timezone: time.Local, | ||
Action: func(_ *cli.Context, t *time.Time) error { | ||
actionsOpts.until.SetTimestamp(t.Add(time.Hour*24 - time.Second)) | ||
return nil | ||
}, | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "ci", | ||
Usage: "print output using standard log", | ||
Category: loggingCategory, | ||
Destination: &actionsOpts.ci, | ||
}, | ||
}, | ||
Before: func(_ *cli.Context) error { | ||
// print logo before any action | ||
fmt.Printf("%s\n\n", logo.Build(opts.BuildVersion)) | ||
|
||
return nil | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
return composeCommandAction(ctx, &actionsOpts) | ||
}, | ||
} | ||
} | ||
|
||
func composeCommandAction(ctx *cli.Context, opts *composeActionOpts) error { | ||
cfg, err := compose.ReadConfig(opts.config) | ||
if err != nil { | ||
return fmt.Errorf("failed to read config from path '%s': %s", opts.config, err.Error()) | ||
} | ||
|
||
return compose.New(ctx.Context, opts.Log).ForConfig(cfg, compose.ComposeOpts{ | ||
Since: *opts.since.Value(), | ||
Until: *opts.until.Value(), | ||
Ci: opts.ci, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package compose | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pPrecel/PKUP/pkg/github" | ||
) | ||
|
||
func buildAuthors(remoteClients map[string]github.Client, user User) (map[string][]string, error) { | ||
authorsMap := map[string][]string{} | ||
|
||
// get signatures for opensource if not empty | ||
if user.Username != "" { | ||
signatures, err := remoteClients[""].GetUserSignatures(user.Username) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to list user signatures for opensource: %s", err.Error()) | ||
} | ||
|
||
authorsMap[""] = signatures | ||
} | ||
|
||
// get signatures for every enterprise | ||
for url, username := range user.EnterpriseUsernames { | ||
signatures, err := remoteClients[url].GetUserSignatures(username) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to list user signatures for '%s': %s", url, err.Error()) | ||
} | ||
|
||
authorsMap[url] = signatures | ||
} | ||
|
||
return authorsMap, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package compose | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/pPrecel/PKUP/pkg/github" | ||
"github.com/pterm/pterm" | ||
) | ||
|
||
func buildClients(ctx context.Context, logger *pterm.Logger, config *Config, buildClient buildClientFunc) (map[string]github.Client, error) { | ||
urlClients := map[string]github.Client{} | ||
|
||
var err error | ||
urlClients, err = appendRemoteClients(urlClients, ctx, logger, config.Orgs, buildClient) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
urlClients, err = appendRemoteClients(urlClients, ctx, logger, config.Repos, buildClient) | ||
|
||
return urlClients, err | ||
} | ||
|
||
func appendRemoteClients(dest map[string]github.Client, ctx context.Context, logger *pterm.Logger, remotes []Remote, buildClient buildClientFunc) (map[string]github.Client, error) { | ||
for i := range remotes { | ||
if _, ok := dest[remotes[i].EnterpriseUrl]; !ok { | ||
var err error | ||
dest[remotes[i].EnterpriseUrl], err = buildClient( | ||
ctx, | ||
logger, | ||
github.ClientOpts{ | ||
EnterpriseURL: remotes[i].EnterpriseUrl, | ||
Token: remotes[i].Token, | ||
}, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to build client for '%s': %s", remotes[i].Name, err.Error()) | ||
} | ||
} | ||
} | ||
|
||
return dest, nil | ||
} |
Oops, something went wrong.