Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Bitbucket commands (#230)
Browse files Browse the repository at this point in the history
* bitbucket create repo

Signed-off-by: JoaoDanielRufino <joaodaniel0405@gmail.com>

* fixing pre-commit

Signed-off-by: JoaoDanielRufino <joaodaniel0405@gmail.com>

* bitbucket delete repo

Signed-off-by: JoaoDanielRufino <joaodaniel0405@gmail.com>

* removing error validation

Signed-off-by: JoaoDanielRufino <joaodaniel0405@gmail.com>

* add formula to unix folder

Signed-off-by: JoaoDanielRufino <joaodaniel0405@gmail.com>

* windows support create repo

Signed-off-by: JoaoDanielRufino <joaodaniel0405@gmail.com>

* windows support delete repo

Signed-off-by: JoaoDanielRufino <joaodaniel0405@gmail.com>

* removing csharp files

Signed-off-by: JoaoDanielRufino <joaodaniel0405@gmail.com>
  • Loading branch information
JoaoDanielRufino authored Sep 21, 2020
1 parent 64795c1 commit b869c6f
Show file tree
Hide file tree
Showing 29 changed files with 391 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bitbucket/create/help.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"long": "Manage Bitbucket create objects",
"short": "Manage Bitbucket create objects"
}
15 changes: 15 additions & 0 deletions bitbucket/create/repo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM cimg/base:stable-20.04

USER root

RUN curl -fsSL https://commons-repo.ritchiecli.io/install.sh | bash

RUN mkdir /rit
COPY . /rit
RUN sed -i 's/\r//g' /rit/set_umask.sh
RUN sed -i 's/\r//g' /rit/run.sh
RUN chmod +x /rit/set_umask.sh

WORKDIR /app
ENTRYPOINT ["/rit/set_umask.sh"]
CMD ["/rit/run.sh"]
14 changes: 14 additions & 0 deletions bitbucket/create/repo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SH
BINARY_NAME=run.sh
BIN_FOLDER=bin

build: bash-build docker

