name: Notify Super Repo of Submodule Changes

on:
  push:
    branches:
      - main
    paths:
      - '**'  # Detect any changes

jobs:
  notify-super-repo:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up GitHub CLI
        uses: cli/gh-action@v2

      - name: Create Issue in Super Repo
        env:
          GH_TOKEN: ${{ secrets.TESTS_REPOS_ACCESS_PAT }}
        run: |
          SUPER_REPOS=("dataiku/dss-plugin-document-question-answering" "dataiku/dss-agents-portal")
          ISSUE_TITLE="Submodule Updated: $GITHUB_REPOSITORY"
          ISSUE_BODY="🚀 A new update was pushed to submodule: [$GITHUB_REPOSITORY](https://github.com/$GITHUB_REPOSITORY/commit/${{ github.sha }})\n\n🔄 Please pull the latest submodule changes in the super repo."

          for SUPER_REPO in "${SUPER_REPOS[@]}"; do
            echo "🔔 Creating issue in $SUPER_REPO..."
            gh issue create --repo "$SUPER_REPO" --title "$ISSUE_TITLE" --body "$ISSUE_BODY"
          done