update
This commit is contained in:
parent
23ddd25fe3
commit
fefd04928c
|
@ -13,6 +13,14 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- 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
|
- name: Get PR Content
|
||||||
id: pr-content
|
id: pr-content
|
||||||
uses: actions/github-script@v6
|
uses: actions/github-script@v6
|
||||||
|
@ -24,35 +32,58 @@ jobs:
|
||||||
pull_number: context.issue.number
|
pull_number: context.issue.number
|
||||||
});
|
});
|
||||||
const content = `${pr.title}\n\n${pr.body}`;
|
const content = `${pr.title}\n\n${pr.body}`;
|
||||||
return content;
|
core.setOutput('content', content);
|
||||||
|
|
||||||
- name: Generate Better Title
|
- name: Generate Better Title
|
||||||
id: generate-title
|
id: generate-title
|
||||||
uses: openai/openai-api@v1
|
run: |
|
||||||
with:
|
node << 'EOF'
|
||||||
api-key: ${{ secrets.OPENAI_API_KEY }}
|
const OpenAI = require('openai');
|
||||||
model: gpt-3.5-turbo
|
|
||||||
messages: |
|
async function generateTitle() {
|
||||||
[
|
const openai = new OpenAI({
|
||||||
{
|
apiKey: process.env.OPENAI_API_KEY
|
||||||
"role": "system",
|
});
|
||||||
"content": "You are a helpful assistant that improves pull request titles. Make titles concise, descriptive, and following conventional commit message style."
|
|
||||||
},
|
const content = `${{ steps.pr-content.outputs.content }}`;
|
||||||
{
|
|
||||||
"role": "user",
|
const completion = await openai.chat.completions.create({
|
||||||
"content": "Based on this pull request content, generate a better title:\n\n${{ steps.pr-content.outputs.result }}"
|
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
|
- name: Update PR Title
|
||||||
if: steps.generate-title.outputs.response != ''
|
if: steps.generate-title.outputs.title != ''
|
||||||
uses: actions/github-script@v6
|
uses: actions/github-script@v6
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const newTitle = ${{ steps.generate-title.outputs.response }}.choices[0].message.content.trim();
|
|
||||||
await github.rest.pulls.update({
|
await github.rest.pulls.update({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
pull_number: context.issue.number,
|
pull_number: context.issue.number,
|
||||||
title: newTitle
|
title: '${{ steps.generate-title.outputs.title }}'
|
||||||
});
|
});
|
Loading…
Reference in New Issue