Skip to content

Commit

Permalink
Handle new scale request issues automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
papauorg committed Jul 9, 2024
1 parent 9063075 commit 4688d6e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/new-scale-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ body:
attributes:
label: Graduation mark settings
description: Anything you want the scale to be different than the default. Keep in mind that this may take longer to get created as it will be manual work to do it.
- type: input
id: template_marker
attributes:
label: Template Marker
value: new-scale-request-template
render: hidden
82 changes: 82 additions & 0 deletions .github/workflows/handle_scale_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Handle new scale issue

on:
issues:
types: [opened, edited]

jobs:
process-issue:
if: contains(github.event.issue.body, 'new-scale-request-template')
runs-on: ubuntu-latest

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

- name: Get Issue ID
id: issue_id
run: echo "::set-output name=id::${{ github.event.issue.number }}"

- name: Parse issue body and extract fields
id: parse_fields
run: |
CONTAINER_FORM=$(grep -oP '(?<=containerForm\n)[^\n]+' issue_body.txt | tr -d '\r')
LENGTH_UNIT=$(grep -oP '(?<=lengthUnit\n)[^\n]+' issue_body.txt | tr -d '\r')
VOLUME_UNIT=$(grep -oP '(?<=volumeUnit\n)[^\n]+' issue_body.txt | tr -d '\r')
DIAMETER=$(grep -oP '(?<=diameter\n)[^\n]+' issue_body.txt | tr -d '\r')
HEIGHT=$(grep -oP '(?<=height\n)[^\n]+' issue_body.txt | tr -d '\r')
MIN_VOLUME=$(grep -oP '(?<=minimumVolume\n)[^\n]+' issue_body.txt | tr -d '\r')
MAX_VOLUME=$(grep -oP '(?<=maximumVolume\n)[^\n]+' issue_body.txt | tr -d '\r')
DESCRIPTION=$(grep -oP '(?<=description\n)[^\n]+' issue_body.txt | tr -d '\r')
FILENAME="${CONTAINER_FORM}_${LENGTH_UNIT}_d${DIAMETER}_h${HEIGHT}_${MIN_VOLUME}-${MAX_VOLUME}${VOLUME_UNIT}_i1"
echo "Form: $CONTAINER_FORM"
echo "LenghtUnit: $LENGTH_UNIT"
echo "VolumeUnit: $VOLUME_UNIT"
echo "Diameter: $DIAMETER"
echo "Height: $HEIGHT"
echo "MinVolume: $MIN_VOLUME"
echo "MaxVolume: $MAX_VOLUME"
echo "Description: $DESCRIPTION"
echo "FileName: $FILENAME"
echo "::set-output name=container_form::$CONTAINER_FORM"
echo "::set-output name=length_unit::$LENGTH_UNIT"
echo "::set-output name=volume_unit::$VOLUME_UNIT"
echo "::set-output name=diameter::$DIAMETER"
echo "::set-output name=height::$HEIGHT"
echo "::set-output name=min_volume::$MIN_VOLUME"
echo "::set-output name=max_volume::$MAX_VOLUME"
echo "::set-output name=description::$DESCRIPTION"
echo "::set-output name=filename::$FILENAME"
- name: Create or override scale file.
run: |
newFile="./scales/definitions/${{ steps.parse_fields.outputs.filename }}.json"
cp -f ./scales/definitions/_newscale.json.template "$newFile"
./scales/definitions/_apply_filename_to_json.sh "$newFile"
- name: Generate scale svg

- name: Configure git
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- name: Create new branch and commit changes
run: |
BRANCH_NAME="feature/scale-request-${{ steps.issue_id.outputs.id }}"
git checkout -b $BRANCH_NAME
git add .
git commit -m "Add/Edit scale for scale request #${{ steps.issue_id.outputs.id }}"
#git push origin $BRANCH_NAME
# - name: Create pull request
# id: create_pr
# uses: peter-evans/create-pull-request@v5
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# head: ${{ github.repository }}:feature/${{ steps.issue_id.outputs.id }}
# base: main
# title: "Scale Request #${{ steps.issue_id.outputs.id }}"
# body: "This PR is to handle the scale request from issue #${{ steps.issue_id.outputs.id }}"
6 changes: 4 additions & 2 deletions scales/definitions/_apply_filename_to_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

set -e

for file in $(find . -iname '*.json' -type f -printf "%f\n"); do
#for file in $(find . -iname '*.json' -type f -printf "%f\n"); do
file=$1

form=$(echo "$file" | cut -d _ -f1)
form=${form##*/}
lengthUnit=$(echo "$file" | cut -d _ -f2)
diameter=$(echo "$file" | cut -d _ -f3)
diameter=${diameter:1}
Expand Down Expand Up @@ -47,4 +49,4 @@ for file in $(find . -iname '*.json' -type f -printf "%f\n"); do
"$file.edited"

mv "$file.edited" "$file" -f
done
#done

0 comments on commit 4688d6e

Please sign in to comment.