Skip to content

Commit

Permalink
Squashed 'vendor/' changes from b9b06d9..dcb8d42
Browse files Browse the repository at this point in the history
dcb8d42 Merge pull request #18 from jpower432/feat/allow-author-config
6f398b3 feat: adds abilty to set commit author from top-level scripts

git-subtree-dir: vendor
git-subtree-split: dcb8d42f4e9a7f19b0c424a9a76c10a054165981
  • Loading branch information
jpower432 committed Jun 12, 2023
1 parent af1ab53 commit 4f8de91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
12 changes: 6 additions & 6 deletions scripts/auto-commit-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function clone_repo() {
# Function to commit changes locally in git
function local_commit () {
local COMMIT_MESSAGE="${1:-"chore: automatic content update"}"
local COMMIT_USER="${2:-"github-actions[bot]"}"
local COMMIT_EMAIL="${3:-"github-actions@github.com"}"
local COMMIT_AUTHOR="${4:-"github-actions[bot] <github-actions@github.com>"}"
local COMMIT_AUTHOR="${2:-"github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"}"
local COMMIT_USER="${3:-"github-actions[bot]"}"
local COMMIT_EMAIL="${4:-"41898282+github-actions[bot]@users.noreply.github.com"}"

git -c user.name="$COMMIT_USER" -c user.email="$COMMIT_EMAIL" \
commit -m "$COMMIT_MESSAGE" --author "$COMMIT_AUTHOR"
Expand All @@ -39,9 +39,9 @@ function push_to_remote() {

# Function to create a new branch and GitHub pull request
function create_branch_pull_request() {
local PR_TITLE="${1:-"chore: sync OSCAL content"}"
local PR_BODY="${2:-"chore: automatic content update"}"
local BRANCH="${3:?"branch is required"}"
local BRANCH="${1:?"branch is required"}"
local PR_TITLE="${2:-"chore: sync OSCAL content"}"
local PR_BODY="${3:-"chore: automatic content update"}"
push_to_remote "$BRANCH"
gh pr create -t "$PR_TITLE" -b "$PR_BODY" -B "main" -H "$BRANCH" --draft
}
Expand Down
10 changes: 6 additions & 4 deletions scripts/update-from-upstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ function main() {
DEFAULT_INCLUDE_DIRS=()
BRANCH=""
REPO_URL=""
AUTHOR=""
patterns=()

# Parse command line options
while getopts ":b:r:p:i:" opt; do
while getopts ":b:r:a:p:i:" opt; do
case $opt in
b) BRANCH="$OPTARG";;
r) REPO_URL="$OPTARG";;
a) AUTHOR="$OPTARG";;
p) patterns+=("$OPTARG");;
i) include_dirs+=("$OPTARG");;
\?) echo "Invalid option -$OPTARG" >&2; exit 1;;
Expand All @@ -40,7 +42,7 @@ function main() {

# Check if required arguments are provided
if [ -z "$BRANCH" ] || [ -z "$REPO_URL" ] || [ ${#patterns[@]} -eq 0 ]; then
echo "Usage: update-from-upstream.sh -b branch -r repo_url -p pattern1 -p pattern2 ... [-i include_dir1] [-i include_dir2] ..."
echo "Usage: update-from-upstream.sh -b branch -r repo_url -a author -p pattern1 -p pattern2 ... [-i include_dir1] [-i include_dir2] ..."
exit 1
fi

Expand Down Expand Up @@ -83,8 +85,8 @@ function main() {
add_files "${patterns[@]}"

if [ -n "$(git status --untracked-files=no --porcelain)" ]; then
local_commit "$COMMIT_BODY"
create_branch_pull_request "$COMMIT_TITLE" "$COMMIT_BODY" "autoupdate_$GITHUB_RUN_ID"
local_commit "$COMMIT_BODY" "$AUTHOR"
create_branch_pull_request "autoupdate_$GITHUB_RUN_ID" "$COMMIT_TITLE" "$COMMIT_BODY"
else
run_log 0 "Nothing to commit."
fi
Expand Down
8 changes: 5 additions & 3 deletions scripts/update-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ source "$SCRIPT_DIR/logging.sh"
# shellcheck disable=SC1091
source "$SCRIPT_DIR/auto-commit-push.sh"

USAGE="Usage: update-push.sh [-b branch] [-c commit_msg] <patterns>"
USAGE="Usage: update-push.sh [-b branch] [-c commit_msg] [-a author] <patterns>"

function main() {

DEFAULT_COMMIT_MSG="chore: automatic content update"
BRANCH=""
AUTHOR=""

# Parse command line options
while getopts ":b:c:" opt; do
while getopts ":b:c:a:" opt; do
case $opt in
b) BRANCH="$OPTARG";;
c) commit_msg="$OPTARG";;
a) AUTHOR="$OPTARG";;
\?) echo "Invalid option -$OPTARG" >&2; exit 1;;
esac
done
Expand All @@ -53,7 +55,7 @@ function main() {
add_files "${patterns[@]}"

if [ -n "$(git status --untracked-files=no --porcelain)" ]; then
local_commit "$COMMIT_BODY"
local_commit "$COMMIT_BODY" "$AUTHOR"
push_to_remote "$BRANCH"
else
run_log 0 "Nothing to commit."
Expand Down
10 changes: 6 additions & 4 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ source "$SCRIPT_DIR/logging.sh"
# shellcheck disable=SC1091
source "$SCRIPT_DIR/auto-commit-push.sh"

USAGE="Usage: update.sh [-c commit_msg] <patterns>"
USAGE="Usage: update.sh [-c commit_msg] [-a author] <patterns>"

function main() {

DEFAULT_COMMIT_MSG="chore: automatic content update"
AUTHOR=""

# Parse command line options
while getopts ":c:" opt; do
while getopts ":c:a:" opt; do
case $opt in
c) commit_msg="$OPTARG";;
a) AUTHOR="$OPTARG";;
\?) echo "Invalid option -$OPTARG" >&2; exit 1;;
esac
done
Expand Down Expand Up @@ -57,8 +59,8 @@ function main() {
if [ -z "$(git status --untracked-files=no --porcelain)" ]; then
run_log 0 "Nothing to commit"
else
local_commit "$COMMIT_BODY"
create_branch_pull_request "$COMMIT_TITLE" "$COMMIT_BODY" "autoupdate_$GITHUB_RUN_ID"
local_commit "$COMMIT_BODY" "$AUTHOR"
create_branch_pull_request "autoupdate_$GITHUB_RUN_ID" "$COMMIT_TITLE" "$COMMIT_BODY"
fi
fi
}
Expand Down

0 comments on commit 4f8de91

Please sign in to comment.