pull/787/head
f 2 weeks ago
parent 23ddd25fe3
commit fefd04928c

@ -13,6 +13,14 @@ jobs:
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
@ -24,35 +32,58 @@ jobs:
pull_number: context.issue.number
});
const content = `${pr.title}\n\n${pr.body}`;
return content;
core.setOutput('content', content);
- name: Generate Better Title
id: generate-title
uses: openai/openai-api@v1
with:
api-key: ${{ secrets.OPENAI_API_KEY }}
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."
},
{
"role": "user",
"content": "Based on this pull request content, generate a better title:\n\n${{ steps.pr-content.outputs.result }}"
}
]
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.response != ''
if: steps.generate-title.outputs.title != ''
uses: actions/github-script@v6
with:
script: |
const newTitle = ${{ steps.generate-title.outputs.response }}.choices[0].message.content.trim();
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
title: newTitle
title: '${{ steps.generate-title.outputs.title }}'
});
Loading…
Cancel
Save