name: Shippie 🚢
trigger:
  - main
pr:
  - main

# Important: shippie needs additional Git history available for affected to function correctly. 
# Make sure Shallow fetching is disabled in your pipeline settings UI. 
# For more info, check out this article from Microsoft https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-checkout?view=azure-pipelines#shallow-fetch.
variables:
  TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
  BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD)

pool:
  vmImage: ubuntu-latest

stages:
  - stage: Shippie
    jobs:
      - job: shippie_review
        displayName: Shippie
        workspace:
          clean: all
        steps:
          - script: |
              npm install shippie
            displayName: "Install shippie"  
          
          - script: |
              npx shippie review --platform=azdev
            env:
              API_TOKEN: $(API_TOKEN)
              OPENAI_API_KEY: $(OPENAI_API_KEY)
              BASE_SHA: $(BASE_SHA)
            workingDirectory: $(Build.SourcesDirectory)
            displayName: "Run shippie review"
