# smart-assignment

Intelligently assigns JIRA issues based on team roles, expertise, workload, and historical patterns.

## Purpose

Automate issue assignment using:

- Team member roles and specializations
- Current workload and capacity
- Code ownership patterns
- Historical assignment success
- Issue type and complexity

## Assignment Logic

### 1. Role-Based Assignment

```yaml
assignment_rules:
  by_issue_type:
    Bug:
      primary_role: qa_engineer
      secondary_role: developer
      logic: |
        1. Check if QA engineer reported the bug → assign to developer
        2. Check if affects specific code area → assign to code owner
        3. Otherwise → assign to available QA engineer

    Story:
      primary_role: developer
      logic: |
        1. Check story components → match to specialization
        2. Check epic owner → prefer same developer
        3. Balance workload across team

    Task:
      primary_role: any
      logic: |
        1. Technical tasks → developers
        2. Testing tasks → QA
        3. Infrastructure → DevOps
        4. Documentation → Tech Lead or Senior Dev

    "Technical Debt":
      primary_role: senior_developer
      secondary_role: tech_lead
      logic: "Assign to senior team members familiar with the codebase"
```

### 2. Specialization Matching

[[LLM: Match issue to team member expertise:

1. Extract keywords from issue title/description
2. Match against team member specializations:
   - Frontend: UI, React, CSS, design
   - Backend: API, database, server, integration
   - Mobile: iOS, Android, React Native
   - DevOps: deployment, CI/CD, infrastructure
3. Score matches and rank candidates
   ]]

### 3. Code Ownership Analysis

```javascript
// Pseudo-code for ownership detection
function findCodeOwner(issueKey) {
  // Get affected files from issue description or linked PRs
  const affectedFiles = extractFilePaths(issue.description);

  // Find who most frequently commits to these areas
  const ownership = {};
  for (const file of affectedFiles) {
    const authors = getGitAuthors(file, last90Days);
    authors.forEach((author) => {
      ownership[author.email] =
        (ownership[author.email] || 0) + author.commitCount;
    });
  }

  // Return developer with highest ownership score
  return sortByOwnership(ownership)[0];
}
```

### 4. Workload Balancing

```yaml
workload_factors:
  current_issues:
    weight: 0.4
    calculation: "Count of open issues assigned"

  story_points:
    weight: 0.3
    calculation: "Sum of story points in current sprint"

  recent_completed:
    weight: 0.2
    calculation: "Issues completed in last 2 weeks"

  capacity:
    weight: 0.1
    calculation: "Team member capacity percentage"

# Example scoring
team_member_load:
  "john.doe":
    current_issues: 5
    story_points: 13
    recent_completed: 8
    capacity: 100%
    load_score: 0.72 # High load

  "jane.smith":
    current_issues: 2
    story_points: 5
    recent_completed: 12
    capacity: 80%
    load_score: 0.35 # Low load - good candidate
```

### 5. Historical Success Patterns

[[LLM: Analyze past assignments:

1. Track resolution time by assignee and issue type
2. Identify successful pairings (type + assignee)
3. Learn from reassignments (initial vs final assignee)
4. Build success probability matrix
   ]]

## Smart Assignment Workflow

```mermaid
graph TD
    A[New Issue Created] --> B{Has Assignee?}
    B -->|No| C[Start Smart Assignment]
    B -->|Yes| D[Validate Assignment]

    C --> E[Analyze Issue Type]
    E --> F[Find Matching Roles]
    F --> G[Filter by Specialization]
    G --> H[Check Code Ownership]
    H --> I[Calculate Workload]
    I --> J[Score Candidates]
    J --> K[Select Best Match]

    D --> L{Is Optimal?}
    L -->|No| M[Suggest Better Assignee]
    L -->|Yes| N[Keep Current]

    K --> O[Assign Issue]
    M --> O
    N --> O
```

## Usage Examples

### Auto-Assignment on Issue Creation

```markdown
"New bug reported: Login fails on mobile devices"

[[Use smart-assignment to:

1. Identify as Bug type → QA primary
2. Detect "mobile" keyword → Mobile specialization
3. Find QA with mobile experience
4. Check workload → Jane (QA, mobile) has capacity
5. Auto-assign to Jane
   ]]

Assignment: jane.smith@company.com (QA Engineer, Mobile Specialist)
Reason: Bug type, mobile expertise, available capacity
```

### Bulk Assignment

```markdown
"jira assign unassigned --smart"

Processing 15 unassigned issues...

- PROJ-123: Bug → jane.smith (QA, low workload)
- PROJ-124: Story → john.doe (Backend, API expertise)
- PROJ-125: Task → mike.wilson (DevOps, deployment task)
  ...

Assigned 15 issues based on smart assignment rules.
```

### Assignment Validation

```markdown
"jira validate assignments"

Checking current assignments...

⚠️ Suboptimal assignments found:

- PROJ-130: Frontend story assigned to backend developer
  Suggestion: Reassign to sarah.jones (Frontend specialist)
- PROJ-131: High priority bug assigned to overloaded developer
  Current: john.doe (load: 85%)
  Suggestion: jane.smith (load: 40%)
```

## Configuration

```yaml
# In jira-expansion-config.yaml
assignment:
  enabled: true

  rules:
    respect_manual: true # Don't override manual assignments
    auto_assign_new: true # Auto-assign new issues
    rebalance_sprint: false # Rebalance at sprint start

  preferences:
    prefer_code_owner: true
    max_concurrent_issues: 10
    balance_threshold: 0.7 # Rebalance if load > 70%

  notifications:
    notify_assignee: true
    notify_reporter: false
    slack_channel: "#dev-team"
```

## Integration with Team Discovery

The smart assignment system relies on data from team-role-discovery:

```yaml
# Team member profile used for assignment
team_member:
  jira_username: "john.doe@company.com"
  primary_role: "developer"
  specializations: ["backend", "api", "database"]
  code_ownership: ["src/api/**", "src/db/**"]
  current_load: 0.65
  capacity: 100%
  avg_resolution_time:
    Bug: "2.5 days"
    Story: "3.2 days"
    Task: "1.8 days"
```

## Reporting

Generate assignment effectiveness reports:

```markdown
## Assignment Effectiveness Report

### Assignment Distribution (Last 30 days)

- Manual assignments: 45%
- Smart assignments: 55%

### Smart Assignment Performance

- Kept without reassignment: 89%
- Average resolution time: -18% vs manual
- Team satisfaction: 4.2/5

### Load Distribution

- Most loaded: john.doe (78%)
- Least loaded: jane.smith (42%)
- Team average: 61%

### Recommendations

1. Consider adding another QA engineer (high QA workload)
2. Rotate frontend tasks (single point of dependency)
3. Enable auto-rebalancing for better distribution
```
