#!/bin/bash # issue-assign.sh - Assign issues on Gitea or GitHub # Usage: issue-assign.sh -i ISSUE_NUMBER [-a assignee] [-l labels] [-m milestone] set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/detect-platform.sh" # Default values ISSUE="" ASSIGNEE="" LABELS="" MILESTONE="" REMOVE_ASSIGNEE=false usage() { cat <&2 usage ;; esac done if [[ -z "$ISSUE" ]]; then echo "Error: Issue number is required (-i)" >&2 usage fi PLATFORM=$(detect_platform) case "$PLATFORM" in github) if [[ -n "$ASSIGNEE" ]]; then gh issue edit "$ISSUE" --add-assignee "$ASSIGNEE" fi if [[ "$REMOVE_ASSIGNEE" == true ]]; then # Get current assignees and remove them CURRENT=$(gh issue view "$ISSUE" --json assignees -q '.assignees[].login' 2>/dev/null | tr '\n' ',') if [[ -n "$CURRENT" ]]; then gh issue edit "$ISSUE" --remove-assignee "${CURRENT%,}" fi fi if [[ -n "$LABELS" ]]; then gh issue edit "$ISSUE" --add-label "$LABELS" fi if [[ -n "$MILESTONE" ]]; then gh issue edit "$ISSUE" --milestone "$MILESTONE" fi echo "Issue #$ISSUE updated successfully" ;; gitea) # tea issue edit syntax CMD="tea issue edit $ISSUE" NEEDS_EDIT=false if [[ -n "$ASSIGNEE" ]]; then # tea uses --assignees flag CMD="$CMD --assignees \"$ASSIGNEE\"" NEEDS_EDIT=true fi if [[ -n "$LABELS" ]]; then # tea uses --labels flag (replaces existing) CMD="$CMD --labels \"$LABELS\"" NEEDS_EDIT=true fi if [[ -n "$MILESTONE" ]]; then MILESTONE_ID=$(tea milestones list 2>/dev/null | grep -E "^\s*[0-9]+" | grep "$MILESTONE" | awk '{print $1}' | head -1) if [[ -n "$MILESTONE_ID" ]]; then CMD="$CMD --milestone $MILESTONE_ID" NEEDS_EDIT=true else echo "Warning: Could not find milestone '$MILESTONE'" >&2 fi fi if [[ "$NEEDS_EDIT" == true ]]; then eval "$CMD" echo "Issue #$ISSUE updated successfully" else echo "No changes specified" fi ;; *) echo "Error: Could not detect git platform" >&2 exit 1 ;; esac