Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link development branches to issues and remove bugfix and feature wrappers over branch #88

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'main' into feature/link-issues
  • Loading branch information
willsawyerrrr committed Mar 11, 2024
commit 255556e7b246c91fd54b8ed1c33c89bcea78779a
27 changes: 18 additions & 9 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
version: 2
updates:
- package-ecosystem: "github-actions"
reviewers:
- "SituDevelopment/employees"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
time: "13:00"
timezone: "Australia/Brisbane"

- package-ecosystem: "npm"
reviewers:
- "SituDevelopment/employees"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
time: "13:00"
timezone: "Australia/Brisbane"

- package-ecosystem: "pip"
reviewers:
- "SituDevelopment/employees"
directory: "/"
groups:
pydantic:
patterns:
- "pydantic"
- "pydantic-core"
pylint:
patterns:
- "astroid"
- "pylint"
schedule:
interval: "daily"
interval: "weekly"
time: "13:00"
timezone: "Australia/Brisbane"
5 changes: 4 additions & 1 deletion .github/labeller.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
bug:
- head-branch: ["bug/*"]

enhancement:
chore:
- head-branch: ["chore/*"]

feature:
- head-branch: ["feature/*"]

dependencies:
2 changes: 1 addition & 1 deletion .github/workflows/add-to-project.yaml
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ jobs:
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- uses: actions/add-to-project@v0.5.0
- uses: actions/add-to-project@v0.6.0
with:
project-url: https://github.com/orgs/SituDevelopment/projects/4
github-token: ${{ secrets.ADD_TO_PROJECT }}
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,12 @@
Tools and configurations for automating processes and ensuring consistency across
codebases and working directories.

## Installation

```shell
curl -sSL https://raw.githubusercontent.com/SituDevelopment/automation/main/install.sh | bash
```

## Tools

- `branch`
@@ -13,14 +19,6 @@ codebases and working directories.
- Creates a GitHub pull request with the given properties.
- `find-by-extension`
- Determines the existence and echoes the names of files with the given file extension(s).
- `github`
- Creates a new GitHub repository with test and production branches.
- `git-post-checkout-hook`
- Initialises the local development environment after checking out a Git repository.
- `git-pre-commit-hook`
- Ensures formatters are installed and formats staged files before committing.
- `prod`
- Pushes the local test branch to production.

## Configurations

4 changes: 2 additions & 2 deletions branch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
#
#
# Creates a new development branch for a GitHub issue.
@@ -128,7 +128,7 @@ issue=$2
# set default values for unset variables
reuse=${reuse:=""}
owner=${owner:="SituDevelopment"}
base=${base:=$(gh api /repos/${owner}/${repo}/branches?protected=true --jq '.[0].name')}
base=${base:=$(bkt --discard-failures -- gh api /repos/${owner}/${repo}/branches?protected=true --jq '.[0].name')}
dev=${dev:=""}


76 changes: 76 additions & 0 deletions branch.completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
#
# Provides autocompletion for the `branch`, `bugfix-branch`, `chore-branch` and `feature-branch` commands.

function _remove_from_array() {
local array=("$@")
local remove=$1
local new_array=()
for i in "${array[@]}"; do
if [[ ${i} != ${remove} ]]; then
new_array+=(${i})
fi
done
echo ${new_array[@]}
unset new_array
}

function _branch() {
cur=${COMP_WORDS[${COMP_CWORD}]}
prev=${COMP_WORDS[${COMP_CWORD}-1]}

# branch [-r] [-o <owner>] [-b <base-branch>] <repository> <branch-name>
options="-r -o -b"
option_offset=0

owner="SituDevelopment"
for ((i=1; i<${#COMP_WORDS[@]}; i++)); do
case ${COMP_WORDS[$i]} in
-r)
options=$(_remove_from_array "-r" ${options})
option_offset=$((${option_offset}+1))
;;
-o)
options=$(_remove_from_array "-o" ${options})
option_offset=$((${option_offset}+2))
owner=${COMP_WORDS[$i+1]}
;;
-b)
options=$(_remove_from_array "-b" ${options})
option_offset=$((${option_offset}+2))
base_branch=${COMP_WORDS[$i+1]} # TODO: autocomplete base-branch based off of owner and repository
;;
esac
done

# complete option
if [[ "${cur}" == "-*" ]]; then
COMPREPLY=($(compgen -W "${options}" -- "${cur}"))
return
fi

# complete repository
if [[ ${COMP_CWORD} -eq $((${option_offset}+1)) ]]; then
if bkt --discard-failures -- gh api /orgs/${owner} --silent 2> /dev/null; then
# owner is an org
repos=$(bkt --discard-failures -- gh api "/orgs/${owner}/repos?per_page=100" --jq '.[].name' 2> /dev/null)
elif bkt --discard-failures -- gh api /users/${owner} --silent 2> /dev/null; then
# owner is a user
repos=$(bkt --discard-failures -- gh api "/users/${owner}/repos?per_page=100" --jq '.[].name' 2> /dev/null)
else
# owner does not exist
repos=""
fi

COMPREPLY=($(compgen -W "${repos} ${options}" -- "${cur}"))
fi

# complete base-branch
if [[ "${prev}" == "-b" ]]; then
repo=${COMP_WORDS[$((${option_offset}+1))]}
branches=$(bkt --discard-failures -- gh api "/repos/${owner}/${repo}/branches" --jq '.[].name' 2> /dev/null)
COMPREPLY=($(compgen -W "${branches}" -- "${cur}"))
fi
}

