From 2e1759af8abaafc3a5a0a9345a1da88062bfc876 Mon Sep 17 00:00:00 2001 From: ReachableCEO Date: Thu, 5 Dec 2024 20:20:27 -0600 Subject: [PATCH] automation --- README.md | 5 +- dsr-joplin-create/dsr-new.sh | 97 +++++++++++++++ dsr-joplin-create/dsr-populate-objectives.sh | 114 ++++++++++++++++++ dsr-publish/.daily-stakeholder-report.yml.swp | Bin 0 -> 12288 bytes dsr-publish/create-dsr-pdf.sh | 6 +- dsr-publish/daily-stakeholder-report.yml | 10 ++ dsr-publish/publish-dsr.sh | 7 +- 7 files changed, 231 insertions(+), 8 deletions(-) create mode 100644 dsr-publish/.daily-stakeholder-report.yml.swp create mode 100644 dsr-publish/daily-stakeholder-report.yml diff --git a/README.md b/README.md index 432c84a..a13be5c 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,9 @@ ## Introduction -I publish a daily stakeholder report to the TSYS Group discourse every day. Up until 11/29 I was performing the publishing step manually. -On 11/29 I automated the process. I also begin work on automated gathering of data going into the new version of the report. +I publish a daily stakeholder report to the TSYS Group discourse every day. Up until 11/29 I was performing the publishing step manually. On 11/29 I automated the pdf creation and publishing to discourse procedure. -These scripts help me maintain a daily report and high fidelity information in the report for my stake holders. +I also begin work on automated gathering of data going into the new version of the report that is in development. ## Scripts diff --git a/dsr-joplin-create/dsr-new.sh b/dsr-joplin-create/dsr-new.sh index e69de29..61f8018 100644 --- a/dsr-joplin-create/dsr-new.sh +++ b/dsr-joplin-create/dsr-new.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# Use the Joplin CLI and create a new note for today. Let me pass in the notebook folder path. Use bash functions. + +# Created by chatgpt +# https://chatgpt.com/share/6750c7df-6b2c-8005-a91c-1bc5b3875170 + + +# shellcheck disable=SC1090 + +# Bash3 Boilerplate Setup +set -o errexit +set -o nounset +set -o pipefail +IFS=$'\n\t' + +# Constants +readonly SCRIPT_NAME=$(basename "$0") +readonly SCRIPT_VERSION="1.0" +readonly SCRIPT_AUTHOR="Charles N Wyble" +readonly SCRIPT_DESC="Create a new Daily Stakeholder Report note in Joplin" + +# Logging and Debugging (from bash3boilerplate) +readonly LOG_FILE="/tmp/${SCRIPT_NAME}.log" +readonly TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S') +info() { echo "[INFO] [$TIMESTAMP] $*"; } +error() { echo "[ERROR] [$TIMESTAMP] $*" >&2; } + +# Default Exit Codes +readonly ERR_JOPLIN_NOT_INSTALLED=10 +readonly ERR_NOTEBOOK_NOT_FOUND=20 + +# Function: Usage Instructions +usage() { + cat < + +Example: + $SCRIPT_NAME "Stakeholder Reports" + +Options: + -h, --help Display this help message. +EOF +} + +# Check dependencies +require_joplin() { + if ! command -v joplin &>/dev/null; then + error "Joplin CLI is not installed or not in PATH. Please install it and try again." + exit $ERR_JOPLIN_NOT_INSTALLED + fi +} + +# Check if notebook exists in Joplin +notebook_exists() { + local notebook="$1" + if ! joplin use "$notebook" >/dev/null 2>&1; then + error "Notebook '$notebook' does not exist. Please create it first." + exit $ERR_NOTEBOOK_NOT_FOUND + fi +} + +# Create a new note in the specified notebook +create_note() { + local notebook="$1" + local today_date=$(date '+%d-%m-%Y') # Format: YYYY-MM-DD + local title="Daily Stakeholder Report - $date" + local content="## Daily Stakeholder Report\n\n**Date:** $date\n\n---\n\n### Key Updates\n\n- \n\n### Issues\n\n- \n\n### Next Steps\n\n- \n" + + joplin create note --title "$title" --body "$content" >/dev/null + info "Note created successfully in notebook '$notebook'." +} + +# Main Function +main() { + local notebook_path="$1" + + # Ensure Joplin CLI is present + require_joplin + + # Verify notebook existence + notebook_exists "$notebook_path" + + # Create a new note + create_note "$notebook_path" +} + +# Argument Parsing +if [[ $# -lt 1 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then + usage + exit 0 +fi + +main "$1" diff --git a/dsr-joplin-create/dsr-populate-objectives.sh b/dsr-joplin-create/dsr-populate-objectives.sh index e69de29..cd8d069 100644 --- a/dsr-joplin-create/dsr-populate-objectives.sh +++ b/dsr-joplin-create/dsr-populate-objectives.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env bash + +# Written by ChatGPT +# https://chatgpt.com/share/6750c7df-6b2c-8005-a91c-1bc5b3875170 + +# Prompt: +# Pull any issues from Redmine that have a due date of today via API + +# shellcheck disable=SC1090 + +# Bash3 Boilerplate Setup +set -o errexit +set -o nounset +set -o pipefail +IFS=$'\n\t' + +# Constants +readonly SCRIPT_NAME=$(basename "$0") +readonly SCRIPT_VERSION="1.0" +readonly SCRIPT_AUTHOR="Charles N Wyble" +readonly SCRIPT_DESC="Pull Redmine issues with a due date of today and output in Markdown" + +# Logging and Debugging +readonly LOG_FILE="/tmp/${SCRIPT_NAME}.log" +readonly TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S') +info() { echo "[INFO] [$TIMESTAMP] $*" | tee -a "$LOG_FILE"; } +error() { echo "[ERROR] [$TIMESTAMP] $*" >&2 | tee -a "$LOG_FILE"; } + +# Default Exit Codes +readonly ERR_CURL_NOT_INSTALLED=10 +readonly ERR_API_FAILURE=20 + +# Configuration +readonly REDMINE_INSTANCE="projects.knownelement.com" +readonly REDMINE_API_URL="https://${REDMINE_INSTANCE}" +readonly REDMINE_API_KEY="your_api_key_here" +readonly DATE=$(date '+%Y-%m-%d') + +# Function: Usage Instructions +usage() { + cat < + +Options: + -h, --help Display this help message. + +Example: + $SCRIPT_NAME 123 +EOF +} + +# Check dependencies +require_curl() { + if ! command -v curl &>/dev/null; then + error "curl is not installed or not in PATH. Please install it and try again." + exit $ERR_CURL_NOT_INSTALLED + fi +} + +# Fetch issues from Redmine API +fetch_issues() { + local project_id="$1" + local url="${REDMINE_API_URL}/issues.json?key=${REDMINE_API_KEY}&project_id=${project_id}&due_date=${DATE}" + + info "Fetching issues with due date ${DATE} for project ID ${project_id}..." + response=$(curl -s -w "%{http_code}" -o /tmp/redmine_response.json "$url") + http_code=$(tail -n1 <<<"$response") + + if [[ "$http_code" -ne 200 ]]; then + error "Failed to fetch issues from Redmine API. HTTP Code: $http_code" + exit $ERR_API_FAILURE + fi + + info "Issues fetched successfully. Parsing and converting to Markdown..." + generate_markdown /tmp/redmine_response.json +} + +# Generate Markdown output from JSON response +generate_markdown() { + local json_file="$1" + local markdown_output="/tmp/redmine_issues.md" + + echo "# Redmine Issues for ${DATE}" > "$markdown_output" + echo "" >> "$markdown_output" + + jq -r --arg base_url "$REDMINE_API_URL" '.issues[] | "## [\(.subject)](\($base_url)/issues/\(.id))\n- **ID**: \(.id)\n- **Status**: \(.status.name)\n- **Due Date**: \(.due_date)\n\n---"' \ + "$json_file" >> "$markdown_output" + + info "Markdown output written to $markdown_output" + cat "$markdown_output" +} + +# Main Function +main() { + local project_id="$1" + + # Ensure curl is installed + require_curl + + # Fetch issues for the project + fetch_issues "$project_id" +} + +# Argument Parsing +if [[ $# -lt 1 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then + usage + exit 0 +fi + +main "$1" + diff --git a/dsr-publish/.daily-stakeholder-report.yml.swp b/dsr-publish/.daily-stakeholder-report.yml.swp new file mode 100644 index 0000000000000000000000000000000000000000..de386e76b85aa5680c3ea15f071060cc6a46d8db GIT binary patch literal 12288 zcmeI2!H&}~5Qe>6kdW9#@B$_X1c$_15EAr+)LkSFz|w_sAPBk6G>PiOmg9(42=NBX zYasC=oIsr5ahRmtv>;Hqt~!xM9>?SH%;!^-f4o0>^qAj|dJLaSjNN!MOuzrwW1qe; z=Bs(tyx#QG+UK)PLAWjw(WDd)h9FfY#~KEQPsM@E_59e&DP%?`;D%t0^Wjl$LFXli zq;jFH$2zYvkusDKqicxTx9GkTJ!(^^!xwk9%En7KBIj^vuMxIuA`moGIk!V+0*VjgMCxU zM1Tko0U|&IhyW2F0z`la5P>sI!28^5urh^Eo7D7qaM1so}je>bwpBw!O` zFn{RsH1k-)t7B6;1zh1duWx4F+o~@_n)_&4nztorD4_I_GKFxbl5z!RqollYN{pQ> zRVE6Vm%mBO6=w1fwyN`F5>?r)t}KOzfy26mvhv+2P^}L8uzZlBc#LQ*k|pnb<5pJaoi*-q?>kY%gk|{RaPo^*Hgv&fOR+D b=ib$@nD==ruIFp&dcKg?^N`00_Q`$$o)87k literal 0 HcmV?d00001 diff --git a/dsr-publish/create-dsr-pdf.sh b/dsr-publish/create-dsr-pdf.sh index 5045804..4750e44 100644 --- a/dsr-publish/create-dsr-pdf.sh +++ b/dsr-publish/create-dsr-pdf.sh @@ -1,8 +1,8 @@ #!/bin/bash TODAY_DATE=$(date +%m-%d-%Y) -INPUT_FILE="./DSR-$TODAY_DATE.md" -OUTPUT_FILE="./DSR-$TODAY_DATE.pdf" +INPUT_FILE="../dsrtemp/@DailyStakeholderReports/Today/DSR-$TODAY_DATE.md" +OUTPUT_FILE="../dsrtemp/DSR-$TODAY_DATE.pdf" METADATA_FILE="daily-stakeholder-report.yml" TEMPLATE="eisvogel" @@ -12,4 +12,4 @@ $INPUT_FILE \ --metadata-file=$METADATA_FILE \ --from markdown \ --to=pdf \ ---output $OUTPUT_FILE \ No newline at end of file +--output $OUTPUT_FILE diff --git a/dsr-publish/daily-stakeholder-report.yml b/dsr-publish/daily-stakeholder-report.yml new file mode 100644 index 0000000..d79431d --- /dev/null +++ b/dsr-publish/daily-stakeholder-report.yml @@ -0,0 +1,10 @@ +title: Daily Stakeholder Report - \date +titlepage: true +header-left: "\\hspace{1cm}" +header-center: "\\leftmark" +header-right: "Page \\thepage" +footer-left: "Charles N Wyble" +footer-center: "Tenacity. Velocity. Focus." +footer-right: "[Source code](https://git.knownelement.com/reachableceo/DailyStakeholderReport-Pipeline/src/branch/main/dsr-publish/create-dsr-pdf.sh)" +page-background: "D:/tsys/@ReachableCEO/ExternalVendorCode/pandoc-latex-template/examples/page-background/backgrounds/background5.pdf" +titlepage-logo: "D:/tsys/@ReachableCEO/ReachableCEO.png" diff --git a/dsr-publish/publish-dsr.sh b/dsr-publish/publish-dsr.sh index c262b4a..898a4cb 100644 --- a/dsr-publish/publish-dsr.sh +++ b/dsr-publish/publish-dsr.sh @@ -39,6 +39,9 @@ export DISCOURSE_APIKEY="$(bw get password APIKEY-discourse)" post_dsr() { + +TODAY_DATE=$(date +%m-%d-%Y) + echo "Posting DSR..." DISCOURSE_URL="https://community.turnsys.com" # e.g., https://forum.example.com @@ -55,7 +58,7 @@ TITLE="Daily Stakeholder Report - $TODAY_DATE" CONTENT="Please use the link below to download today's stakeholder report." # The file to upload (from the second argument or auto-generated based on date) -FILE_PATH="./DSR-$TODAY_DATE.pdf" +FILE_PATH="../dsrtemp/DSR-$TODAY_DATE.pdf" # Check if the file exists if [ ! -f "$FILE_PATH" ]; then @@ -125,4 +128,4 @@ secrets_manager # - upload PDF to discourse # - attach uploaded PDF to the topic -post_dsr \ No newline at end of file +post_dsr