Skip to content

Commit 71cc58f

Browse files
committed
Add support for space names, useful for team organisations.
#2
1 parent 1cf8f06 commit 71cc58f

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ inputs:
1212
repository:
1313
required: true
1414
default: ${{ github.event.repository.name }}
15+
spacename:
16+
required: true
17+
default: ${{ github.actor }}
1518

1619
runs:
1720
using: "composite"
1821
steps:
19-
- run: ${{ github.action_path }}/fillbucket.sh "${{ inputs.username }}" "${{ inputs.password }}" "${{ inputs.repository }}"
22+
- run: ${{ github.action_path }}/fillbucket.sh "${{ inputs.username }}" "${{ inputs.password }}" "${{ inputs.repository }}" "${{ inputs.spacename }}"
2023
shell: bash

fillbucket.sh

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ trap "echo 'Missing parameter'; exit 1" INT TERM EXIT
88
username="$1"
99
password="$2"
1010
reponame="$3"
11-
#remote="$4"
1211
trap - INT TERM EXIT
1312

13+
spacename="$username"
14+
if [ $# -ge 4 ]; then
15+
spacename="$4"
16+
fi
17+
1418

1519
CURL_OPTS=(-u "$username:$password" --silent)
1620

@@ -24,21 +28,11 @@ curl --fail "${CURL_OPTS[@]}" "https://api.bitbucket.org/2.0/user" > /dev/null |
2428

2529
reponame=$(echo $reponame | tr '[:upper:]' '[:lower:]')
2630

27-
echo "Checking if BitBucket repository \"$username/$reponame\" exists..."
28-
curl "${CURL_OPTS[@]}" "https://api.bitbucket.org/2.0/repositories/$username/$reponame" | grep "error" > /dev/null && (
29-
echo "BitBucket repository \"$username/$reponame\" does NOT exist, creating it..."
30-
curl -X POST --fail "${CURL_OPTS[@]}" "https://api.bitbucket.org/2.0/repositories/$username/$reponame" -H "Content-Type: application/json" -d '{"scm": "git", "is_private": "true"}' > /dev/null
31+
echo "Checking if BitBucket repository \"$spacename/$reponame\" exists..."
32+
curl "${CURL_OPTS[@]}" "https://api.bitbucket.org/2.0/repositories/$spacename/$reponame" | grep "error" > /dev/null && (
33+
echo "BitBucket repository \"$spacename/$reponame\" does NOT exist, creating it..."
34+
curl -X POST --fail "${CURL_OPTS[@]}" "https://api.bitbucket.org/2.0/repositories/$spacename/$reponame" -H "Content-Type: application/json" -d '{"scm": "git", "is_private": "true"}' > /dev/null
3135
)
3236

33-
34-
#remote=$(echo $remote | tr '[:upper:]' '[:lower:]')
35-
#
36-
#echo "Checking for remote \"$remote\"..."
37-
#git remote get-url "$remote" &> /dev/null || (
38-
# echo "Repository has no remote \"$remote\", creating it..."
39-
# git remote add "$remote" https://[email protected]/$username/$reponame.git
40-
#)
41-
42-
4337
echo "Pushing to remote..."
44-
git push https://"$username:$password"@bitbucket.org/$username/$reponame.git --all --force
38+
git push https://"$username:$password"@bitbucket.org/$spacename/$reponame.git --all --force

index.en.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Username to use on Bitbucket for 1) authentication and as 2) workspace name. Def
2323
### `repository`
2424
Name of the repository on Bitbucket. If it does not exist, it is created automatically. Default: GitHub repository name.
2525

26+
### `spacename`
27+
Name of the space in which the repository should be contained on Bitbucket. Default: GitHub user name.
28+
2629
## Outputs
2730
None
2831

@@ -34,7 +37,20 @@ None
3437
with:
3538
fetch-depth: 0 # <-- clone with complete history
3639
- name: Push
37-
uses: heussd/mirror-to-bitbucket-github-action@main
38-
id: mirror-to-bitbucket
40+
uses: heussd/mirror-to-bitbucket-github-action@v2
41+
with:
42+
password: ${{ secrets.BITBUCKET_PASSWORD }}
43+
44+
## Example with all parameters
45+
46+
- name: Checkout
47+
uses: actions/checkout@v2
48+
with:
49+
fetch-depth: 0 # <-- clone with complete history
50+
- name: Push
51+
uses: heussd/mirror-to-bitbucket-github-action@v2
3952
with:
53+
username: mycrazybbusername
54+
spacename: teamspace
55+
repository: bestrepo
4056
password: ${{ secrets.BITBUCKET_PASSWORD }}

0 commit comments

Comments
 (0)