# Using `jl-automation-common-modules` in an Automation Repo

> For publishing a new version, see [PUBLISHING.md](PUBLISHING.md).

---

## Step 1 — Add to `requirements.txt`

**Option A — Install from PyPI (recommended):**

```txt
jl-automation-common-modules==1.0.1
```

**Option B — Install from Git (internal / no PyPI access):**

```txt
jl-automation-common-modules @ git+https://JobLogic@dev.azure.com/JobLogic/JobLogic%20Automations/_git/joblogic-automation-modules@v1.0.1
```

**Always pin to a specific version** — never use `@main` or an unpinned version in production.

---

## Step 2 — Install

```bash
pip install -r requirements.txt
```

---

## Step 3 — Use in Your Automation

```python
from joblogic_automation_modules import AutomationManager, ExecutionResult
from joblogic_automation_modules import slack_notification, teams_notification

class MyAutomation(AutomationManager):

    @slack_notification()
    @teams_notification()
    async def start_processing(self, *args, **kwargs) -> ExecutionResult:
        # Available managers (all lazy-loaded):
        # self.db          → SqlManager
        # self.api         → MainSubSysApiManager
        # self.audit       → AuditManager
        # self.common      → CommonManager
        # self.sharepoint  → SharePointManager
        # self.config      → Configurations

        data = await self.common.get_reliable_report_data(report_id=123)

        return ExecutionResult(
            execution_time=await self.common.get_last_exec_time(),
            read_count=len(data),
            create_count=0,
            update_count=0,
            failure_count=0,
        )
```

---

## Step 4 — Pipeline Setup

Azure Pipelines can access other repos in the same organisation automatically. Add a `checkout` step for the modules repo, then install as normal:

```yaml
resources:
  repositories:
    - repository: automation_modules
      type: git
      name: 'JobLogic Automations/jl-automation-common-modules'
      ref: refs/tags/v1.0.1

steps:
  - checkout: self
  - checkout: automation_modules

  - task: UsePythonVersion@0
    inputs:
      versionSpec: '3.11'

  - script: pip install -r requirements.txt
    displayName: 'Install dependencies'
```

> **Note:** If the pipeline build agent cannot reach Azure DevOps Git over HTTPS, grant the pipeline access under **Project Settings → Repos → Security**.
