-
Notifications
You must be signed in to change notification settings - Fork 3
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
4 changed files
with
140 additions
and
0 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,19 @@ | ||
package repo | ||
|
||
import ( | ||
"github.com/craftamap/bb/cmd/commands/repo/view" | ||
"github.com/craftamap/bb/cmd/options" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func Add(rootCmd *cobra.Command, globalOpts *options.GlobalOptions) { | ||
repoCommand := cobra.Command{ | ||
Use: "repo", | ||
Long: "Work with repositories", | ||
Short: "Manage your repository", | ||
} | ||
|
||
view.Add(&repoCommand, globalOpts) | ||
|
||
rootCmd.AddCommand(&repoCommand) | ||
} |
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,78 @@ | ||
package view | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/charmbracelet/glamour" | ||
"github.com/craftamap/bb/cmd/options" | ||
"github.com/craftamap/bb/internal" | ||
"github.com/logrusorgru/aurora" | ||
"github.com/pkg/browser" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
Web bool | ||
) | ||
|
||
func Add(repoCmd *cobra.Command, globalOpts *options.GlobalOptions) { | ||
viewCmd := &cobra.Command{ | ||
Use: "view", | ||
Short: "View a pull request", | ||
Long: "Display the title, body, and other information about a pull request.", | ||
Annotations: map[string]string{ | ||
"RequiresClient": "true", | ||
"RequiresRepository": "true", | ||
}, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
c := globalOpts.Client | ||
bbrepo := globalOpts.BitbucketRepo | ||
|
||
repo, err := c.RepositoryGet(bbrepo.RepoOrga, bbrepo.RepoSlug) | ||
if err != nil { | ||
fmt.Printf("%s%s%s\n", aurora.Red(":: "), aurora.Bold("An error occured: "), err) | ||
return | ||
} | ||
if Web { | ||
err := browser.OpenURL(repo.Links["html"].(map[string]interface{})["href"].(string)) | ||
if err != nil { | ||
fmt.Printf("%s%s%s\n", aurora.Red(":: "), aurora.Bold("An error occured: "), err) | ||
return | ||
} | ||
return | ||
} | ||
|
||
readme, err := c.GetReadmeContent(bbrepo.RepoOrga, bbrepo.RepoSlug, repo.MainBranch.Name) | ||
if err != nil { | ||
fmt.Printf("%s%s%s\n", aurora.Red(":: "), aurora.Bold("An error occured: "), err) | ||
return | ||
} | ||
|
||
PrintSummary(repo, readme) | ||
}, | ||
} | ||
|
||
viewCmd.Flags().BoolVar(&Web, "web", false, "view this repository in your web browser") | ||
repoCmd.AddCommand(viewCmd) | ||
|
||
} | ||
|
||
func PrintSummary(repo *internal.Repository, readme string) { | ||
fmt.Println(aurora.Bold(repo.FullName)) | ||
if repo.Description != "" { | ||
fmt.Println(aurora.Bold("Description:"), repo.Description) | ||
} | ||
fmt.Println(aurora.Bold("Project:"), repo.Project.Name, fmt.Sprintf("(%s)", repo.Project.Key)) | ||
if readme != "" { | ||
out, err := glamour.Render(readme, "dark") | ||
if err != nil { | ||
fmt.Printf("%s%s%s\n", aurora.Red(":: "), aurora.Bold("An error occured: "), err) | ||
return | ||
} | ||
fmt.Println(out) | ||
} | ||
footer := aurora.Index(242, fmt.Sprintf("View this repository on Bitbucket.org: %s", repo.Links["html"].(map[string]interface{})["href"].(string))).String() | ||
fmt.Println(footer) | ||
|
||
} |
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