Skip to content
name: Forward request to PR
on:
issues:
types: [labeled]
jobs:
createPullRequest:
if: github.event.label.name == 'data request'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Create new branch and commit
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
git checkout -b issue-${{ github.event.issue.number }}/request
echo "This is a new file" > newfile.txt
git add newfile.txt
git commit -m "Add new file for issue #${{ github.event.issue.number }}"
git push origin issue-${{ github.event.issue.number }}/request
- name: Create Pull Request
id: create_pr
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pr = await github.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Request #${context.issue.number}`,
head: `issue-${context.issue.number}/request`,
base: 'main',
body: `Request triggered by #${context.issue.number}`
});
return pr.data.number;
- name: Extract JSON
id: extract
run: |
BODY='${{ github.event.issue.body }}'
JSON=$(echo "$BODY" | sed -n '/```json/,/```/p' | sed '/```json/d' | sed '/```/d')
echo "$JSON" > json.txt
- name: Add issue comment to PR
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const issueComment = context.payload.issue.body;
const prNumber = ${{ steps.create_pr.outputs.result }};
const JSON = fs.readFileSync('json.txt', 'utf8');
github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `submit request ${JSON}`
});
- name: Add label to issue
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['submitted']
});
- name: Add label to PR
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prNumber = ${{ steps.create_pr.outputs.result }};
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['auto-generated']
});