-
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.
Merge pull request #1 from craftamap/dev
Merge current draft into master
- Loading branch information
Showing
33 changed files
with
2,430 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
name: build | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
go-version: [~1.13, ^1] | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
GO111MODULE: "on" | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Download Go modules | ||
run: go mod download | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test ./... |
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,22 @@ | ||
name: lint | ||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. | ||
version: v1.30 | ||
# Optional: golangci-lint command line arguments. | ||
args: --issues-exit-code=0 | ||
# Optional: working directory, useful for monorepos | ||
# working-directory: somedir | ||
# Optional: show only new issues if it's a pull request. The default value is `false`. | ||
only-new-issues: true |
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,18 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ rootCmd.PersistentFlags | ||
|
||
bb | ||
dist/ |
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 @@ | ||
# This is an example goreleaser.yaml file with some sane defaults. | ||
# Make sure to check the documentation at http://goreleaser.com | ||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod download | ||
# you may remove this if you don't need go generate | ||
- go generate ./... | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
archives: | ||
- replacements: | ||
darwin: Darwin | ||
linux: Linux | ||
windows: Windows | ||
386: i386 | ||
amd64: x86_64 | ||
|
||
nfpms: | ||
- | ||
vendor: craftamap | ||
maintainer: "Fabian Siegel <[email protected]>" | ||
description: "inoffical Bitbucket.org command line tool" | ||
license: MIT | ||
formats: | ||
- deb | ||
- rpm | ||
bindir: /usr/bin | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ .Tag }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' |
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 |
---|---|---|
@@ -1 +1,69 @@ | ||
# bb | ||
# bb | ||
|
||
![bb logo](.github/bb-logo.png) | ||
|
||
--- | ||
|
||
`bb` is an inoffical bitbucket.org command line tool deeply inspired by the | ||
official [GitHub CLI](https://github.com/cli/cli/). It brings pull requests, | ||
downloads, and other bitbucket concepts to you the terminal. | ||
|
||
![screenshot showing ](.github/screenshot_create_pr.png) | ||
|
||
# Installation | ||
|
||
Currently, the only option to install bb is by compiling it from source. | ||
|
||
Make sure you have a working Go environment. Follow the | ||
[Go install instructions](https://golang.org/doc/install). | ||
|
||
## Using `go get` | ||
|
||
```bash | ||
go get github.com/craftamap/bb | ||
``` | ||
|
||
## Building from source | ||
|
||
```bash | ||
git clone https://github.com/craftamap/bb.git | ||
go build | ||
``` | ||
|
||
# Set-Up | ||
|
||
You need to authenticate with your credentials first. You should generate a | ||
[app password](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/) | ||
for that. Make sure to grant read and write access to the features you want to use. | ||
(**Recommended**:Repositories: Read/Write, Pull Requests: Read/Write, Pipelines: Read/Write) | ||
|
||
Run the following command to enter your username and password: | ||
|
||
```bash | ||
bb auth login | ||
``` | ||
|
||
Your credentials will be stored to `~/.config/bb/configuration.toml`. | ||
|
||
# Usage | ||
|
||
To see all available commands, use `bb` without any subcommand. | ||
|
||
## Pull Requests | ||
|
||
You can use `bb pr` to list, view and merge existing pull requests and see how | ||
their pipelines run. You can also use `bb pr create` to create new ones. | ||
|
||
## Downloads | ||
|
||
Manage downloads by listing, downloading or uploading them. | ||
|
||
# Development | ||
## Used Libraries | ||
|
||
We use two multiple different bitbucket libaries: | ||
|
||
- https://github.com/ktrysmt/go-bitbucket | ||
- https://github.com/jsdidierlaurent/go-bitbucket | ||
|
||
Thanks to both of these! |
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,84 @@ | ||
package api | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/craftamap/bb/cmd/options" | ||
"github.com/logrusorgru/aurora" | ||
"github.com/spf13/cobra" | ||
"github.com/tidwall/pretty" | ||
) | ||
|
||
var ( | ||
Method string | ||
Headers []string | ||
) | ||
|
||
func Add(rootCmd *cobra.Command, globalOpts *options.GlobalOptions) { | ||
apiCmd := &cobra.Command{ | ||
Use: "api <url> [<body>]", | ||
Short: "Make an authenticated api.bitbucket.org request to the rest 2.0 api", | ||
Long: "Make an authenticated api.bitbucket.org request to the rest 2.0 api", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(Headers) | ||
|
||
client := http.Client{} | ||
|
||
url := "" | ||
if len(args) > 0 { | ||
url = args[0] | ||
} | ||
url = "https://api.bitbucket.org/2.0/" + url | ||
|
||
reqBody := "" | ||
if len(args) == 2 { | ||
reqBody = args[1] | ||
} | ||
|
||
req, err := http.NewRequest(Method, url, bytes.NewBufferString(reqBody)) | ||
if err != nil { | ||
fmt.Printf("%s%s%s\n", aurora.Red(":: "), aurora.Bold("An error occured: "), err) | ||
return | ||
} | ||
req.SetBasicAuth(globalOpts.Username, globalOpts.Password) | ||
|
||
for _, header := range Headers { | ||
splitted := strings.SplitN(header, "=", 2) | ||
if len(splitted) == 2 { | ||
req.Header.Add(splitted[0], splitted[1]) | ||
} | ||
} | ||
|
||
response, err := client.Do(req) | ||
if err != nil { | ||
fmt.Printf("%s%s%s\n", aurora.Red(":: "), aurora.Bold("An error occured: "), err) | ||
return | ||
} | ||
|
||
defer response.Body.Close() | ||
|
||
resBody, err := ioutil.ReadAll(response.Body) | ||
if err != nil { | ||
fmt.Printf("%s%s%s\n", aurora.Red(":: "), aurora.Bold("An error occured: "), err) | ||
return | ||
} | ||
if response.StatusCode <= 200 || response.StatusCode > 299 { | ||
fmt.Printf("%s%s%d\n", aurora.Yellow(":: "), aurora.Bold("Status Code: "), response.StatusCode) | ||
} | ||
|
||
if strings.Contains(response.Header["Content-Type"][0], "json") { | ||
fmt.Println(string(pretty.Color(pretty.Pretty(resBody), nil))) | ||
} else { | ||
fmt.Println(string(resBody)) | ||
} | ||
}, | ||
} | ||
|
||
apiCmd.Flags().StringVarP(&Method, "method", "X", "GET", "The HTTP method for the request") | ||
apiCmd.Flags().StringArrayVarP(&Headers, "header", "H", []string{}, "Add an additional HTTP request header") | ||
rootCmd.AddCommand(apiCmd) | ||
} |
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,16 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/craftamap/bb/cmd/commands/auth/login" | ||
"github.com/craftamap/bb/cmd/options" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func Add(rootCmd *cobra.Command, globalOpts *options.GlobalOptions) { | ||
authCmd := &cobra.Command{ | ||
Use: "auth", | ||
Short: "Manage bb authentification state", | ||
} | ||
login.Add(authCmd, globalOpts) | ||
rootCmd.AddCommand(authCmd) | ||
} |
Oops, something went wrong.