-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #767 from Scalingo/feature/574/add_cli_changelog_c…
…ommand Feature/574/add cli changelog command
- Loading branch information
Showing
171 changed files
with
54,720 additions
and
2 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
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,28 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/urfave/cli" | ||
|
||
"github.com/Scalingo/cli/cmd/autocomplete" | ||
"github.com/Scalingo/cli/update" | ||
) | ||
|
||
var ( | ||
changelogCommand = cli.Command{ | ||
Name: "changelog", | ||
Category: "CLI Internals", | ||
Usage: "Show the Scalingo CLI changelog from last version", | ||
Description: `Show the Scalingo CLI changelog from last version | ||
Example | ||
'scalingo changelog'`, | ||
Action: func(c *cli.Context) { | ||
err := update.ShowLastChangelog() | ||
if err != nil { | ||
errorQuit(err) | ||
} | ||
}, | ||
BashComplete: func(c *cli.Context) { | ||
autocomplete.CmdFlagsAutoComplete(c, "changelog") | ||
}, | ||
} | ||
) |
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 |
---|---|---|
|
@@ -263,6 +263,9 @@ var ( | |
// Version | ||
UpdateCommand, | ||
|
||
// Changelog | ||
changelogCommand, | ||
|
||
// Help | ||
HelpCommand, | ||
} | ||
|
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,43 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/google/go-github/v47/github" | ||
"gopkg.in/errgo.v1" | ||
|
||
"github.com/Scalingo/go-scalingo/v4/debug" | ||
) | ||
|
||
type Client interface { | ||
GetLatestRelease(ctx context.Context) (*github.RepositoryRelease, error) | ||
} | ||
|
||
type client struct { | ||
githubRepositoriesService *github.RepositoriesService | ||
} | ||
|
||
func NewClient() Client { | ||
return client{ | ||
githubRepositoriesService: github.NewClient(&http.Client{ | ||
Timeout: 5 * time.Second, | ||
}).Repositories, | ||
} | ||
} | ||
|
||
func (c client) GetLatestRelease(ctx context.Context) (*github.RepositoryRelease, error) { | ||
latestRelease, githubResponse, err := c.githubRepositoriesService.GetLatestRelease(ctx, "Scalingo", "cli") | ||
if githubResponse != nil && githubResponse.Body != nil { | ||
defer githubResponse.Body.Close() | ||
} | ||
|
||
debug.Printf("GitHub response: %#v\n", githubResponse) | ||
|
||
if err != nil { | ||
return nil, errgo.Notef(err, "fail to get the latest release of the Scalingo/cli repository") | ||
} | ||
|
||
return latestRelease, 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,29 @@ | ||
package update | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"gopkg.in/errgo.v1" | ||
|
||
"github.com/Scalingo/cli/io" | ||
"github.com/Scalingo/cli/services/github" | ||
) | ||
|
||
func ShowLastChangelog() error { | ||
cliLastRelease, err := github.NewClient().GetLatestRelease(context.Background()) | ||
if err != nil { | ||
return errgo.Notef(err, "fail to get last CLI release") | ||
} | ||
|
||
if cliLastRelease.GetBody() == "" { | ||
io.Warning("GitHub last release is empty") | ||
return nil | ||
} | ||
|
||
fmt.Printf("Changelog of the version %v\n\n", cliLastRelease.GetTagName()) | ||
fmt.Printf("%v\n\n", strings.ReplaceAll(cliLastRelease.GetBody(), "\\r\\n", "\r\n")) | ||
|
||
return 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
Oops, something went wrong.