# Agent Profile: Software Catalog Automation Agent

**Purpose:**  
Automates the creation and maintenance of `software-catalog.yaml` files and ensures Jenkinsfiles have the correct "Publish Software Catalog Definition" stage for multiple repositories.

---

## Prompt Configuration & Workflow

### YAML File Naming
- The YAML file is named `software-catalog.yaml`.
- Skip repos that already have a `software-catalog.yaml` file, but ensure the Jenkinsfile is updated if needed.
- **Sample yaml file:**

  ```yaml
  apiVersion: v3
  kind: service
  metadata:
    name: ows-moneyhub
    description: Financial data aggregation and management service for The Orchard
    owner: customer-accounting
    tags:
      - public:false
  spec:
    type: web
  ```

### Name Extraction
- The `name` field in the YAML is set based on the "GitHub Repository Ownership.csv" file, mapping the Repo column.

### Owner Extraction
- The `owner` field in the YAML is set based on the "GitHub Repository Ownership.csv" file, mapping the Repo to its respective Owner. If an update is requested, the agent will set the owner to the specified value.

### Description
- The `description` field is filled out to summarize what the code does, using repo descriptions or readme if possible.

### Jenkinsfile Stage
- The agent ensures the Jenkinsfile has:
  - The `Publish Software Catalog Definition` step wrapped inside the `Deploy to Prod` stage, immediately after the prod deployment step. The publish step should be a direct step (not inside a `script` block):

  ```groovy
  stage('Deploy to Prod') {
    when {
      allOf {
        branch 'master'
        expression { params.DEPLOY_TO_PROD }
        expression { !params.RUN_E2E_TESTS_ONLY }
      }
    }
    steps {
      fargateDeploy environment: 'prod', awsRegions: AWS_REGIONS, gitCommit: env.GIT_COMMIT, serviceName: GITHUB_REPOSITORY,
        ecrRegistryAccountId: ECR_ACCOUNT_ID, awsDeploymentTargetAccountId: PROD_ACCOUNT_ID, awsDeploymentRoleName: PROD_DEPLOYMENT_ROLE
      datadogSoftwareCatalogPublish()
    }
  }
  ```
  - The `Validate Software Catalog Definition` stage immediately after `Compliance Checks`:

  ```groovy
  stage('Validate Software Catalog Definition') {
    steps {
      datadogSoftwareCatalogValidate()
    }
  }
  ```
  - If these steps already exist, no changes are made to the Jenkinsfile.

### Branching & PRs
- All changes are made in a branch named `add-software-catalog-yaml`.
- Pull requests are created for each repo, and the agent ensures all changes are squashed into a single commit before merge.

### Supported Repos
- Read the list of repos from a provided CSV file `GitHub Repository Ownership.csv`.
- Open a PR for only ten repos at a time to avoid overwhelming reviewers.
- After opening a PR, automatically update the CSV file to set the `Copilot Pull request created` column for that repo to the PR number (e.g., `760`). Make sure update the record in place in csv. Don't create a new row
- Skip opening PRs for repos that already have an open PR for this change. Use `GitHub Repository Ownership.csv` to track this by checking the `Copilot Pull request created` column.

---

## How to Use
1. Provide the repo names and any specific requirements (e.g., public/private, owner, description).
2. The agent will:
   - Extract CODEOWNERS and repo context.
   - Generate or update the YAML file.
   - Update the Jenkinsfile if needed.
   - Create a branch and open a PR.
   - Ensure all changes are squashed into one commit.
