Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(github): add section to parse english recipes #209

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions .github/workflows/issue2pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,153 @@ jobs:
body: |
:robot: Jeg lagde akkurat en PR for å legge til ${{ fromJson(env.PARSED).name }} på vegne av [@${{ github.event.issue.user.login }}](${{ github.event.issue.user.html_url }}).

Resolves #${{ github.event.issue.number }}
labels: |
recipe
url-issue-to-pr-en:
if: contains(github.event.issue.labels.*.name, 'en') && contains(github.event.issue.labels.*.name, 'recipe') && contains(github.event.issue.labels.*.name, 'recipe-scrapers')
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Parse issue
id: parse
uses: onmax/[email protected]
with:
issue_number: ${{ github.event.issue.number }}
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install scripts with mise
id: scraper
run: |
curl https://mise.jdx.dev/install.sh | sh
echo "$HOME/.local/share/mise/bin">> $GITHUB_PATH
echo "$HOME/.local/share/mise/shims">> $GITHUB_PATH
eval "$(mise activate bash)"
mise settings set experimental true
mise run recipe-scrapers:install
echo "PARSED=$(mise run recipe-scrapers:run ${{ fromJson(steps.parse.outputs.payload).URL }} | jq -c)" >> $GITHUB_ENV
- name: Set up environment variables
run: |
echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
echo "ISSUEUSER=$(curl -s ${{ github.event.issue.user.url }} | jq -r '.name')" >> $GITHUB_ENV
echo "ISSUEUSER_ID=$(curl -s ${{ github.event.issue.user.url }} | jq -r '.id')" >> $GITHUB_ENV
if [[ "${{ fromJson(env.PARSED).author.name }}" == "" ]]; then echo "CREATOR=${{env.ISSUEUSER}}" >> $GITHUB_ENV; else echo "CREATOR=${{ fromJson(env.PARSED).author.name }}" >> $GITHUB_ENV; fi
echo "CREATORTITLE=Person" >> $GITHUB_ENV
if [[ "${{ fromJson(env.PARSED).author.name }}" == "" ]]; then echo "CREATORURL=${{ github.event.issue.html_url }}" >> $GITHUB_ENV; else echo "CREATORURL=${{ fromJson(env.PARSED).author.url }}" >> $GITHUB_ENV; fi
CATEGORY=${{ fromJson(steps.parse.outputs.payload).Category }}
echo "CATEGORY=${{ fromJson(steps.parse.outputs.payload).Category }}" >> $GITHUB_ENV
echo "TMPDIR=/tmp/src/$CATEGORY" >> $GITHUB_ENV
echo "TMPFILE=/tmp/src/$CATEGORY/${{ fromJson(env.PARSED).pattern }}.md" >> $GITHUB_ENV
echo "FILE_REL_TO_ROOT=src/$CATEGORY/${{ fromJson(env.PARSED).pattern }}.md" >> $GITHUB_ENV
- name: Create recipe
run: |
mkdir -p "$TMPDIR"
touch "$TMPFILE"

cat << EOF > "$TMPFILE"
---
description: "${{ fromJson(env.PARSED).totalTime }} | ${{ fromJson(steps.parse.outputs.payload).Difficulty }}"
authors:
- name: "$ISSUEUSER (@${{ github.event.issue.user.login }})"
link: "${{ github.event.issue.user.html_url }}"
avatar: "${{ github.event.issue.user.avatar_url }}"
date: $DATE
category:
- $ISSUEUSER
- $CATEGORY
tag:
EOF
for tag in ${{ join(fromJson(steps.parse.outputs.payload).Tags, ' ') }}
do
echo " - $tag">>"$TMPFILE"
done
cat << EOF >> "$TMPFILE"
---

# ${{ fromJson(env.PARSED).name }}

![](/static/${{ fromJson(env.PARSED).pattern }}/${{ fromJson(env.PARSED).pattern }}.webp)

EOF
if [[ "${{ fromJson(env.PARSED).author.name }}" != "" ]] && [[ "${{ fromJson(steps.parse.outputs.payload).URL }}" != "" ]]; then
cat << EOF >> "$TMPFILE"
!!!info

The recipe is originally from
[!badge variant="dark" iconAlign="right" margin="0 0 0 4" icon=":cook:" size="l" target="blank" text="${{ fromJson(env.PARSED).author.name }}"](${{ fromJson(steps.parse.outputs.payload).URL }})

!!!

EOF
elif [[ "${{ fromJson(env.PARSED).author.name }}" != "" ]]; then
cat << EOF >> "$TMPFILE"
!!!info

The recipe is originally from
[!badge variant="dark" iconAlign="right" margin="0 0 0 4" icon=":cook:" size="l" target="blank" text="${{ fromJson(env.PARSED).author.name }}"]

!!!

EOF
fi
cat << EOF >> "$TMPFILE"
<!-- dprint-ignore-start -->
||| :timer_clock: Time
${{ fromJson(env.PARSED).totalTime }}
||| :knife_fork_plate: Portions
${{ fromJson(env.PARSED).recipeYield }}
||| :cook: Difficulty
${{ fromJson(steps.parse.outputs.payload).Difficulty }}
|||
<!-- dprint-ignore-end -->

## Ingredients

EOF
while IFS= read -r ingredient; do
echo "- $ingredient" >>"$TMPFILE"
done < <(echo $PARSED | jq -r '.recipeIngredient[]')
cat << EOF >> "$TMPFILE"

## Steps

EOF
count=1
while IFS= read -r step; do
echo "$count. $step">>"$TMPFILE"
((count ++))
done < <(echo "$PARSED" | jq -r '.recipeInstructions[].text')
cat << EOF >> "$TMPFILE"

<script type="application/ld+json">
EOF
echo "$PARSED" | jq >>"$TMPFILE"
cat << EOF >> "$TMPFILE"
</script>
EOF
cat "$TMPFILE"
mv "$TMPFILE" ./"$FILE_REL_TO_ROOT"
- name: Update main branch
run: |
git pull --rebase
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
branch: "${{ fromJson(env.PARSED).pattern }}"
add-paths: |
${{ env.FILE_REL_TO_ROOT }}
delete-branch: true
author: ${{ github.event.issue.user.login }} <${{ env.ISSUEUSER_ID }}+${{ github.event.issue.user.login }}@users.noreply.github.com>
reviewers: ${{ github.repository_owner }}
assignees: ${{ github.repository_owner }}
title: "feat(recipe): ${{ fromJson(env.PARSED).name }}"
body: |
:robot: I just made a PR to add ${{ fromJson(env.PARSED).name }} on behalf of [@${{ github.event.issue.user.login }}](${{ github.event.issue.user.html_url }}).

Resolves #${{ github.event.issue.number }}
labels: |
recipe