diff --git a/.github/workflows/close-issue-with-banned-phrases.yml b/.github/workflows/close-issue-with-banned-phrases.yml index 5fb35811d..de14b3000 100644 --- a/.github/workflows/close-issue-with-banned-phrases.yml +++ b/.github/workflows/close-issue-with-banned-phrases.yml @@ -3,6 +3,8 @@ name: Close Icon Requests with Brand Terms on: issues: types: [opened] + discussion: + types: [created] permissions: {} @@ -16,12 +18,13 @@ jobs: permissions: contents: read issues: write + discussions: write steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Load stopwords from JSON & check issue title & body - if: contains(github.event.issue.labels.*.name, '🙌 icon request') + if: github.event_name == 'issues' && contains(github.event.issue.labels.*.name, '🙌 icon request') run: | ISSUE_TITLE=$(jq -r '.issue.title' "$GITHUB_EVENT_PATH") ISSUE_BODY=$(jq -r '.issue.body // ""' "$GITHUB_EVENT_PATH") @@ -34,6 +37,8 @@ jobs: if echo "$ISSUE_TITLE" | grep -iqE "$SAFE_KEY|$SAFE_VALUE" || \ { [ -n "$ICON_NAME_SECTION" ] && echo "$ICON_NAME_SECTION" | grep -iqE "$SAFE_KEY|$SAFE_VALUE"; }; then + URL_ENCODED_VALUE=$(jq -rn --arg val "$VALUE" '$val|@uri') + gh issue close ${{ github.event.issue.number }} \ --reason "not planned" \ --comment "It looks like this request is about **${VALUE}**, which is a brand logo. @@ -42,7 +47,7 @@ jobs: [Click here to read our official statement about brand logos in Lucide.](https://github.com/lucide-icons/lucide/blob/main/BRAND_LOGOS_STATEMENT.md) - You can [search for similar issues.](https://github.com/lucide-icons/lucide/issues?q=is%3Aissue+${VALUE}) + You can [search for similar issues.](https://github.com/lucide-icons/lucide/issues?q=is%3Aissue+${URL_ENCODED_VALUE}) We’re always happy to help on [Discord](https://discord.gg/EH6nSts)." @@ -50,3 +55,56 @@ jobs: exit 0 fi done + + - name: Load stopwords from JSON & check discussion title & body + if: github.event_name == 'discussion' && github.event.discussion.category.slug == 'icon-design' + run: | + DISCUSSION_TITLE=$(jq -r '.discussion.title' "$GITHUB_EVENT_PATH") + DISCUSSION_BODY=$(jq -r '.discussion.body // ""' "$GITHUB_EVENT_PATH") + ICON_NAME_SECTION=$(printf '%s\n' "$DISCUSSION_BODY" | awk '/### Icon name/{flag=1; next} /^### /{flag=0} flag') + + jq -r 'to_entries[] | "\(.key) \(.value)"' brand-stopwords.json | while read -r KEY VALUE; do + SAFE_KEY=$(printf '%s\n' "$KEY" | sed 's/[][\.^$*]/\\&/g') + SAFE_VALUE=$(printf '%s\n' "$VALUE" | sed 's/[][\.^$*]/\\&/g') + + if echo "$DISCUSSION_TITLE" | grep -iqE "$SAFE_KEY|$SAFE_VALUE" || \ + { [ -n "$ICON_NAME_SECTION" ] && echo "$ICON_NAME_SECTION" | grep -iqE "$SAFE_KEY|$SAFE_VALUE"; }; then + + URL_ENCODED_VALUE=$(jq -rn --arg val "$VALUE" '$val|@uri') + DISCUSSION_NODE_ID=$(jq -r '.discussion.node_id' "$GITHUB_EVENT_PATH") + COMMENT_BODY="It looks like this request is about **${VALUE}**, which is a brand logo. + + Lucide **does not accept** brand logos, and we do not plan to add them in the future. This is due to a combination of **legal restrictions**, **design consistency concerns**, and **practical maintenance reasons**. + + [Click here to read our official statement about brand logos in Lucide.](https://github.com/lucide-icons/lucide/blob/main/BRAND_LOGOS_STATEMENT.md) + + You can [search for similar discussions.](https://github.com/lucide-icons/lucide/discussions/categories/icon-design?discussions_q=category%253A%22Icon+design%22+${URL_ENCODED_VALUE}) + + We’re always happy to help on [Discord](https://discord.gg/EH6nSts)." + + # Add comment to discussion + gh api graphql -f query=' + mutation($discussionId: ID!, $body: String!) { + addDiscussionComment(input: {discussionId: $discussionId, body: $body}) { + comment { id } + } + }' -f discussionId="$DISCUSSION_NODE_ID" -f body="$COMMENT_BODY" + + # Close discussion + gh api graphql -f query=' + mutation($discussionId: ID!) { + closeDiscussion(input: {discussionId: $discussionId}) { + discussion { closed } + } + }' -f discussionId="$DISCUSSION_NODE_ID" + + # Lock discussion + gh api graphql -f query=' + mutation($lockableId: ID!, $reason: LockReason) { + lockLockable(input: {lockableId: $lockableId, lockReason: $reason}) { + lockedRecord { locked } + } + }' -f lockableId="$DISCUSSION_NODE_ID" -f reason="SPAM" + exit 0 + fi + done