-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathopen-issue
More file actions
executable file
·66 lines (57 loc) · 1.9 KB
/
open-issue
File metadata and controls
executable file
·66 lines (57 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
#ddev-generated
#annertech-ddev
## Description: Quickly open the current issue you are working on
## Usage: open-issue
## Example: "ddev open-issue"
DOMAIN="${TEAMWORK_DOMAIN}"
if [[ -z "$DOMAIN" ]]; then
echo "Error: TEAMWORK_DOMAIN environment variable must be set."
exit 1
fi
# Get the name of the active Git branch
branch_name=$(git rev-parse --abbrev-ref HEAD)
# If no task ID in current branch, fall back to the previously checked-out branch
if [[ ! $branch_name =~ T-([0-9]+) ]]; then
prev_branch=$(git rev-parse --abbrev-ref @{-1} 2>/dev/null)
if [[ -n "$prev_branch" && "$prev_branch" != "@{-1}" && $prev_branch =~ T-([0-9]+) ]]; then
task_id_prev="${BASH_REMATCH[1]}"
echo "No task ID in current branch. Found T-${task_id_prev} in previous branch: $prev_branch"
read -p "Continue with T-${task_id_prev}? (Y/n): " confirm
confirm=${confirm:-Y}
if [[ ! "$confirm" =~ ^[Nn] ]]; then
branch_name="$prev_branch"
fi
fi
fi
# Extract the task ID using regex
if [[ $branch_name =~ T-([0-9]+) ]]; then
task_id="${BASH_REMATCH[1]}"
result="https://${DOMAIN}/app/tasks/$task_id"
# Copy to clipboard based on OS
if command -v xclip &> /dev/null; then
echo "$result" | xclip -selection clipboard
echo "Copied to clipboard: $result"
elif command -v pbcopy &> /dev/null; then
echo "$result" | pbcopy
echo "Copied to clipboard: $result"
else
echo "Clipboard command not found. Please install xclip (Linux) or use pbcopy (macOS)."
# Display the result for manual copying
printf "$result"
printf "\n\n"
fi
case $OSTYPE in
linux-gnu)
xdg-open ${result}
;;
"darwin"*)
open ${result}
;;
"win*"* | "msys"*)
start ${result}
;;
esac
else
echo "No task ID found in the branch name."
fi