Skip to content

Commit

Permalink
feat(shellcheck): apply fixes throughout this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
myii committed Nov 27, 2019
1 parent b6d7742 commit 1ea7fbb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
6 changes: 3 additions & 3 deletions pre-commit_semantic-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA
sudo -H pip install m2r

# Copy and then convert the `.md` docs
cp *.md docs/
cd docs/
m2r --overwrite *.md
cp ./*.md docs/
cd docs/ || exit
m2r --overwrite ./*.md

# Change excess `H1` headings to `H2` in converted `CHANGELOG.rst`
sed -i -e '/^=.*$/s/=/-/g' CHANGELOG.rst
Expand Down
18 changes: 10 additions & 8 deletions ssf/files/default/git/git_10_prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ COMMENT='Command `'${STATE}'` run'
# Check if PR branch already exists
BRANCH=$(git branch -l "${BRANCH_PR}")
COMMIT=
if [ ! -z "${BRANCH}" ]; then
git checkout ${BRANCH_PR}
if [ -n "${BRANCH}" ]; then
git checkout "${BRANCH_PR}"
# This may end up as blank as well, so that's why a separate `if` is required below
COMMIT=$(git log -n1 | grep "${COMMIT_GREP}")
fi

# Perform actions depending on if a commit was found or not
if [ ! -z "${COMMIT}" ]; then
if [ -n "${COMMIT}" ]; then
CHANGED='False'
else
git checkout ${BRANCH_UPSTREAM}
git checkout "${BRANCH_UPSTREAM}"
git pull
git status
# If the branch existed but not the commit, assume the branch is stale (i.e. previous PR merged)
# Remove it, ready to be recreated at the latest upstream commit
if [ ! -z "${BRANCH}" ]; then
git branch -d ${BRANCH_PR}
if [ -n "${BRANCH}" ]; then
git branch -d "${BRANCH_PR}"
fi
# TODO: Improve this part, should be able to remove with the duplication with the right solution
# Don't want to resort to using `git branch -D` above, since that could be premature in certain situations
Expand All @@ -40,8 +40,10 @@ else
if [ -z "${BRANCH}" ]; then
NEW_BRANCH='-b'
fi
git checkout ${NEW_BRANCH} ${BRANCH_PR}
git merge ${BRANCH_UPSTREAM}
# Disabling `SC2086` where double-quoting an empty variable introduces an error
# shellcheck disable=SC2086
git checkout ${NEW_BRANCH} "${BRANCH_PR}"
git merge "${BRANCH_UPSTREAM}"
fi

# Write the state line
Expand Down
22 changes: 13 additions & 9 deletions ssf/files/default/git/git_20_commit_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ COMMIT_GREP=${4}
COMMIT_TITLE=${5}
COMMIT_BODY=${6}
COMMIT_OPTIONS=${7}
PUSH_ACTIVE=$(echo ${8} | tr "[:upper:]" "[:lower:]")
PUSH_VIA_PR=$(echo ${9} | tr "[:upper:]" "[:lower:]")
PUSH_ACTIVE=$(echo "${8}" | tr "[:upper:]" "[:lower:]")
PUSH_VIA_PR=$(echo "${9}" | tr "[:upper:]" "[:lower:]")
REMOTE_FORK_NAME=${10}
REMOTE_FORK_BRANCH=${11}
# Currently unused but leaving here as a placeholder
# REMOTE_FORK_BRANCH=${11}
REMOTE_UPSTREAM_NAME=${12}
REMOTE_UPSTREAM_BRANCH=${13}
# Prepare initial state line variables
Expand All @@ -22,7 +23,7 @@ COMMENT='Command `'${STATE}'` run'

# Prepare git options depending on if a commit was found or not
COMMIT=$(git log -n1 | grep "${COMMIT_GREP}")
if [ ! -z "${COMMIT}" ]; then
if [ -n "${COMMIT}" ]; then
AMEND='--amend'
FORCE='-f'
else
Expand All @@ -31,15 +32,18 @@ else
fi

# Perform actions
# Disabling `SC2086` where double-quoting an empty variable introduces errors
# shellcheck disable=SC2086
git commit ${AMEND} "${COMMIT_OPTIONS}" -m "${COMMIT_TITLE}" -m "${COMMIT_BODY}"
if ${PUSH_ACTIVE}; then
if ${PUSH_VIA_PR}; then
git push ${FORCE} -u ${REMOTE_FORK_NAME} ${BRANCH_PR}
# shellcheck disable=SC2086
git push ${FORCE} -u "${REMOTE_FORK_NAME}" "${BRANCH_PR}"
else
git checkout ${BRANCH_UPSTREAM}
git merge ${BRANCH_PR}
git push ${REMOTE_UPSTREAM_NAME} HEAD:${REMOTE_UPSTREAM_BRANCH}
git branch -d ${BRANCH_PR}
git checkout "${BRANCH_UPSTREAM}"
git merge "${BRANCH_PR}"
git push "${REMOTE_UPSTREAM_NAME}" "HEAD:${REMOTE_UPSTREAM_BRANCH}"
git branch -d "${BRANCH_PR}"
fi
fi

Expand Down
10 changes: 5 additions & 5 deletions ssf/files/default/git/git_30_create_PR.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ COMMENT='Command `'${STATE}'` run'

# Only create the PR if it doesn't already exist
# If it already exists, the `git push` done earlier will have updated the PR already
PR_EXISTS=$(curl -i https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls | grep "${GH_USER}:${BRANCH_PR}")
if [ ! -z "${PR_EXISTS}" ]; then
PR_EXISTS=$(curl -i "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls" | grep "${GH_USER}:${BRANCH_PR}")
if [ -n "${PR_EXISTS}" ]; then
CHANGED='False'
else
curl -H "Authorization: bearer ${GH_TOKEN}" -d '
{
"title": "'"${COMMIT_TITLE}"'",
"body": "'"${COMMIT_BODY}"'",
"head": "'${GH_USER}':'${BRANCH_PR}'",
"base": "'${REPO_BRANCH}'"
"head": "'"${GH_USER}"':'"${BRANCH_PR}"'",
"base": "'"${REPO_BRANCH}"'"
}
' https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls >> ${FILE_API_RESPONSE}
' "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/pulls" >> "${FILE_API_RESPONSE}"
fi

# Write the state line
Expand Down
6 changes: 3 additions & 3 deletions ssf/files/default/pre-commit_semantic-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA
sudo -H pip install m2r

# Copy and then convert the `.md` docs
cp *.md docs/
cd docs/
m2r --overwrite *.md
cp ./*.md docs/
cd docs/ || exit
m2r --overwrite ./*.md

# Change excess `H1` headings to `H2` in converted `CHANGELOG.rst`
sed -i -e '/^=.*$/s/=/-/g' CHANGELOG.rst
Expand Down

0 comments on commit 1ea7fbb

Please sign in to comment.