Make external APIs configurable #1369
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update database | |
on: | |
issue_comment: | |
types: [created] | |
defaults: | |
run: | |
working-directory: backend/api | |
jobs: | |
# The base job checks if comment is the right function and made on a pull request | |
base_check: | |
if: | | |
github.event.issue.pull_request && | |
github.event.comment.body == '/UpdateDatabase' | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
outputs: | |
eyes_id: ${{ fromJson(steps.eyes.outputs.data).id }} | |
steps: | |
# Using the post request directly to be able to remove the reaction later (Need reaction id for this) | |
# This allows the reaction to act as a status for the function. | |
- name: React to comment | |
uses: octokit/[email protected] | |
id: eyes | |
with: | |
route: POST /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions | |
content: "eyes" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Need to curl for the PR state as this does not exist in the github.event payload for issue_comment | |
get_review_state: | |
needs: base_check | |
runs-on: windows-latest | |
outputs: | |
review_approved: ${{ contains(fromJson(steps.get.outputs.data).*.state, 'APPROVED') }} | |
eyes_id: ${{ needs.base_check.outputs.eyes_id }} | |
steps: | |
- uses: octokit/[email protected] | |
id: get | |
with: # Search in PR's for this ID with review approved. | |
# If no results, the PR is not approved | |
route: GET /repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}/reviews | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
if_not_approved_then_stop: | |
needs: get_review_state | |
if: ${{ needs.get_review_state.outputs.review_approved == 'false' }} | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Remove 'eyes' reaction | |
uses: octokit/[email protected] | |
with: | |
route: DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.get_review_state.outputs.eyes_id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: React to comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
comment-id: ${{ github.event.comment.id }} | |
reactions: confused, -1 | |
- name: Add comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
:no_entry: Cannot update database until the Pull Request is approved! :no_entry: | |
database_update_start: | |
needs: get_review_state | |
if: ${{ needs.get_review_state.outputs.review_approved == 'true' }} | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Remove 'eyes' reaction | |
uses: octokit/[email protected] | |
with: | |
route: DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.get_review_state.outputs.eyes_id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: React to comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
comment-id: ${{ github.event.comment.id }} | |
reactions: rocket, +1 | |
- name: Add comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
:eyes: Running migration command... :eyes: | |
run_migrations: | |
needs: database_update_start | |
uses: ./.github/workflows/runMigrations.yml | |
with: | |
PullRequestCheckout: true | |
Environment: Development | |
secrets: | |
ClientId: ${{secrets.CLIENTID}} | |
ClientSecret: ${{secrets.CLIENTSECRET}} | |
database_success: | |
needs: run_migrations | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Add comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
:sparkles: Successfully ran migration command! :sparkles: | |
database_failure: | |
needs: run_migrations | |
if: ${{ failure() }} | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
steps: | |
- name: Add comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
:x: Migration failed, please see action log below for details :x: | |
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |