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

updates in methodology chapter #14

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
128 changes: 104 additions & 24 deletions a.cli
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,62 @@
# Exit immediately if a command exits with a non-zero status
set -e

# setup hooks
setup() {
# Default values
DEFAULT_ZOTERO_USER_ID=""
DEFAULT_ZOTERO_API_KEY=""
DEFAULT_ZOTERO_GROUP_ID="5582837"
DEFAULT_BIBTEX_FILE="references.bib"

# Read environment variables or set defaults
ZOTERO_USER_ID=${ZOTERO_USER_ID:-$DEFAULT_ZOTERO_USER_ID}
ZOTERO_API_KEY=${ZOTERO_API_KEY:-$DEFAULT_ZOTERO_API_KEY}
ZOTERO_GROUP_ID=${ZOTERO_GROUP_ID:-$DEFAULT_ZOTERO_GROUP_ID}
BIBTEX_FILE=${BIBTEX_FILE:-$DEFAULT_BIBTEX_FILE}

# Function to parse command-line arguments
parse_args() {
while [[ "$#" -gt 0 ]]; do
case $1 in
--zotero-user-id) ZOTERO_USER_ID="$2"; shift ;;
--zotero-api-key) ZOTERO_API_KEY="$2"; shift ;;
--zotero-group-id) ZOTERO_GROUP_ID="$2"; shift ;;
--bibtex-file) BIBTEX_FILE="$2"; shift ;;
--help)
echo "Usage: $0 [options] {setup|create|list|delete|update-bibtex} [version]"
echo "Options:"
echo " --zotero-user-id Zotero User ID"
echo " --zotero-api-key Zotero API Key"
echo " --zotero-group-id Zotero Group ID (optional, omit if using user library)"
echo " --bibtex-file Path to the BibTeX file (default: your_bibtex_file.bib)"
echo "Commands:"
echo " setup : Setup hooks for commit, checkout, and merge"
echo " create : Create a new release with the provided version"
echo " list : List all existing releases"
echo " delete : Delete the release with the provided version"
echo " update-bibtex : Fetch and update the BibTeX file from Zotero"
echo " version : Optional argument specifying the version for create and delete commands"
exit 0 ;;
esac
shift
done
}

for i in commit checkout merge; do
cp hooks/post-commit .git/hooks/post-$i
chmod +x .git/hooks/post-$i
done
echo "Hooks setup successfully."
# Function to setup hooks
setup() {
for i in commit checkout merge; do
cp hooks/post-commit .git/hooks/post-$i
chmod +x .git/hooks/post-$i
done
echo "Hooks setup successfully."

git checkout
git checkout

if ! test -f .git/gitHeadInfo.gin; then
cp .git/gitHeadInfo.gin gitHeadLocal.gin
if ! test -f .git/gitHeadInfo.gin; then
cp .git/gitHeadInfo.gin gitHeadLocal.gin

git add gitHeadLocal.gin
git commit -m "Created gitHeadLocal.gin for initial setup"
fi
git add gitHeadLocal.gin
git commit -m "Created gitHeadLocal.gin for initial setup"
fi
}

# Function to create a release
Expand All @@ -31,26 +70,25 @@ create_release() {
exit 1
fi

# check if the tag already exists
# Check if the tag already exists
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Error: Tag $VERSION already exists."
exit 1
fi

# check the format of the version number
# Check the format of the version number
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?$ ]]; then
echo "Error: Version number should be in the format vx.y.z or vx.y.z-pre.a."
exit 1
fi


# Tag the repository with the provided version
git tag -a "$VERSION" -m "Release $VERSION"

# Checkout the tag to trigger post-commit hook to update gitinfo2 info file
git checkout

# show the reltag line of .git/gitHeadInfo.gin
# Show the reltag line of .git/gitHeadInfo.gin
grep reltag .git/gitHeadInfo.gin

cp .git/gitHeadInfo.gin gitHeadLocal.gin
Expand Down Expand Up @@ -83,12 +121,44 @@ delete_release() {
git tag -d "$VERSION"

# Delete the tag remotely
#git push origin --delete "$VERSION"
# git push origin --delete "$VERSION"

echo "Release $VERSION deleted successfully."
}

# Function to fetch and update BibTeX file from Zotero
update_bibtex() {
if [ -z "$ZOTERO_GROUP_ID" ]; then
if [ -z "$ZOTERO_USER_ID" ]; then
echo "Zotero group ID and user ID are not set, one of them is required."
echo "If Group ID is set, User ID is not required."
exit 1
fi
fi

if [ -z "$ZOTERO_API_KEY" ]; then
echo "Zotero API key is not set."
exit 1
fi

echo "Fetching BibTeX entries from Zotero..."

# Define the URL to fetch BibTeX
if [ -z "$ZOTERO_GROUP_ID" ]; then
URL="https://api.zotero.org/users/$ZOTERO_USER_ID/items?format=bibtex"
else
URL="https://api.zotero.org/groups/$ZOTERO_GROUP_ID/items?format=bibtex"
fi

# Fetch and save BibTeX entries
curl -s -H "Zotero-API-Key: $ZOTERO_API_KEY" "$URL" > "$BIBTEX_FILE"

echo "BibTeX entries updated successfully in $BIBTEX_FILE."
}

# Main script logic
parse_args "$@"

case "$1" in
setup)
setup
Expand All @@ -102,13 +172,23 @@ case "$1" in
delete)
delete_release "$2"
;;
update-bibtex)
update_bibtex
;;
*)
echo "Usage: $0 {setup|create|list|delete} [version]"
echo " setup : Setup hooks for commit, checkout, and merge"
echo " create : Create a new release with the provided version"
echo " list : List all existing releases"
echo " delete : Delete the release with the provided version"
echo " version : Optional argument specifying the version for create and delete commands"
echo "Usage: $0 [options] {setup|create|list|delete|update-bibtex} [version]"
echo "Options:"
echo " --zotero-user-id Zotero User ID (optional, omit if using group id given)"
echo " --zotero-api-key Zotero API Key"
echo " --zotero-group-id Zotero Group ID (optional, omit if using user id given)"
echo " --bibtex-file Path to the BibTeX file (default: your_bibtex_file.bib)"
echo "Commands:"
echo " setup : Setup hooks for commit, checkout, and merge"
echo " create : Create a new release with the provided version"
echo " list : List all existing releases"
echo " delete : Delete the release with the provided version"
echo " update-bibtex : Fetch and update the BibTeX file from Zotero"
echo " version : Optional argument specifying the version for create and delete commands"
exit 1
;;
esac
Loading