Skip to content

Merge branch 'main' of github.com:insper-education/issue_generator in… #9

Merge branch 'main' of github.com:insper-education/issue_generator in…

Merge branch 'main' of github.com:insper-education/issue_generator in… #9

Workflow file for this run

name: Create Issues on First Push
on:
push:
branches:
- main
jobs:
create_issues:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Check for open issues
id: check_issues
run: |
ISSUES=$(curl -H "Authorization: token ${{ secrets.ISSUE_GENERATOR }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues?state=open)
COUNT=$(echo "$ISSUES" | jq '. | length')
if [[ "$COUNT" -eq 0 ]]; then
echo "::set-output name=has_issues::false"
else
echo "::set-output name=has_issues::true"
fi
continue-on-error: true
- name: Create Issues
if: steps.check_issues.outputs.has_issues == 'false'
uses: actions/github-script@v3
with:
github-token: ${{secrets.ISSUE_GENERATOR}}
script: |
const fs = require('fs');
const path = require('path');
const issueDir = './issues'; // Replace with the actual directory path
const files = fs.readdirSync(issueDir).filter(file => path.extname(file) === '.md').sort();
files.forEach(file => {
const issueTitle = path.basename(file, '.md');
const issueBody = fs.readFileSync(path.join(issueDir, file), 'utf8');
const issue = {
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody
};
await github.issues.create(issue);
await sleep(2000);
});