complete -F _branch branch bugfix-branch chore-branch feature-branch
5 changes: 4 additions & 1 deletion clone-mongo-db
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
#
#
# Clones a MongoDB database.
@@ -97,3 +97,6 @@ assert_success "Cloning database $1 to $2..." \
"Failed to clone database $1 to $2." \
${MONGO_ERROR} \
"Successfully cloned database $1 to $2."


exit ${SUCCESS}
16 changes: 16 additions & 0 deletions completions
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
#
#
# Initialises autocompletion for the Automation suite.

export BKT_TTL="1m"
export BKT_SCOPE="$$"

completions=(branch create-pr)

for completion in ${completions[@]}; do
if [ -f "./${completion}.completion" ]; then
source "./${completion}.completion"
fi
done

19 changes: 7 additions & 12 deletions create-pr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
#
#
# Creates a GitHub pull request with the given properties.
@@ -37,7 +37,7 @@ GITHUB_ERROR=2
#######################################
showhelp() {
# Get list of labels for the current repository
label_options=$(gh label list --json name --template '{{range .}}{{"\t\t\t - "}}{{.name}}{{"\n"}}{{end}}' 2> /dev/null)
label_options=$(bkt --discard-failures -- gh label list --json name --template '{{range .}}{{"\t\t\t - "}}{{.name}}{{"\n"}}{{end}}' 2> /dev/null)
if [[ -n "${label_options}" ]]; then
label_options=$'Available labels:\n'$label_options
fi
@@ -111,15 +111,18 @@ fi

if [[ -z "${base}" ]]; then
assert_success "Determining base branch..." \
"base=$(gh api /repos/$(git remote get-url origin | sed 's/git@github.com://')/branches?protected=true --jq '.[0].name')" \
"base=$(bkt --discard-failures -- gh api /repos/$(git remote get-url origin | sed 's/^git@github.com://' | sed 's/.git$//g')/branches?protected=true --jq '.[0].name')" \
"Error determining base branch" \
${GITHUB_ERROR} \
"Base branch determined\n"
fi


title=$(git branch --show-current)
title=$(echo ${title} | sed -e 's|\(.*\)/|\u\1:-|') # Replace '<type>/' prefix with '<Type>:-'
title=$(echo ${title} | sed -e 's|-\(.\)| \u\1|g') # convert kebab-case to Title Case
assert_success "Creating pull request..." \
"gh pr create --assignee @me --base '${base}' --fill ${labels}" \
"gh pr create --assignee @me --base '${base}' --fill ${labels} --title '${title}'" \
"Error creating pull request" \
${GITHUB_ERROR} \
"Pull request created\n"
@@ -134,13 +137,5 @@ assert_success "Requesting review from 'Employees' team..." \
"Review requested\n"


assert_success "Enabling auto-merge..." \
"gh pr merge ${testb} --auto --rebase" \
"Error enabling auto-merge" \
${GITHUB_ERROR} \
"Auto-merge enabled\n"


echo "Goodbye..."
exit ${SUCCESS}

33 changes: 33 additions & 0 deletions create-pr.completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
#
# Provides autocompletion for the `create-pr` command.


function _create-pr() {
cur=${COMP_WORDS[${COMP_CWORD}]}

# create-pr [-b <base-branch>] [<label> ...]
options="-b"

if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ]]; then
# Not in a git repository
return
fi

# create-pr [-b <base-branch>] [<label> ...]
if [[ ${COMP_CWORD} -eq 2 && "${cur}" == "-b" ]]; then
# Complete the base branch
branches=$(bkt --discard-failures -- gh api /repos/$(git remote get-url origin | sed 's/^git@github.com://' | sed 's/.git$//g')/branches --jq '.[].name')
COMPREPLY=($(compgen -W "${branches}" -- "${cur}"))
else
# Complete the labels
labels=$(bkt --discard-failures -- gh label list --json name --jq '.[].name' 2> /dev/null)
if [[ ${COMP_CWORD} -eq 1 ]]; then
COMPREPLY=($(compgen -W "${labels} ${options}" -- "${cur}"))
else
COMPREPLY=($(compgen -W "${labels}" -- "${cur}"))
fi
fi
}

complete -F _create-pr create-pr
2 changes: 1 addition & 1 deletion find-by-extension
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
#
#
# Determines the existence and echoes the names of files with the given file
50 changes: 0 additions & 50 deletions git-post-checkout-hook

This file was deleted.

30 changes: 0 additions & 30 deletions git-pre-commit-hook

This file was deleted.

Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.