Skip to content

Commit

Permalink
feat: add main action for labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
flukolo4ek committed Oct 11, 2024
1 parent 33bf9b0 commit 2b15bd4
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/.scripts/add_labels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

CONFIG_URL="https://raw.githubusercontent.com/datalens-tech/datalens/main/.github/workflows/scripts/changelog/changelog_config.json"

PR_TITLE=${PR_TITLE}
GH_TOKEN=${GH_TOKEN}
REPO=${REPO}
PR_NUMBER=${PR_NUMBER}

CONFIG_DATA=$(curl -s $CONFIG_URL)

TYPE_LABELS=$(echo $CONFIG_DATA | jq '.section_tags.tags[].id' | tr -d '"')
TYPE_LABELS_PREFIX=$(echo $CONFIG_DATA | jq '.section_tags.prefix' | tr -d '"')

COMPONENT_LABELS=$(echo $CONFIG_DATA | jq '.component_tags.tags[].id' | tr -d '"')
COMPONENT_LABELS_PREFIX=$(echo $CONFIG_DATA | jq '.component_tags.prefix' | tr -d '"')

LABELS_TO_ADD=""


for label in $TYPE_LABELS
do
echo $PR_TITLE | grep -Ei "^$label*" > /dev/null

if [ $? == 0 ]
then
LABELS_TO_ADD+="$TYPE_LABELS_PREFIX$label"
fi

done

for label in $COMPONENT_LABELS
do
echo $PR_TITLE | grep -Ei "[a-z]+\(.*$label.*\):*" > /dev/null

if [ $? == 0 ]
then
LABELS_TO_ADD+=",$COMPONENT_LABELS_PREFIX$label"
fi

done

gh pr edit $PR_NUMBER --repo $REPO --add-label $LABELS_TO_ADD

echo $LABELS_TO_ADD
31 changes: 31 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: E2E

on:
pull_request:
types:
- opened
- reopened
- synchronize
- edited

jobs:
e2e-default:
runs-on: ubuntu-20.04

permissions:
contents: read
pull-requests: write

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

- name: Test Run
id: test-run
uses: ./

- name: Assert placeholder
uses: nick-fields/assert-action@v2
with:
actual: ${{ steps.test-run.outputs.added_labels }}
expected: "type/feat"
42 changes: 42 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Add labels to PR"
description: "Add labels to PR Action"

inputs:
github_owner:
description: "Owner of the repository"
default: ${{ github.repository_owner }}
github_repo:
description: "Repository name"
default: ${{ github.event.repository.name }}
github_token:
description: "GitHub token"
default: ${{ github.token }}
github_pr_number:
description: "GitHub PR number"
default: ${{ github.event.pull_request.number }}
github_pr_title:
description: "GitHub PR title"
default: ${{ github.event.pull_request.title }}

outputs:
added_labels:
description: "Added labels to PR"
value: ${{ steps.run.outputs.added_labels }}

runs:
using: "composite"
steps:
- name: Run script
id: run
working-directory: .github/.scripts
shell: bash
run: echo "added_labels=$(./add_labels.sh)" >> $GITHUB_OUTPUT
env:
REPO: ${{ inputs.github_owner }}/${{ inputs.github_repo }}
PR_NUMBER: ${{ inputs.github_pr_number }}
PR_TITLE: ${{ inputs.github_pr_title }}
GH_TOKEN: ${{ inputs.github_token }}

branding:
icon: "tag"
color: "gray-dark"

0 comments on commit 2b15bd4

Please sign in to comment.