Skip to content

Commit

Permalink
Merge pull request #41 from hmcts/DTSPO-18475-Github-Rulesets
Browse files Browse the repository at this point in the history
Fresh PR with changes made switching the test org back to hmcts org. Updated variables to match the hmcts org.
  • Loading branch information
ConnorOKane-Kainos authored Aug 30, 2024
2 parents 7427363 + a0d724f commit 66dd476
Show file tree
Hide file tree
Showing 13 changed files with 598 additions and 127 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/pr-reviewer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI PR Reviewer Pipeline
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
review:
runs-on: ubuntu-latest
env:
X_API_KEY: ${{ secrets.SYSTEM_API_KEY }}
X_API_CONSUMER: ${{ secrets.SYSTEM_CONSUMER_UUID }}
API_HOST: "https://app-gippi-api-s-latest-uksouth.azurewebsites.net/"
WORKING_DIRECTORY: ${{ github.workspace }}/
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Create a diff file
run: |
git diff origin/main...remotes/origin/${{ github.head_ref }} > ${{ env.working_directory }}diff.txt && cat ${{ env.working_directory }}diff.txt
- name: Generate a response
run: |
API_HOST=$(printenv API_HOST)
WORKING_DIRECTORY=$(printenv WORKING_DIRECTORY)
X_API_CONSUMER=$(printenv X_API_CONSUMER)
X_API_KEY=$(printenv X_API_KEY)
DIFF_FILE="diff.txt"
RESPONSE_MD_FILE="response.md"
if [ ! -f "${WORKING_DIRECTORY}${DIFF_FILE}" ]; then
echo "File ${WORKING_DIRECTORY}${DIFF_FILE} not found."
exit 1
fi
file_contents=$(cat "${WORKING_DIRECTORY}${DIFF_FILE}")
json_body=$(jq -n --arg pt "pullrequest-review" --arg p "$file_contents" '{prompt_type: $pt, prompt: $p}')
response=$(curl -s -i -X POST "${API_HOST}/predefined" \
-H "Content-Type: application/json" \
-H "X-API-CONSUMER: ${X_API_CONSUMER}" \
-H "X-API-KEY: ${X_API_KEY}" \
-d "$json_body")
echo "Response: $response"
response_code=$(echo "$response" | awk -F' ' '/HTTP\/1.1/{print $2}' | head -n 1)
if [ "$response_code" -eq 200 ]; then
echo "File contents sent successfully."
# Remove headers
response_body=$(echo "$response" | tail -n +2)
# Remove more headers
response_body=$(echo "$response_body" | sed '/^date: /Id' | sed '/^server: /Id' | sed '/^content-length: /Id' | sed '/^content-type: /Id')
# remove trailing and leading quotes
response_body=$(echo "$response_body" | sed 's/^"\(.*\)"$/\1/')
# remove the initial markdown code block ident if it exists
response_body=$(echo "$response_body" | sed 's/```markdown//')
# remove the last code block ident
response_body=$(echo "$response_body" | sed 's/```//')
# Write to file
echo -e "$response_body" > "${WORKING_DIRECTORY}${RESPONSE_MD_FILE}"
else
echo "Error sending file contents: $response_code"
echo -e "Request to AEP failed to process" > "${WORKING_DIRECTORY}${RESPONSE_MD_FILE}"
fi
if [ $? -eq 0 ]; then
echo "Response saved as response.md"
else
echo "Error writing to file in ${WORKING_DIRECTORY}."
exit 1
fi
- name: Get the response as a variable
id: get_response
run: |
{
echo 'response<<EOF'
cat ${WORKING_DIRECTORY}response.md
echo EOF
} >> "$GITHUB_ENV"
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.response
})
101 changes: 101 additions & 0 deletions .github/workflows/pr-summary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: CI PR Summary Pipeline
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
review:
runs-on: ubuntu-latest
env:
X_API_KEY: ${{ secrets.SYSTEM_API_KEY }}
X_API_CONSUMER: ${{ secrets.SYSTEM_CONSUMER_UUID }}
API_HOST: "https://app-gippi-api-s-latest-uksouth.azurewebsites.net/"
WORKING_DIRECTORY: ${{ github.workspace }}/
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Create a diff file
run: |
git diff origin/main...remotes/origin/${{ github.head_ref }} > ${{ env.working_directory }}diff.txt && cat ${{ env.working_directory }}diff.txt
- name: Generate a response
run: |
API_HOST=$(printenv API_HOST)
WORKING_DIRECTORY=$(printenv WORKING_DIRECTORY)
X_API_CONSUMER=$(printenv X_API_CONSUMER)
X_API_KEY=$(printenv X_API_KEY)
DIFF_FILE="diff.txt"
RESPONSE_MD_FILE="response.md"
if [ ! -f "${WORKING_DIRECTORY}${DIFF_FILE}" ]; then
echo "File ${WORKING_DIRECTORY}${DIFF_FILE} not found."
exit 1
fi
file_contents=$(cat "${WORKING_DIRECTORY}${DIFF_FILE}")
json_body=$(jq -n --arg pt "pullrequest-summary-perfile" --arg p "$file_contents" '{prompt_type: $pt, prompt: $p}')
response=$(curl -s -i -X POST "${API_HOST}/predefined" \
-H "Content-Type: application/json" \
-H "X-API-CONSUMER: ${X_API_CONSUMER}" \
-H "X-API-KEY: ${X_API_KEY}" \
-d "$json_body")
echo "Response: $response"
response_code=$(echo "$response" | awk -F' ' '/HTTP\/1.1/{print $2}' | head -n 1)
if [ "$response_code" -eq 200 ]; then
echo "File contents sent successfully."
# Remove headers
response_body=$(echo "$response" | tail -n +2)
# Remove more headers
response_body=$(echo "$response_body" | sed '/^date: /Id' | sed '/^server: /Id' | sed '/^content-length: /Id' | sed '/^content-type: /Id')
# remove trailing and leading quotes
response_body=$(echo "$response_body" | sed 's/^"\(.*\)"$/\1/')
# remove the initial markdown code block ident if it exists
response_body=$(echo "$response_body" | sed 's/```markdown//')
# remove the last code block ident
response_body=$(echo "$response_body" | sed 's/```//')
# Write to file
echo -e "$response_body" > "${WORKING_DIRECTORY}${RESPONSE_MD_FILE}"
else
echo "Error sending file contents: $response_code"
echo -e "Request to AEP failed to process" > "${WORKING_DIRECTORY}${RESPONSE_MD_FILE}"
fi
if [ $? -eq 0 ]; then
echo "Response saved as response.md"
else
echo "Error writing to file in ${WORKING_DIRECTORY}."
exit 1
fi
- name: Get the response as a variable
id: get_response
run: |
{
echo 'response<<EOF'
cat ${WORKING_DIRECTORY}response.md
echo EOF
} >> "$GITHUB_ENV"
- uses: actions/github-script@v6
with:
script: |
const prBody = context.payload.pull_request.body || '';
const updatedBody = prBody.includes('## 🤖AEP PR SUMMARY🤖')
? prBody.replace(/## 🤖AEP PR SUMMARY🤖[\s\S]*/, '') + '\n\n## 🤖AEP PR SUMMARY🤖\n\n' + process.env.response
: prBody + '\n\n## 🤖AEP PR SUMMARY🤖\n\n' + process.env.response;
github.rest.pulls.update({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: updatedBody
})
4 changes: 3 additions & 1 deletion .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ jobs:
run: terraform plan -var="oauth_token=${{ secrets.OAUTH_TOKEN }}"

- name: Terraform Apply
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
working-directory: components
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.DCD_CFT_SANDBOX_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
OAUTH_TOKEN: ${{ secrets.OAUTH_TOKEN }}
run: terraform apply -var="oauth_token=${{ secrets.OAUTH_TOKEN }}" -auto-approve



33 changes: 28 additions & 5 deletions .github/workflows/update-repos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

jobs:
update-file:
update-files:
runs-on: ubuntu-latest

steps:
Expand All @@ -23,15 +23,38 @@ jobs:
python -m pip install --upgrade pip
pip install pyyaml requests
- name: Run update script
- name: Run set_org_custom_properties script
env:
OAUTH_TOKEN: ${{ secrets.OAUTH_TOKEN }}
run: python custom-properties/set_org_custom_properties.py

- name: Run update-repo-list script
run: python scripts/update-repo-list.py

- name: Run update-readme script
run: python scripts/update-readme.py

- name: Install jq
run: sudo apt-get install jq -y

- name: List Repositories
run: |
echo "Listing Repositories"
for repo in $(jq -r '.[]' < ./production-repos.json); do
echo "Listing repository: $repo"
curl -H "Authorization: token ${{ secrets.OAUTH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/hmcts/$repo
done
shell: bash
continue-on-error: true

- name: Commit and push changes
run: |
git config --global user.name 'hmcts-platform-operations'
git config --global user.email 'github-platform-operations@HMCTS.NET'
git add production-repos.json
git commit -m 'Update repository list'
git add production-repos.json ReadMe.md
git commit -m 'Update repository list and readme'
git push
env:
GITHUB_TOKEN: ${{ secrets.OAUTH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.OAUTH_TOKEN }}
Loading

0 comments on commit 66dd476

Please sign in to comment.