Skip to content

Add Compatibility for category and categories in Properties Files #29

Add Compatibility for category and categories in Properties Files

Add Compatibility for category and categories in Properties Files #29

Workflow file for this run

name: Issue to Pull Request
on:
issues:
types:
- opened
- edited
- reopened
permissions:
contents: write
issues: write
pull-requests: write
jobs:
validate:
# Only run this job if the issue has the 'new contribution' label
if: contains(github.event.issue.labels.*.name, 'new contribution')
runs-on: ubuntu-latest
outputs:
props: ${{ steps.parseProps.outputs.props }}
comment-id: ${{ steps.issueComment.outputs.comment-id }}
steps:
- name: Parse issue
id: parseIssue
uses: onmax/[email protected]
with:
issue_number: ${{ github.event.issue.number }}
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: pip install -r requirements.txt
- name: Get issue labels
id: getLabels
env:
GH_TOKEN: ${{ github.token }}
run: |
labels=$(gh issue view "${{ github.event.issue.number }}" --json labels -q '.labels|map(.name)')
echo "Labels: $labels"
echo "labels=$labels" >> $GITHUB_ENV
- name: Determine category from labels
id: determineCategory
run: |
labels_json='${{ env.labels }}'
echo "Labels: $labels_json"
category=$(python scripts/determine_category.py "$labels_json")
if [ -z "$category" ]; then
echo "Category is empty. Please ensure the issue has a valid label."
exit 1
fi
echo "category=$category" >> $GITHUB_OUTPUT
echo "Category found: $category"
- name: Debug payload
run: echo "${{ steps.parseIssue.outputs.payload }}"
- name: Validate properties URL
id: validateUrl
run: |
properties_url="${{ fromJson(steps.parseIssue.outputs.payload)['Properties File URL'] }}"
if [ -z "$properties_url" ]; then
echo "Properties URL is empty. Please provide a valid URL."
exit 1
fi
if ! curl --output /dev/null --silent --head --fail "$properties_url"; then
echo "Url not valid: $properties_url"
exit 1
fi
- name: Read and validate properties txt file
id: parseProps
run: |
properties_url="${{ fromJson(steps.parseIssue.outputs.payload)['Properties File URL'] }}"
python -u scripts/parse_and_validate_properties_txt.py \
${{ steps.determineCategory.outputs.category }} \
"$properties_url"
- name: add comment to issue
id: issueComment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
Your properties file was successfully parsed.
- name: if failure, add comment to issue
if: failure()
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
There was an error in reading your properties file or parsing it.
Please ensure that the URL is correct and the file follows the required format.
${{ steps.parseProps.outputs.error }}
create-pr:
# Only run this job if the issue has the 'new contribution' label
if: contains(github.event.issue.labels.*.name, 'new contribution')
needs: validate
env:
BRANCH_NAME: issue-${{ github.event.issue.number }}
ISSUE_NUM: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: pip install -r requirements.txt
- name: check if target branch exists
id: branchExists
uses: GuillaumeFalourd/branch-exists@v1
with:
branch: ${{ env.BRANCH_NAME }}
- name: delete target branch if exists
if: steps.branchExists.outputs.exists == 'true'
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{github.token}}
branches: ${{ env.BRANCH_NAME }}
- name: create branch
env:
GH_TOKEN: ${{ github.token }}
run: gh issue develop $ISSUE_NUM --name $BRANCH_NAME --checkout
- name: edit database
run: |
cd scripts
python add_new_contribution_to_yaml.py '${{ needs.validate.outputs.props }}'
- name: commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: new contribution from issue ${{ env.ISSUE_NUM }}
branch: ${{ env.BRANCH_NAME }}
add_options: '-u'
- name: Create pull request
run: gh pr create -B main -H $BRANCH_NAME --title "new contribution issue $ISSUE_NUM" --body "${{github.event.issue.title }}"
env:
GH_TOKEN: ${{ github.token }}
- name: add comment to issue
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ needs.validate.outputs.comment-id }}
body: |
A pull request with your contribution has been successfully created.
- name: if failure, add comment to issue
if: failure()
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ needs.validate.outputs.comment-id }}
body: |
An error was encountered when adding your contribution.
We will look into this issue as soon as possible. Please check the details of your submission and try again if necessary.