Generate and Summarize Project Issues #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate and Summarize Sprint Report | |
on: | |
workflow_dispatch: | |
jobs: | |
generate_sprint_report: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 # Checkout the repository to make changes | |
- name: Generate Sprint Report | |
id: generate_report | |
uses: actions/github-script@v6 # Updated to v6 | |
with: | |
script: | | |
const issues = await github.rest.issues.listForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'closed', | |
since: '2024-09-01T00:00:00Z', // Modify sprint period here | |
per_page: 100 | |
}); | |
let report = `# Sprint Summary\n\n## Closed Issues\n`; | |
issues.data.forEach(issue => { | |
report += `- [${issue.title}](${issue.html_url}) - Closed by @${issue.user.login}\n`; | |
}); | |
core.setOutput('report', report); | |
- name: Save report as environment variable | |
run: | | |
echo "REPORT<<EOF" >> $GITHUB_ENV | |
echo "${{ steps.generate_report.outputs.report }}" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Send report to OpenAI for summarization | |
id: summarize_report | |
run: | | |
REPORT="${{ env.REPORT }}" | |
RESPONSE=$(curl -s -w "%{http_code}" -o response.json \ | |
https://api.openai.com/v1/chat/completions \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer ${{ secrets.OPENAI_API_KEY }}" \ | |
-d "$(jq -n --arg content "$REPORT" '{model: "gpt-4", messages: [{role: "user", content: $content}], max_tokens: 300, temperature: 0.7}')") | |
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1) | |
if [ "$HTTP_STATUS" != "200" ]; then | |
echo "Request failed with status code: $HTTP_STATUS" | |
cat response.json | |
exit 1 | |
fi | |
- name: Output the summary and save to a markdown file | |
run: | | |
if [ -f response.json ]; then | |
SUMMARY=$(jq -r '.choices[0].message.content' < response.json) | |
echo "$SUMMARY" > sprint_summary.md # Save the summary to markdown file | |
else | |
echo "No response file found" | |
exit 1 | |
fi | |
shell: bash | |
env: | |
REPORT: "${{ steps.generate_report.outputs.report }}" | |
- name: Commit the markdown file to the repository | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add sprint_summary.md | |
git commit -m "Add Sprint Summary Report" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use the GitHub token to authenticate the push |