-
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
2 changed files
with
51 additions
and
10 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 |
---|---|---|
@@ -1,31 +1,68 @@ | ||
package internal | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ktrysmt/go-bitbucket" | ||
"github.com/logrusorgru/aurora" | ||
) | ||
|
||
func PrList(username string, password string, repoOrga string, repoSlug string) { | ||
func PrList(username string, password string, repoOrga string, repoSlug string) error { | ||
|
||
client := bitbucket.NewBasicAuth(username, password) | ||
|
||
opt := &bitbucket.PullRequestsOptions{ | ||
Owner: repoOrga, | ||
RepoSlug: repoSlug, | ||
} | ||
|
||
response, _ := client.Repositories.PullRequests.Gets(opt) | ||
mapResponse := response.(map[string]interface{}) | ||
values := mapResponse["values"].([]interface{}) | ||
response, err := client.Repositories.PullRequests.Gets(opt) | ||
if err != nil { | ||
return err | ||
} | ||
mapResponse, ok := response.(map[string]interface{}) | ||
if !ok { | ||
return errors.New("type assertion failed") | ||
} | ||
values, ok := mapResponse["values"].([]interface{}) | ||
if !ok { | ||
return errors.New("type assertion failed") | ||
} | ||
|
||
fmt.Println() | ||
fmt.Printf("%s Showing %d of %d open pull requests in %s/%s\n", aurora.Blue(" :: "), len(values), int(mapResponse["size"].(float64)), repoOrga, repoSlug) | ||
fmt.Println() | ||
for _, pr := range values { | ||
mapPr := pr.(map[string]interface{}) | ||
sourceName := mapPr["source"].(map[string]interface{})["branch"].(map[string]interface{})["name"] | ||
destName := mapPr["destination"].(map[string]interface{})["branch"].(map[string]interface{})["name"] | ||
mapPr, ok := pr.(map[string]interface{}) | ||
if !ok { | ||
return errors.New("type assertion failed") | ||
} | ||
source, ok := mapPr["source"].(map[string]interface{}) | ||
if !ok { | ||
return errors.New("type assertion failed") | ||
} | ||
|
||
sourceBranch, ok := source["branch"].(map[string]interface{}) | ||
if !ok { | ||
return errors.New("type assertion failed") | ||
} | ||
|
||
sourceName := sourceBranch["name"] | ||
|
||
dest, ok := mapPr["destination"].(map[string]interface{}) | ||
if !ok { | ||
return errors.New("type assertion failed") | ||
} | ||
|
||
destBranch, ok := dest["branch"].(map[string]interface{}) | ||
if !ok { | ||
return errors.New("type assertion failed") | ||
} | ||
|
||
destName := destBranch["name"] | ||
fmt.Printf("#%03d %s %s -> %s\n", aurora.Green(int(mapPr["id"].(float64))), mapPr["title"].(string), sourceName, destName) | ||
} | ||
|
||
return nil | ||
} |