bash-build:
mkdir -p $(BIN_FOLDER)
cp -r src/* $(BIN_FOLDER)
mv $(BIN_FOLDER)/main.sh $(BIN_FOLDER)/$(BINARY_NAME)
chmod +x $(BIN_FOLDER)/$(BINARY_NAME)

docker:
cp Dockerfile set_umask.sh $(BIN_FOLDER)
25 changes: 25 additions & 0 deletions bitbucket/create/repo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Ritchie Formula

## command

```bash
rit bitbucket create repo
```

## Requirements

- git installed

- set bitbucket username and token credentials using

```bash
rit set credential
```

## How to generate personal access token(app password)

To generate a personal access token click [here](https://bitbucket.org/account/settings/app-passwords/)

## How it works

![gif](doc/bitbucket-create-repo.gif)
14 changes: 14 additions & 0 deletions bitbucket/create/repo/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@echo off
SETLOCAL
SET BINARY_NAME=run.bat
SET BIN_FOLDER=bin
SET ENTRY_POINT=main.bat

:build
mkdir %BIN_FOLDER%
xcopy src %BIN_FOLDER% /e/h/i/c
cd %BIN_FOLDER%
rename %ENTRY_POINT% %BINARY_NAME%
exit /b 0

ENDLOCAL
39 changes: 39 additions & 0 deletions bitbucket/create/repo/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"dockerImageBuilder": "cimg/base:stable-20.04",
"inputs": [
{
"label": "Project name: ",
"name": "project_name",
"type": "text"
},
{
"label": "Project description: ",
"name": "project_description",
"type": "text"
},
{
"default": "false",
"items": [
"false",
"true"
],
"label": "Create a private repository?: ",
"name": "private",
"type": "bool"
},
{
"default": " ",
"label": "Workspace path (ex: /home/user/my-project)\n(Note: An empty value create a Bitbucket repo with just a README file): ",
"name": "workspace_path",
"type": "text"
},
{
"name": "username",
"type": "CREDENTIAL_BITBUCKET_USERNAME"
},
{
"name": "token",
"type": "CREDENTIAL_BITBUCKET_TOKEN"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions bitbucket/create/repo/help.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"long": "bitbucket command to create a repo",
"short": "bitbucket command to create a repo"
}
18 changes: 18 additions & 0 deletions bitbucket/create/repo/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"execution": [
"local",
"docker"
],
"os": {
"deps": [],
"support": [
"mac",
"linux"
]
},
"tags": [
"bitbucket",
"create",
"repo"
]
}
3 changes: 3 additions & 0 deletions bitbucket/create/repo/set_umask.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
umask 0011
$1
3 changes: 3 additions & 0 deletions bitbucket/create/repo/src/main.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

call windows\formula\formula.bat runFormula
6 changes: 6 additions & 0 deletions bitbucket/create/repo/src/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# shellcheck source=/dev/null
. "$(dirname "$0")"/unix/formula/formula.sh --source-only

runFormula
59 changes: 59 additions & 0 deletions bitbucket/create/repo/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# shellcheck disable=SC2086

checkCommand() {
if ! command -v "$1" >/dev/null; then
echo "Error: $1 command required"
exit 1
fi
}

removeSpaces() {
echo "${1}" | xargs | tr " " -
}

checkSpace() {
tmp="$1"

if [[ "$1" = *" "* ]]; then
echo >&2 "Removing spaces from Project name..."
tmp=$(removeSpaces "$1")
echo >&2 "Project name without spaces: $tmp"
fi

echo "$tmp"
}

checkProjectName() {
if [[ ! "$1" =~ ^[a-zA-Z0-9-]+$ ]]; then
echo "Project name cannot contain special characters"
exit 1
fi
}

runFormula() {
checkCommand git

PROJECT_NAME=$(checkSpace "$PROJECT_NAME")

checkProjectName "$PROJECT_NAME"

if [[ "$WORKSPACE_PATH" != " " ]]; then
cd "$WORKSPACE_PATH" || exit 1
else
mkdir "$PROJECT_NAME"
cd "$PROJECT_NAME" || exit 1
echo "$PROJECT_DESCRIPTION" >> README.md
fi

git init

git add .
git commit -m "Initial Commit"
curl -X POST -u "$USERNAME":"$TOKEN" -H 'Content-Type: application/json' https://api.bitbucket.org/2.0/repositories/"$USERNAME"/"$PROJECT_NAME" -d '{"scm": "git", "is_private": '$PRIVATE'}' > /dev/null
git remote add origin https://"$USERNAME":"$TOKEN"@bitbucket.org/"$USERNAME"/"$PROJECT_NAME".git

git push origin master

echo "✅ Repository successfully initialized with Git and added on Bitbucket!!"
}
28 changes: 28 additions & 0 deletions bitbucket/create/repo/src/windows/formula/formula.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@echo off
SETLOCAL

call:%~1
goto exit

:runFormula
if "%WORKSPACE_PATH%" == " " (
mkdir %CURRENT_PWD%\%PROJECT_NAME%
cd %CURRENT_PWD%\%PROJECT_NAME%
echo %PROJECT_DESCRIPTION% >> README.md
) else (
cd %WORKSPACE_PATH%
)

git init
git add .
git commit -m "Initial Commit"
curl -X POST -u %USERNAME%:%TOKEN% -H "Content-Type: application/json" https://api.bitbucket.org/2.0/repositories/%USERNAME%/%PROJECT_NAME% -d "{\"scm\": \"git\", \"is_private\": %PRIVATE%}" > nul
git remote add origin https://%USERNAME%:%TOKEN%@bitbucket.org/%USERNAME%/%PROJECT_NAME%.git
git push origin master

echo Repository successfully initialized with git and added on Bitbucket!!
goto exit

:exit
ENDLOCAL
exit /b
4 changes: 4 additions & 0 deletions bitbucket/delete/help.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"long": "Manage bitbucket delete objects",
"short": "Manage bitbucket delete objects"
}
15 changes: 15 additions & 0 deletions bitbucket/delete/repo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM cimg/base:stable-20.04

USER root

RUN curl -fsSL https://commons-repo.ritchiecli.io/install.sh | bash

RUN mkdir /rit
COPY . /rit
RUN sed -i 's/\r//g' /rit/set_umask.sh
RUN sed -i 's/\r//g' /rit/run.sh
RUN chmod +x /rit/set_umask.sh

WORKDIR /app
ENTRYPOINT ["/rit/set_umask.sh"]
CMD ["/rit/run.sh"]
14 changes: 14 additions & 0 deletions bitbucket/delete/repo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SH
BINARY_NAME=run.sh
BIN_FOLDER=bin

build: bash-build docker

bash-build:
mkdir -p $(BIN_FOLDER)
cp -r src/* $(BIN_FOLDER)
mv $(BIN_FOLDER)/main.sh $(BIN_FOLDER)/$(BINARY_NAME)
chmod +x $(BIN_FOLDER)/$(BINARY_NAME)

docker:
cp Dockerfile set_umask.sh $(BIN_FOLDER)
25 changes: 25 additions & 0 deletions bitbucket/delete/repo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Ritchie Formula

## command

```bash
rit bitbucket delete repo
```

## Requirements

- git installed

- set bitbucket username and token credentials using

```bash
rit set credential
```

## How to generate personal access token(app password)

To generate a personal access token click [here](https://bitbucket.org/account/settings/app-passwords/)

## How it works

![gif](doc/bitbucket-delete-repo.gif)
14 changes: 14 additions & 0 deletions bitbucket/delete/repo/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@echo off
SETLOCAL
SET BINARY_NAME=run.bat
SET BIN_FOLDER=bin
SET ENTRY_POINT=main.bat

:build
mkdir %BIN_FOLDER%
xcopy src %BIN_FOLDER% /e/h/i/c
cd %BIN_FOLDER%
rename %ENTRY_POINT% %BINARY_NAME%
exit /b 0

ENDLOCAL
18 changes: 18 additions & 0 deletions bitbucket/delete/repo/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"dockerImageBuilder": "cimg/base:stable-20.04",
"inputs": [
{
"label": "Bitbucket project name to delete: ",
"name": "project_name",
"type": "text"
},
{
"name": "username",
"type": "CREDENTIAL_BITBUCKET_USERNAME"
},
{
"name": "token",
"type": "CREDENTIAL_BITBUCKET_TOKEN"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions bitbucket/delete/repo/help.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"long": "Command to delete a single bitbucket repository",
"short": "Command to delete a single bitbucket repository"
}
17 changes: 17 additions & 0 deletions bitbucket/delete/repo/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"execution": [
"local"
],
"os": {
"deps": [],
"support": [
"mac",
"linux"
]
},
"tags": [
"bitbucket",
"delete",
"repo"
]
}
3 changes: 3 additions & 0 deletions bitbucket/delete/repo/set_umask.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
umask 0011
$1
3 changes: 3 additions & 0 deletions bitbucket/delete/repo/src/main.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

call windows\formula\formula.bat runFormula
6 changes: 6 additions & 0 deletions bitbucket/delete/repo/src/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# shellcheck source=/dev/null
. "$(dirname "$0")"/formula/formula.sh --source-only

runFormula
17 changes: 17 additions & 0 deletions bitbucket/delete/repo/src/unix/formula/formula.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# shellcheck disable=SC2181

checkCommand() {
if ! command -v "$1" >/dev/null; then
echo "Error: $1 command required"
exit 1
fi
}

runFormula() {
checkCommand git

curl -X DELETE -u "$USERNAME":"$TOKEN" https://api.bitbucket.org/2.0/repositories/"$USERNAME"/"$PROJECT_NAME"

echo "✅ Repository successfully deleted from Bitbucket"
}
Loading

0 comments on commit b869c6f

Please sign in to comment.