Skip to content

doc: update instruction #134

doc: update instruction

doc: update instruction #134

Workflow file for this run

name: Auto Labeler
on:
issues:
types:
- reopened
- opened
- edited
pull_request:
types:
- reopened
- opened
- edited
jobs:
auto_labeler:
# Add permission to update PR and issue labels
permissions:
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Extract labels from title
id: extract_labels
run: |
# Supported labels definition
supported_labels=("ci" "doc" "core" "bug" "enhancement" "sample" "usage")
# Get title
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
title="${{ github.event.pull_request.title }}"
number="${{ github.event.pull_request.number }}"
type="pr"
elif [[ "${{ github.event_name }}" == "issues" ]]; then
title="${{ github.event.issue.title }}"
number="${{ github.event.issue.number }}"
type="issue"
else
echo "Invalid event type: ${{ github.event_name }}"
exit 1
fi
# Function to parse title and return supported labels
echo "Analyzing pull request title: '${title}'"
# Parse title and return supported labels
parsed_labels=""
for label in "${supported_labels[@]}"; do
if [[ $title == *"${label}"* ]]; then
if [[ $parsed_labels == "" ]]; then
# Cover init case
parsed_labels="${label}"
else
parsed_labels="${parsed_labels},${label}"
fi
echo "Added label ${label}"
fi
done
# Remove trailing semicolon if present
parsed_labels="${parsed_labels%;}"
echo "$parsed_labels"
# Main script
if [ -z "$title" ]; then
echo "Please provide a title."
exit 1
fi
echo "labels=${parsed_labels}" >> $GITHUB_OUTPUT
echo "number=${number}" >> $GITHUB_OUTPUT
echo "type=${type}" >> $GITHUB_OUTPUT
echo $GITHUB_OUTPUT
- name: Add labels to the PR/issue
if: steps.extract_labels.outputs.labels != ''
run: gh "$TYPE" edit "$NUMBER" --add-label "$LABELS"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ steps.extract_labels.outputs.number }}
TYPE: ${{ steps.extract_labels.outputs.type }}
LABELS: ${{ steps.extract_labels.outputs.labels }}