mirror of
https://github.com/f/awesome-chatgpt-prompts.git
synced 2025-03-10 07:59:24 -04:00
89 lines
2.7 KiB
YAML
89 lines
2.7 KiB
YAML
name: Improve PR Title
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, edited, synchronize]
|
|
|
|
jobs:
|
|
improve-title:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
pull-requests: write
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '18'
|
|
|
|
- name: Install OpenAI SDK
|
|
run: npm install openai@^4.0.0
|
|
|
|
- name: Get PR Content
|
|
id: pr-content
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
const { data: pr } = await github.rest.pulls.get({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: context.issue.number
|
|
});
|
|
const content = `${pr.title}\n\n${pr.body}`;
|
|
core.setOutput('content', content);
|
|
|
|
- name: Generate Better Title
|
|
id: generate-title
|
|
run: |
|
|
node << 'EOF'
|
|
const OpenAI = require('openai');
|
|
|
|
async function generateTitle() {
|
|
const openai = new OpenAI({
|
|
apiKey: process.env.OPENAI_API_KEY
|
|
});
|
|
|
|
const content = `${{ steps.pr-content.outputs.content }}`;
|
|
|
|
const completion = await openai.chat.completions.create({
|
|
model: "gpt-3.5-turbo",
|
|
messages: [
|
|
{
|
|
role: "system",
|
|
content: "You are a helpful assistant that improves pull request titles. Make titles concise, descriptive, and following conventional commit message style. Return ONLY the new title, nothing else."
|
|
},
|
|
{
|
|
role: "user",
|
|
content: `Based on this pull request content, generate a better title:\n\n${content}`
|
|
}
|
|
],
|
|
temperature: 0.7,
|
|
max_tokens: 60,
|
|
top_p: 1.0
|
|
});
|
|
|
|
const newTitle = completion.choices[0].message.content.trim();
|
|
console.log(`::set-output name=title::${newTitle}`);
|
|
}
|
|
|
|
generateTitle().catch(error => {
|
|
console.error('Error:', error);
|
|
process.exit(1);
|
|
});
|
|
EOF
|
|
env:
|
|
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
|
|
|
- name: Update PR Title
|
|
if: steps.generate-title.outputs.title != ''
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
await github.rest.pulls.update({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: context.issue.number,
|
|
title: '${{ steps.generate-title.outputs.title }}'
|
|
}); |