diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..24d443d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[**.sh] +max_line_length = 120 + +[**.md] +indent_size = 4 + +[{Makefile,**.mk,.git*}] +indent_style = tab + +[{lib/*,README.md}] +indent_size = unset diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index bc90d6e..3b9c8da 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -38,4 +38,4 @@ at [https://contributor-covenant.org/version/1/3/0/][version] [homepage]: https://contributor-covenant.org -[version]: https://contributor-covenant.org/version/1/3/0/ \ No newline at end of file +[version]: https://contributor-covenant.org/version/1/3/0/ diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..d3be202 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,100 @@ +# Contributing to bashunit + +## We have a Code of Conduct + +Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. + +## Any contributions you make will be under the MIT License + +When you submit code changes, your submissions are understood to be under the same [MIT](https://github.com/TypedDevs/bashunit/blob/main/LICENSE) that covers the project. By contributing to this project, you agree that your contributions will be licensed under its MIT. + +## Write bug reports with detail, background, and sample code + +In your bug report, please provide the following: + +* A quick summary and/or background +* Steps to reproduce + * Be specific! + * Give sample code if you can. +* What you expected would happen +* What actually happens +* Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) + +Please post code and output as text ([using proper markup](https://guides.github.com/features/mastering-markdown/)). Additional screenshots to help contextualize behavior are ok. + +## Workflow for Pull Requests + +1. Fork/clone the repository. +2. Create your branch from `main` if you plan to implement new functionality or change existing code significantly. +3. Implement your change and add tests for it. +4. Ensure the test suite passes. +5. Ensure the code complies with our coding guidelines (see below). +6. Send that pull request! + +Please make sure you have [set up your username and email address](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup) for use with Git. Strings such as `silly nick name ` looks bad in the commit history of a project. + +## Testing + +Run tests from the library: +```bash +# using make +make test + +# using bashunit +lib/bashunit tests +``` + +Run the test with a watcher for development: +this will require to have installed [fswatcher](https://github.com/emcrisostomo/fswatch) +```bash +# you have to install `watch` for your OS +make test/watch +``` + +## Coding Guidelines + +### ShellCheck + +To contribute to this repository you must have [ShellCheck](https://github.com/koalaman/shellcheck) installed on your local machine or IDE, since it is the static code analyzer that is being used in continuous integration pipelines. + +Installation: https://github.com/koalaman/shellcheck#installing + +#### Example of usage + +```bash +# using make +make sa + +# using ShellCheck itself +shellcheck ./**/**/*.sh -C +``` + +### editorconfig-checker + +To contribute to this repository, consider installing [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) to check all project files regarding the `.editorconfig` to ensure we all fulfill the standard. + +Installation: https://github.com/editorconfig-checker/editorconfig-checker#installation + +To run it, use the following command: +```bash +# using make +make lint + +# using editorconfig-checker itself +ec -config .editorconfig +``` + +This command will be executed on the CI to ensure the project's quality standards. + +#### We recommend + +To install the pre-commit of the project with the following command: + +**Please note that you will need to have ShellCheck and editorconfig-checker installed on your computer.** +See above how to install in your local. + +```bash +make pre_commit/install +``` + +[Shell Guide](https://google.github.io/styleguide/shellguide.html#s7.2-variable-names) by Google Conventions. diff --git a/LICENSE b/LICENSE index 1b4c92f..efd4302 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4f28bf4 --- /dev/null +++ b/Makefile @@ -0,0 +1,92 @@ +SHELL=/bin/bash + +-include .env + +STATIC_ANALYSIS_CHECKER := $(shell which shellcheck 2> /dev/null) +LINTER_CHECKER := $(shell which ec 2> /dev/null) +GIT_DIR = $(shell git rev-parse --git-dir 2> /dev/null) + +OS:= +ifeq ($(OS),Windows_NT) + OS +=WIN32 + ifeq ($(PROCESSOR_ARCHITECTURE),AMD64) + OS +=_AMD64 + endif + ifeq ($(PROCESSOR_ARCHITECTURE),x86) + OS +=_IA32 + endif +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + OS+=LINUX + endif + ifeq ($(UNAME_S),Darwin) + OS+=OSX + endif + UNAME_P := $(shell uname -p) + ifeq ($(UNAME_P),x86_64) + OS +=_AMD64 + endif + ifneq ($(filter %86,$(UNAME_P)),) + OS+=_IA32 + endif + ifneq ($(filter arm%,$(UNAME_P)),) + OS+=_ARM + endif +endif + +help: + @echo "" + @echo "Usage: make [command]" + @echo "" + @echo "Commands:" + @echo " test Run the tests" + @echo " test/list List all tests under the tests directory" + @echo " test/watch Automatically run tests every second" + @echo " env/example Copy variables without the values from .env into .env.example" + @echo " pre_commit/install Install the pre-commit hook" + @echo " pre_commit/run Function that will be called when the pre-commit hook runs" + @echo " sa Run shellcheck static analysis tool" + @echo " lint Run editorconfig linter tool" + +SRC_SCRIPTS_DIR=src +TEST_SCRIPTS_DIR=tests +EXAMPLE_TEST_SCRIPTS=./example/logic_test.sh +PRE_COMMIT_SCRIPTS_FILE=./bin/pre-commit + +TEST_SCRIPTS = $(wildcard $(TEST_SCRIPTS_DIR)/*/*[tT]est.sh) + +test/list: + @echo "Test scripts found:" + @echo $(TEST_SCRIPTS) | tr ' ' '\n' + +test: $(TEST_SCRIPTS) + @lib/bashunit $(TEST_SCRIPTS) + +test/watch: $(TEST_SCRIPTS) + @lib/bashunit $(TEST_SCRIPTS) + @fswatch -m poll_monitor -or $(SRC_SCRIPTS_DIR) $(TEST_SCRIPTS_DIR) .env Makefile | xargs -n1 lib/bashunit $(TEST_SCRIPTS) + +env/example: + @echo "Copying variables without the values from .env into .env.example" + @sed 's/=.*/=/' .env > .env.example + +pre_commit/install: + @echo "Installing pre-commit hook" + cp $(PRE_COMMIT_SCRIPTS_FILE) $(GIT_DIR)/hooks/ + +pre_commit/run: test sa lint env/example + +sa: +ifndef STATIC_ANALYSIS_CHECKER + @printf "\e[1m\e[31m%s\e[0m\n" "Shellcheck not installed: Static analysis not performed!" && exit 1 +else + @shellcheck ./**/*.sh -C && printf "\e[1m\e[32m%s\e[0m\n" "ShellCheck: OK!" +endif + +lint: +ifndef LINTER_CHECKER + @printf "\e[1m\e[31m%s\e[0m\n" "Editorconfig not installed: Lint not performed!" && exit 1 +else + @ec -config .editorconfig && printf "\e[1m\e[32m%s\e[0m\n" "editorconfig-check: OK!" +endif diff --git a/README.md b/README.md index 610d3f6..4f52f32 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ To build the project yourself, you can do it manually or execute it `./build.sh` ## How to use it? Optional env vars: -- `PR_TICKET_LINK_PREFIX=https://your-company.atlassian.net/browse/` - - This will be replaced in the placeholder `{{TICKET_LINK}}` in your PR template +- `PR_TICKET_LINK_PREFIX=https://your-company.atlassian.net/browse/` + - This will be replaced in the placeholder `{{TICKET_LINK}}` in your PR template - If no value is present for `PR_TICKET_LINK_PREFIX` then the `{{TICKET_LINK}}` will be ignored - It will use the ticket key and number to append to the link prefix - `PR_TEMPLATE_DIR=.github/PULL_REQUEST_TEMPLATE.md` diff --git a/create-pr.sh b/create-pr.sh index 90131a7..62914aa 100755 --- a/create-pr.sh +++ b/create-pr.sh @@ -39,12 +39,13 @@ fi # Create the PR with the specified options if ! gh pr create --title "$PR_TITLE" \ - --base "$BASE_BRANCH" \ - --head "$BRANCH_NAME" \ - --assignee "$ASSIGNEE" \ - --label "$LABEL" \ - --body "$PR_BODY"; then - error_and_exit "Failed to create the pull request. Ensure you have the correct permissions and the repository is properly configured." + --base "$BASE_BRANCH" \ + --head "$BRANCH_NAME" \ + --assignee "$ASSIGNEE" \ + --label "$LABEL" \ + --body "$PR_BODY"; then + error_and_exit "Failed to create the pull request."\ + "Ensure you have the correct permissions and the repository is properly configured." fi echo "Pull request created successfully." diff --git a/src/check_os.sh b/src/check_os.sh index 6f17e8f..b702549 100644 --- a/src/check_os.sh +++ b/src/check_os.sh @@ -9,4 +9,4 @@ elif [[ "$(uname)" == "Darwin" ]]; then _OS="OSX" elif [[ $(uname) == *"MINGW"* ]]; then _OS="Windows" -fi \ No newline at end of file +fi diff --git a/src/dev/debug.sh b/src/dev/debug.sh index 879f4d8..f50135c 100644 --- a/src/dev/debug.sh +++ b/src/dev/debug.sh @@ -57,4 +57,4 @@ function debug_var() { printf "[%s] %s: %s=%s\n" "${_COLOR_FAINT}DEBUG${_COLOR_DEFAULT}" \ "${_COLOR_GREEN}${BASH_SOURCE[1]}:${BASH_LINENO[0]}" \ "$var_name" "$var_value" -} \ No newline at end of file +} diff --git a/src/generic.sh b/src/generic.sh index 87345c2..571c7a1 100644 --- a/src/generic.sh +++ b/src/generic.sh @@ -19,7 +19,7 @@ function validate_the_branch_has_commits() { function validate_base_branch_exists() { if ! git show-ref --verify --quiet "refs/heads/$BASE_BRANCH"; then - error_and_exit "Base branch '$BASE_BRANCH' does not exist. Please check the base branch name or create it." + error_and_exit "Base branch '$BASE_BRANCH' does not exist. Please check the base branch name or create it." fi } diff --git a/src/pr_format.sh b/src/pr_format.sh index 74fd63b..848f057 100644 --- a/src/pr_format.sh +++ b/src/pr_format.sh @@ -16,7 +16,7 @@ function format_title() { prefix=$(echo "$input" | cut -d'/' -f1) input="${input#*/}" - case "$prefix" in + case "$prefix" in fix|bug|bugfix) prefix="Fix" ;; *) prefix="" ;; esac