juno-code 1.0.36 → 1.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,269 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # slack_fetch.sh
4
+ #
5
+ # Purpose: Fetch Slack messages and create kanban tasks
6
+ #
7
+ # This script activates the Python virtual environment and runs the
8
+ # slack_fetch.py script to monitor a Slack channel and create kanban
9
+ # tasks from new messages.
10
+ #
11
+ # Usage:
12
+ # ./.juno_task/scripts/slack_fetch.sh --channel bug-reports
13
+ # ./.juno_task/scripts/slack_fetch.sh --channel feature-requests --continuous
14
+ # ./.juno_task/scripts/slack_fetch.sh --channel general --dry-run --verbose
15
+ #
16
+ # Environment Variables:
17
+ # SLACK_BOT_TOKEN Slack bot token (required, starts with xoxb-)
18
+ # SLACK_CHANNEL Default channel to monitor
19
+ # CHECK_INTERVAL_SECONDS Polling interval in seconds (default: 60)
20
+ # JUNO_DEBUG=true Show debug messages
21
+ # JUNO_VERBOSE=true Show informational messages
22
+ #
23
+ # Created by: juno-code init command
24
+ # Date: Auto-generated during project initialization
25
+
26
+ set -euo pipefail
27
+
28
+ # Debug output
29
+ if [ "${JUNO_DEBUG:-false}" = "true" ]; then
30
+ echo "[DEBUG] slack_fetch.sh is being executed from: $(pwd)" >&2
31
+ fi
32
+
33
+ # Color output
34
+ RED='\033[0;31m'
35
+ GREEN='\033[0;32m'
36
+ YELLOW='\033[1;33m'
37
+ BLUE='\033[0;34m'
38
+ NC='\033[0m'
39
+
40
+ # Configuration
41
+ VENV_DIR=".venv_juno"
42
+ SCRIPTS_DIR=".juno_task/scripts"
43
+ INSTALL_SCRIPT="${SCRIPTS_DIR}/install_requirements.sh"
44
+ SLACK_FETCH_SCRIPT="${SCRIPTS_DIR}/slack_fetch.py"
45
+
46
+ # Logging functions
47
+ log_info() {
48
+ if [ "${JUNO_VERBOSE:-false}" = "true" ]; then
49
+ echo -e "${BLUE}[SLACK_FETCH]${NC} $1"
50
+ fi
51
+ }
52
+
53
+ log_success() {
54
+ if [ "${JUNO_VERBOSE:-false}" = "true" ]; then
55
+ echo -e "${GREEN}[SLACK_FETCH]${NC} $1"
56
+ fi
57
+ }
58
+
59
+ log_warning() {
60
+ if [ "${JUNO_VERBOSE:-false}" = "true" ]; then
61
+ echo -e "${YELLOW}[SLACK_FETCH]${NC} $1"
62
+ fi
63
+ }
64
+
65
+ log_error() {
66
+ echo -e "${RED}[SLACK_FETCH]${NC} $1" >&2
67
+ }
68
+
69
+ # Check if we're in .venv_juno
70
+ is_in_venv_juno() {
71
+ if [ -n "${VIRTUAL_ENV:-}" ]; then
72
+ if [[ "${VIRTUAL_ENV:-}" == *"/.venv_juno" ]] || [[ "${VIRTUAL_ENV:-}" == *".venv_juno"* ]]; then
73
+ return 0
74
+ fi
75
+ if [ "$(basename "${VIRTUAL_ENV:-}")" = ".venv_juno" ]; then
76
+ return 0
77
+ fi
78
+ fi
79
+ return 1
80
+ }
81
+
82
+ # Activate virtual environment
83
+ activate_venv() {
84
+ local venv_path="$1"
85
+
86
+ if [ ! -d "$venv_path" ]; then
87
+ log_error "Virtual environment not found: $venv_path"
88
+ return 1
89
+ fi
90
+
91
+ if [ -f "$venv_path/bin/activate" ]; then
92
+ # shellcheck disable=SC1091
93
+ source "$venv_path/bin/activate"
94
+ log_success "Activated virtual environment: $venv_path"
95
+ return 0
96
+ else
97
+ log_error "Activation script not found: $venv_path/bin/activate"
98
+ return 1
99
+ fi
100
+ }
101
+
102
+ # Ensure Python environment is ready
103
+ ensure_python_environment() {
104
+ log_info "Checking Python environment..."
105
+
106
+ if is_in_venv_juno; then
107
+ log_success "Already inside .venv_juno virtual environment"
108
+ return 0
109
+ fi
110
+
111
+ if [ -d "$VENV_DIR" ]; then
112
+ log_info "Found existing virtual environment: $VENV_DIR"
113
+ if activate_venv "$VENV_DIR"; then
114
+ return 0
115
+ else
116
+ log_error "Failed to activate virtual environment"
117
+ return 1
118
+ fi
119
+ fi
120
+
121
+ log_warning "Virtual environment not found: $VENV_DIR"
122
+ log_info "Running install_requirements.sh to create virtual environment..."
123
+
124
+ if [ ! -f "$INSTALL_SCRIPT" ]; then
125
+ log_error "Install script not found: $INSTALL_SCRIPT"
126
+ log_error "Please run 'juno-code init' to initialize the project"
127
+ return 1
128
+ fi
129
+
130
+ chmod +x "$INSTALL_SCRIPT"
131
+
132
+ if bash "$INSTALL_SCRIPT"; then
133
+ log_success "Python environment setup completed successfully"
134
+ if [ -d "$VENV_DIR" ]; then
135
+ activate_venv "$VENV_DIR"
136
+ fi
137
+ return 0
138
+ else
139
+ log_error "Failed to run install_requirements.sh"
140
+ return 1
141
+ fi
142
+ }
143
+
144
+ # Check for required Slack dependencies
145
+ check_slack_deps() {
146
+ log_info "Checking Slack SDK dependencies..."
147
+
148
+ if python3 -c "import slack_sdk; import dotenv" 2>/dev/null; then
149
+ log_success "Slack SDK dependencies available"
150
+ return 0
151
+ fi
152
+
153
+ log_warning "Slack SDK not installed. Installing..."
154
+ pip install slack_sdk python-dotenv >/dev/null 2>&1 || {
155
+ log_error "Failed to install Slack SDK dependencies"
156
+ log_error "Please run: pip install slack_sdk python-dotenv"
157
+ return 1
158
+ }
159
+
160
+ log_success "Slack SDK installed successfully"
161
+ return 0
162
+ }
163
+
164
+ # Get script directory and project root
165
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
166
+ PROJECT_ROOT="$( cd "$SCRIPT_DIR/../.." && pwd )"
167
+
168
+ cd "$PROJECT_ROOT"
169
+
170
+ # Show help for Slack environment setup
171
+ show_env_help() {
172
+ echo ""
173
+ echo "========================================================================"
174
+ echo "Slack Integration - Environment Setup"
175
+ echo "========================================================================"
176
+ echo ""
177
+ echo "Required Environment Variables:"
178
+ echo " SLACK_BOT_TOKEN Your Slack bot token (starts with xoxb-)"
179
+ echo ""
180
+ echo "Optional Environment Variables:"
181
+ echo " SLACK_CHANNEL Default channel to monitor"
182
+ echo " CHECK_INTERVAL_SECONDS Polling interval (default: 60)"
183
+ echo " LOG_LEVEL DEBUG, INFO, WARNING, ERROR (default: INFO)"
184
+ echo ""
185
+ echo "Configuration Methods:"
186
+ echo " 1. Environment variables:"
187
+ echo " export SLACK_BOT_TOKEN=xoxb-your-token-here"
188
+ echo " export SLACK_CHANNEL=bug-reports"
189
+ echo ""
190
+ echo " 2. .env file (in project root):"
191
+ echo " SLACK_BOT_TOKEN=xoxb-your-token-here"
192
+ echo " SLACK_CHANNEL=bug-reports"
193
+ echo ""
194
+ echo " 3. .juno_task/.env file (project-specific):"
195
+ echo " SLACK_BOT_TOKEN=xoxb-your-token-here"
196
+ echo " SLACK_CHANNEL=bug-reports"
197
+ echo ""
198
+ echo "To generate a Slack bot token:"
199
+ echo " 1. Go to https://api.slack.com/apps and create a new app"
200
+ echo " 2. Under 'OAuth & Permissions', add these scopes:"
201
+ echo " - channels:history, channels:read (public channels)"
202
+ echo " - groups:history, groups:read (private channels)"
203
+ echo " - users:read (user info)"
204
+ echo " - chat:write (for slack_respond.py)"
205
+ echo " 3. Install the app to your workspace"
206
+ echo " 4. Copy the 'Bot User OAuth Token' (starts with xoxb-)"
207
+ echo ""
208
+ echo " Full tutorial: https://api.slack.com/tutorials/tracks/getting-a-token"
209
+ echo ""
210
+ echo "========================================================================"
211
+ echo ""
212
+ }
213
+
214
+ # Main function
215
+ main() {
216
+ log_info "=== Slack Fetch Wrapper ==="
217
+
218
+ # Ensure Python environment
219
+ if ! ensure_python_environment; then
220
+ log_error "Failed to setup Python environment"
221
+ exit 1
222
+ fi
223
+
224
+ # Check Slack dependencies
225
+ if ! check_slack_deps; then
226
+ exit 1
227
+ fi
228
+
229
+ # Load .env file if it exists
230
+ if [ -f ".env" ]; then
231
+ # shellcheck disable=SC1091
232
+ set -a
233
+ source .env
234
+ set +a
235
+ log_success "Loaded environment from .env"
236
+ fi
237
+
238
+ # Also check .juno_task/.env
239
+ if [ -f ".juno_task/.env" ]; then
240
+ # shellcheck disable=SC1091
241
+ set -a
242
+ source .juno_task/.env
243
+ set +a
244
+ log_success "Loaded environment from .juno_task/.env"
245
+ fi
246
+
247
+ # Check for SLACK_BOT_TOKEN
248
+ if [ -z "${SLACK_BOT_TOKEN:-}" ]; then
249
+ log_error "SLACK_BOT_TOKEN not set!"
250
+ show_env_help
251
+ exit 1
252
+ fi
253
+
254
+ # Validate token format
255
+ if [[ ! "${SLACK_BOT_TOKEN:-}" =~ ^xoxb- ]]; then
256
+ log_warning "SLACK_BOT_TOKEN does not start with 'xoxb-' - this may be an invalid bot token"
257
+ log_info "Bot tokens from Slack should start with 'xoxb-'"
258
+ log_info "To generate a valid token, visit: https://api.slack.com/tutorials/tracks/getting-a-token"
259
+ fi
260
+
261
+ log_success "Python environment ready!"
262
+ log_success "Slack token configured"
263
+
264
+ # Execute slack_fetch.py
265
+ log_info "Executing slack_fetch.py: $*"
266
+ exec python3 "$SLACK_FETCH_SCRIPT" "$@"
267
+ }
268
+
269
+ main "$@"