|
| 1 | +name: Issue to Pull Request |
| 2 | +on: |
| 3 | + issues: |
| 4 | + types: |
| 5 | + - opened |
| 6 | + - edited |
| 7 | + - reopened |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + issues: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + validate: |
| 15 | + if: contains(github.event.issue.labels.*.name, 'new-contribution') |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + props: ${{ steps.parseProps.outputs.props }} |
| 19 | + comment-id: ${{ steps.issueComment.outputs.comment-id }} |
| 20 | + steps: |
| 21 | + - name: Parse issue |
| 22 | + id: parseIssue |
| 23 | + |
| 24 | + with: |
| 25 | + issue_number: ${{ github.event.issue.number }} |
| 26 | + |
| 27 | + - name: Checkout sources |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Setup Python |
| 31 | + uses: actions/setup-python@v5 |
| 32 | + with: |
| 33 | + python-version: 3.x |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: pip install -r requirements.txt |
| 37 | + |
| 38 | + - name: Read and validate properties txt file |
| 39 | + id: parseProps |
| 40 | + run: > |
| 41 | + python -u scripts/parse_and_validate_properties_txt.py \ |
| 42 | + ${{ fromJson(steps.parseIssue.outputs.payload).contribution_type }} \ |
| 43 | + "${{ fromJson(steps.parseIssue.outputs.payload).properties_url }}" |
| 44 | +
|
| 45 | + - name: add comment to issue |
| 46 | + id: issueComment |
| 47 | + uses: peter-evans/create-or-update-comment@v4 |
| 48 | + with: |
| 49 | + issue-number: ${{ github.event.issue.number }} |
| 50 | + body: | |
| 51 | + Your properties file was successfully parsed. |
| 52 | +
|
| 53 | + - name: if failure, add comment to issue |
| 54 | + if: failure() |
| 55 | + uses: peter-evans/create-or-update-comment@v4 |
| 56 | + with: |
| 57 | + issue-number: ${{ github.event.issue.number }} |
| 58 | + body: | |
| 59 | + There was an error in reading in your file and parsing it. |
| 60 | + |
| 61 | + ${{ steps.parseProps.outputs.error }} |
| 62 | + create-pr: |
| 63 | + needs: validate |
| 64 | + env: |
| 65 | + BRANCH_NAME: issue-${{ github.event.issue.number }} |
| 66 | + ISSUE_NUM: ${{ github.event.issue.number }} |
| 67 | + ISSUE_TITLE: ${{ github.event.issue.title }} |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: Checkout sources |
| 71 | + uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Setup Python |
| 74 | + uses: actions/setup-python@v5 |
| 75 | + with: |
| 76 | + python-version: 3.x |
| 77 | + |
| 78 | + - name: Install dependencies |
| 79 | + run: pip install -r requirements.txt |
| 80 | + |
| 81 | + - name: check if target branch exists |
| 82 | + id: branchExists |
| 83 | + uses: GuillaumeFalourd/branch-exists@v1 |
| 84 | + with: |
| 85 | + branch: ${{ env.BRANCH_NAME }} |
| 86 | + |
| 87 | + - name: delete target branch if exists |
| 88 | + if: steps.branchExists.outputs.exists == 'true' |
| 89 | + uses: dawidd6/action-delete-branch@v3 |
| 90 | + with: |
| 91 | + github_token: ${{github.token}} |
| 92 | + branches: ${{ env.BRANCH_NAME }} |
| 93 | + |
| 94 | + - name: create branch |
| 95 | + env: |
| 96 | + GH_TOKEN: ${{ github.token }} |
| 97 | + run: gh issue develop $ISSUE_NUM --name $BRANCH_NAME --checkout |
| 98 | + |
| 99 | + - name: edit database |
| 100 | + run: | |
| 101 | + cd scripts |
| 102 | + python add_new_contribution_to_yaml.py '${{ needs.validate.outputs.props }}' |
| 103 | +
|
| 104 | + - name: commit changes |
| 105 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 106 | + with: |
| 107 | + commit_message: new contribution from issue ${{ env.ISSUE_NUM }} |
| 108 | + branch: ${{ env.BRANCH_NAME }} |
| 109 | + add_options: '-u' |
| 110 | + |
| 111 | + - name: Create pull request |
| 112 | + run: gh pr create -B main -H $BRANCH_NAME --title "new contribution issue $ISSUE_NUM" --body "${{github.event.issue.title }}" |
| 113 | + env: |
| 114 | + GH_TOKEN: ${{ github.token }} |
| 115 | + |
| 116 | + - name: add comment to issue |
| 117 | + uses: peter-evans/create-or-update-comment@v4 |
| 118 | + with: |
| 119 | + comment-id: ${{ needs.validate.outputs.comment-id }} |
| 120 | + body: | |
| 121 | + A pull request with your contribution has been successfully created. |
| 122 | +
|
| 123 | +
|
| 124 | + - name: if failure, add comment to issue |
| 125 | + if: failure() |
| 126 | + uses: peter-evans/create-or-update-comment@v4 |
| 127 | + with: |
| 128 | + comment-id: ${{ needs.validate.outputs.comment-id }} |
| 129 | + body: | |
| 130 | + An error was encountered when adding your contribution. |
| 131 | + We will look into this issue as soon as possible. |
0 commit comments