Skip to content

Commit 87e4b54

Browse files
authored
Privatebb (gabrie30#186)
1 parent cc87329 commit 87e4b54

File tree

5 files changed

+74
-34
lines changed

5 files changed

+74
-34
lines changed

.github/workflows/go.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,41 @@ jobs:
99
matrix:
1010
os: [macos-latest, ubuntu-latest]
1111
steps:
12-
- name: Set up Go 1.16
12+
- name: Set up Go 1.17
1313
uses: actions/setup-go@v1
1414
with:
15-
go-version: 1.16
15+
go-version: 1.17
1616
id: go
1717
- name: Check out code into the Go module directory
1818
uses: actions/checkout@v1
1919
- name: Test
2020
run: go test -v ./...
21-
- name: Get dependencies
22-
run: |
23-
go get -v -t -d ./...
2421
- name: Build
2522
run: go build -v -o ghorg .
2623
- name: Run GitHub Integration Tests
2724
run: scripts/github_integration_tests.sh
2825
env:
2926
GITHUB_TOKEN: ${{ secrets.GHORG_GITHUB_TOKEN }}
27+
- name: Run Bitbucket Integration Tests
28+
run: scripts/bitbucket_integration_tests.sh
29+
env:
30+
BITBUCKET_TOKEN: ${{ secrets.GHORG_BITBUCKET_APP_PASSWORD }}
31+
BITBUCKET_USERNAME: ${{ secrets.GHORG_BITBUCKET_USERNAME }}
3032
build_and_test_windows:
3133
name: Build and Test Windows
3234
runs-on: windows-latest
3335
steps:
3436
- name: Set up Go 1.16
3537
uses: actions/setup-go@v1
3638
with:
37-
go-version: 1.16
39+
go-version: 1.17
3840
id: go
3941
- name: Check out code into the Go module directory
4042
uses: actions/checkout@v1
4143
- name: Set configuration file
4244
run: |
4345
mkdir C:\Users\runneradmin\.config\ghorg
4446
copy sample-conf.yaml C:\Users\runneradmin\.config\ghorg\conf.yaml
45-
- name: Get dependencies
46-
run: |
47-
go get -v -t -d ./...
4847
- name: Build
4948
run: env GOOS=windows GOARCH=386 go build -v -o ghorg.exe .
5049
- name: Test
@@ -53,3 +52,8 @@ jobs:
5352
run: scripts/windows_github_integration_tests.bat
5453
env:
5554
GITHUB_TOKEN: ${{ secrets.GHORG_GITHUB_TOKEN }}
55+
- name: Run Bitbucket Integration Tests
56+
run: scripts/bitbucket_integration_tests.sh
57+
env:
58+
BITBUCKET_TOKEN: ${{ secrets.GHORG_BITBUCKET_APP_PASSWORD }}
59+
BITBUCKET_USERNAME: ${{ secrets.GHORG_BITBUCKET_USERNAME }}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
6+
7+
## [1.7.9] - unreleased
8+
### Added
9+
- Bitbucket base url support
10+
### Changed
11+
### Deprecated
12+
### Removed
13+
### Fixed
14+
### Security
515
## [1.7.8] - 2/14/22
616
### Added
717
### Changed

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ var versionCmd = &cobra.Command{
1111
Short: "Print the version number of Ghorg",
1212
Long: `All software has versions. This is Ghorg's`,
1313
Run: func(cmd *cobra.Command, args []string) {
14-
fmt.Println("v1.7.8")
14+
fmt.Println("v1.7.9")
1515
},
1616
}

scm/bitbucket.go

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package scm
22

33
import (
4+
"net/url"
5+
46
"os"
57

68
"github.com/gabrie30/ghorg/colorlog"
@@ -26,22 +28,22 @@ func (_ Bitbucket) GetType() string {
2628

2729
// GetOrgRepos gets org repos
2830
func (c Bitbucket) GetOrgRepos(targetOrg string) ([]Repo, error) {
29-
resp, err := c.Teams.Repositories(targetOrg)
31+
resp, err := c.Repositories.ListForAccount(&bitbucket.RepositoriesOptions{Owner: targetOrg})
3032
if err != nil {
3133
return []Repo{}, err
3234
}
3335

34-
return c.filter(resp)
36+
return c.filter(resp.Items)
3537
}
3638

3739
// GetUserRepos gets user repos from bitbucket
3840
func (c Bitbucket) GetUserRepos(targetUser string) ([]Repo, error) {
39-
resp, err := c.Users.Repositories(targetUser)
41+
resp, err := c.Repositories.ListForAccount(&bitbucket.RepositoriesOptions{Owner: targetUser})
4042
if err != nil {
4143
return []Repo{}, err
4244
}
4345

44-
return c.filter(resp)
46+
return c.filter(resp.Items)
4547
}
4648

4749
// NewClient create new bitbucket scm client
@@ -56,16 +58,20 @@ func (_ Bitbucket) NewClient() (Client, error) {
5658
} else {
5759
c = bitbucket.NewBasicAuth(user, password)
5860
}
61+
62+
if os.Getenv("GHORG_SCM_BASE_URL") != "" {
63+
u, _ := url.Parse(os.Getenv("GHORG_SCM_BASE_URL"))
64+
c.SetApiBaseURL(*u)
65+
}
66+
5967
return Bitbucket{c}, nil
6068
}
6169

62-
func (_ Bitbucket) filter(resp interface{}) (repoData []Repo, err error) {
70+
func (_ Bitbucket) filter(resp []bitbucket.Repository) (repoData []Repo, err error) {
6371
cloneData := []Repo{}
64-
values := resp.(map[string]interface{})["values"].([]interface{})
6572

66-
for _, a := range values {
67-
clone := a.(map[string]interface{})
68-
links := clone["links"].(map[string]interface{})["clone"].([]interface{})
73+
for _, a := range resp {
74+
links := a.Links["clone"].([]interface{})
6975
for _, l := range links {
7076
link := l.(map[string]interface{})["href"]
7177
linkType := l.(map[string]interface{})["name"]
@@ -75,23 +81,10 @@ func (_ Bitbucket) filter(resp interface{}) (repoData []Repo, err error) {
7581
}
7682

7783
r := Repo{}
78-
r.Name = clone["name"].(string)
79-
80-
if os.Getenv("GHORG_BRANCH") == "" {
81-
var defaultBranch string
82-
if clone["mainbranch"] == nil {
83-
defaultBranch = "master"
84-
} else {
85-
defaultBranch = clone["mainbranch"].(map[string]interface{})["name"].(string)
86-
}
87-
88-
r.CloneBranch = defaultBranch
89-
} else {
90-
r.CloneBranch = os.Getenv("GHORG_BRANCH")
91-
}
84+
r.Name = a.Name
9285

9386
if os.Getenv("GHORG_BRANCH") == "" {
94-
r.CloneBranch = "master"
87+
r.CloneBranch = a.Mainbranch.Name
9588
} else {
9689
r.CloneBranch = os.Getenv("GHORG_BRANCH")
9790
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Running BitBucket Integration Tests"
6+
7+
cp ./ghorg /usr/local/bin
8+
9+
BITBUCKET_WORKSPACE=ghorg
10+
11+
ghorg version
12+
13+
# clone an org with no config file
14+
ghorg clone $BITBUCKET_WORKSPACE --token="${BITBUCKET_TOKEN}" --bitbucket-username="${BITBUCKET_USERNAME}" --scm=bitbucket --base-url="https://api.bitbucket.org/2.0"
15+
16+
if [ -e "${HOME}"/ghorg/$BITBUCKET_WORKSPACE ]
17+
then
18+
echo "Pass: bitbucket org clone using no configuration file"
19+
else
20+
echo "Fail: bitbucket org clone using no configuration file"
21+
exit 1
22+
fi
23+
24+
# clone an org with no config file to a specific path
25+
ghorg clone $BITBUCKET_WORKSPACE --token="${BITBUCKET_TOKEN}" --bitbucket-username="${BITBUCKET_USERNAME}" --path=/tmp --output-dir=testing_output_dir --scm=bitbucket --base-url="https://api.bitbucket.org/2.0"
26+
27+
if [ -e /tmp/testing_output_dir ]
28+
then
29+
echo "Pass: bitbucket org clone, commandline flags take overwrite conf.yaml"
30+
else
31+
echo "Fail: bitbucket org clone, commandline flags take overwrite conf.yaml"
32+
exit 1
33+
fi

0 commit comments

Comments
 (0)