Skip to content
Merged
Show file tree
Hide file tree
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
91 changes: 91 additions & 0 deletions .github/workflows/component-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Identify Component and Label Issue

on:
issues:
types: [opened, edited]

jobs:
process-issue:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Extract component and locate file
id: search_component
shell: bash
run: |
echo "Issue Body:"
echo "${{ github.event.issue.body }}"

# Extract the component name (line after "### Component Name")
COMPONENT=$(echo "${{ github.event.issue.body }}" | awk 'tolower($0) ~ /#+[ ]*component name/ {getline; print}' | xargs)
echo "Component Name: $COMPONENT"

# Search for a Python file matching the component name in the specified directories
FILE_PATH=$(find plugins/modules plugins/module_utils -type f -name "${COMPONENT}.py" | head -n 1)

if [ -z "$FILE_PATH" ]; then
echo "No file found for component $COMPONENT"
FILE_PATH="No file found for component $COMPONENT"
else
echo "Found file: $FILE_PATH"
fi

# Set the found file path as an output variable
echo "::set-output name=file_path::$FILE_PATH"

- name: Determine label based on file path
id: determine_label
shell: bash
run: |
FILE_PATH="${{ steps.search_component.outputs.file_path }}"
LABEL=""
if [[ "$FILE_PATH" == *"plugins/modules"* ]]; then
LABEL="module"
elif [[ "$FILE_PATH" == *"plugins/module_utils"* ]]; then
LABEL="module_utils"
else
LABEL="unknown"
fi
echo "Determined label: $LABEL"
echo "::set-output name=label::$LABEL"

- name: Create a link to the file if found
id: file_link
shell: bash
run: |
FILE_PATH="${{ steps.search_component.outputs.file_path }}"
if [[ "$FILE_PATH" == No\ file\ found* ]]; then
LINK="No file found for component"
else
# Build a Markdown link using the repository, default branch (main), and the file path
REPO="${{ github.repository }}"
BRANCH="main" # change this if your default branch is different
LINK="[${FILE_PATH}](https://github.com/${REPO}/blob/${BRANCH}/${FILE_PATH})"
fi
echo "File link: $LINK"
echo "::set-output name=link::$LINK"

- name: Post a comment with identified file link
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.issue.number }}
body: |
**Files identified in the description:**

- ${{ steps.file_link.outputs.link }}

- name: Add label to issue based on file path
if: steps.determine_label.outputs.label != 'unknown'
uses: actions/github-script@v6
with:
script: |
const label = "${{ steps.determine_label.outputs.label }}";
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [label]
});
91 changes: 91 additions & 0 deletions .github/workflows/component-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Identify Component and Label PR

on:
pull_request:
types: [opened, edited, synchronize]

jobs:
process-pr:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Extract component and locate file
id: search_component
shell: bash
run: |
echo "PR Description:"
echo "${{ github.event.pull_request.body }}"

# Extract the component name (the line after "### Component Name")
COMPONENT=$(echo "${{ github.event.pull_request.body }}" | awk 'tolower($0) ~ /#+[ ]*component name/ {getline; print}' | xargs)
echo "Component Name: $COMPONENT"

# Search for a Python file matching the component name in the specified directories
FILE_PATH=$(find plugins/modules plugins/module_utils -type f -name "${COMPONENT}.py" | head -n 1)

if [ -z "$FILE_PATH" ]; then
echo "No file found for component $COMPONENT"
FILE_PATH="No file found for component $COMPONENT"
else
echo "Found file: $FILE_PATH"
fi

# Set the found file path as an output variable
echo "::set-output name=file_path::$FILE_PATH"

- name: Determine label based on file path
id: determine_label
shell: bash
run: |
FILE_PATH="${{ steps.search_component.outputs.file_path }}"
LABEL=""
if [[ "$FILE_PATH" == *"plugins/modules"* ]]; then
LABEL="module"
elif [[ "$FILE_PATH" == *"plugins/module_utils"* ]]; then
LABEL="module_utils"
else
LABEL="unknown"
fi
echo "Determined label: $LABEL"
echo "::set-output name=label::$LABEL"

- name: Create a link to the file if found
id: file_link
shell: bash
run: |
FILE_PATH="${{ steps.search_component.outputs.file_path }}"
if [[ "$FILE_PATH" == No\ file\ found* ]]; then
LINK="No file found for component"
else
# Build a Markdown link using the repository, default branch (main), and the file path
REPO="${{ github.repository }}"
BRANCH="main" # change this if your default branch is different
LINK="[${FILE_PATH}](https://github.com/${REPO}/blob/${BRANCH}/${FILE_PATH})"
fi
echo "File link: $LINK"
echo "::set-output name=link::$LINK"

- name: Post a comment with identified file link
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
**Files identified in the description:**

- ${{ steps.file_link.outputs.link }}

- name: Add label to PR based on file path
if: steps.determine_label.outputs.label != 'unknown'
uses: actions/github-script@v6
with:
script: |
const label = "${{ steps.determine_label.outputs.label }}";
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [label]
});
3 changes: 1 addition & 2 deletions .github/workflows/issue-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on:
jobs:
label-issue:
runs-on: ubuntu-latest
permissions:
issues: write
permissions: write-all
steps:
- name: Add label for Bug Report
if: contains(github.event.issue.body, 'Bug Report')
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/pr-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on:
jobs:
label-pull_request:
runs-on: ubuntu-latest
permissions:
pull-requests: write
permissions: write-all
steps:
- name: Add label for Bugfix
if: contains(github.event.pull_request.body, '- Bugfix Pull Request')
Expand Down
Loading