Skip to content

Commit

Permalink
GH-1 GH-2 Limit title and description length
Browse files Browse the repository at this point in the history
  • Loading branch information
jmetrikat committed Jan 19, 2024
1 parent c2b59c3 commit 8a7c108
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/new_experience.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ body:
attributes:
label: Title
description: The Experience title will be displayed in the Gallery.
placeholder: "Maximum length of 40 characters."
validations:
required: true
- type: textarea
Expand All @@ -39,6 +40,7 @@ body:
attributes:
label: Description
description: It helps people understand what the Experience provides. It will be displayed in the Gallery.
placeholder: "Maximum length of 260 characters."
validations:
required: true
- type: dropdown
Expand Down Expand Up @@ -391,7 +393,7 @@ body:
options:
- label: I agree that this Experience is licensed under the MIT License.
required: true
- label: I have intellectual property rights and/or permission to contribute the Experience and its content.
- label: I have intellectual property rights and/or permission to contribute the Experience and its content.
required: true
- label: I confirm that the Experience does not contain any harmful or malicious content.
required: true
61 changes: 51 additions & 10 deletions .github/workflows/parse-new-experience.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
on:
issues:
types: [labeled]
types: [labeled, edited]

name: Parse New Experience
jobs:
new_experience:
if: github.event.label.name == 'experience'
if: github.event.label.name == 'experience' || github.event.action == 'edited'
runs-on: ubuntu-latest
permissions:
issues: write
Expand All @@ -17,13 +17,52 @@ jobs:
id: issue-parser
with:
template-path: .github/ISSUE_TEMPLATE/new_experience.yml
- run: echo '${{ steps.issue-parser.outputs.jsonString }}' > issue.json
- run: |
- name: Create issue.json
run: echo '${{ steps.issue-parser.outputs.jsonString }}' > issue.json
- name: Check length restriction for title and description
id: check-restrictions
run: |
title_length=$(jq '.title | length' issue.json)
description_length=$(jq '.description | length' issue.json)
if [ $title_length -gt 40 ]; then
echo "title_length_comment=Title is too long: $title_length characters, but only 40 are allowed." >> $GITHUB_OUTPUT
echo "restrictions-exceeded=true" >> $GITHUB_OUTPUT
fi
if [ $description_length -gt 260 ]; then
echo "description_length_comment=Description is too long: $description_length characters, but only 260 are allowed." >> $GITHUB_OUTPUT
echo "restrictions-exceeded=true" >> $GITHUB_OUTPUT
fi
if [ $title_length -le 40 ] && [ $description_length -le 260 ]; then
echo "restrictions-exceeded=false" >> $GITHUB_OUTPUT
fi
- name: Comment and add label to issue
if: ${{ steps.check-restrictions.outputs.restrictions_exceeded }} == 'true'
run: gh issue comment "$NUMBER" --body "$BODY" && gh issue edit "$NUMBER" --add-label "$LABELS"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
LABELS: changes_requested
BODY: "I've noticed a problem with your submission. Please fix it by editing your issue:\n\n
${{ steps.check-restrictions.outputs.title_length_comment }}\n
${{ steps.check-restrictions.outputs.description_length_comment }}"
- name: Remove label from issue if restrictions are not exceeded
if: ${{ steps.check-restrictions.outputs.restrictions_exceeded }} == 'false' && contains(github.event.issue.labels.*.name, 'changes_requested')
run: gh issue edit "$NUMBER" --remove-label "$LABELS"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
LABELS: changes_requested
- name: Create experience name and id
run: |
echo "experience_name=$(echo '${{ steps.issue-parser.outputs.issueparser_title }}' | sed -e 's/[^[:alnum:]]/_/g' | tr -s '_' | tr A-Z a-z)" >> "$GITHUB_ENV"
echo "id=$(uuidgen)" >> "$GITHUB_ENV"
- run: |
jq '. + {"author": "${{ github.event.issue.user.login }}", "name": "${{ env.experience_name }}", "id": "${{ env.id }}"}' issue.json > tmp && mv tmp issue.json
- id: manifest-builder
- name: Add author, name and id to issue.json
run: |
jq '. + {"author": "${{ github.event.issue.user.login }}", "name": "${{ env.experience_name }}", "id": "${{ env.id }}"}' issue.json > tmp && mv tmp issue.json
- name: Build manifest
id: manifest-builder
run: |
node tools/prepare-experience.js
rm issue.json
Expand All @@ -39,6 +78,7 @@ jobs:
echo "test-manifest=anytype://main/import/?type=experience&source=https%3A%2F%2Fgithub.com%2Fanyproto%2Fgallery%2Fraw%2F${{ env.experience_name }}%2Fexperiences%2F${{ env.experience_name }}%2Ftest-manifest.json" >> "$GITHUB_ENV"
- name: Create Pull Request
id: cpr
if: ${{ steps.check-restrictions.outputs.restrictions_exceeded }} == 'false' && !contains(github.event.issue.labels.*.name, 'changes_requested')
uses: peter-evans/create-pull-request@v5
with:
commit-message: "Add preview for ${{ steps.issue-parser.outputs.issueparser_title }}"
Expand All @@ -48,6 +88,7 @@ jobs:
title: "Add experience ${{ steps.issue-parser.outputs.issueparser_title }}"
body: "Based on issue #${{ github.event.issue.number }}"
- name: Comment on Issue
if: ${{ steps.check-restrictions.outputs.restrictions_exceeded }} == 'false' && !contains(github.event.issue.labels.*.name, 'changes_requested')
run: gh issue comment "$NUMBER" --body "$BODY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -56,10 +97,10 @@ jobs:
BODY: >
Thanks for your contribution! :tada:
I have created a pull request #${{ steps.cpr.outputs.pull-request-number }} based on data you provided.
I have created a pull request #${{ steps.cpr.outputs.pull-request-number }} based on data you provided.
If everything worked correctly, you can test the Experience:
If everything worked correctly, you can test the Experience:
[${{ env.test-manifest }}](${{ env.test-manifest }})
The Experience will be added to the Gallery after someone from the Any team reviews it.

0 comments on commit 8a7c108

Please sign in to comment.