Skip to content

fix: v3 dataset api #26

fix: v3 dataset api

fix: v3 dataset api #26

name: Auto Upsert Release PR
on:
# trigger on push to dev branch
push:
branches:
- dev
# trigger on manual workflow_dispatch
workflow_dispatch:
concurrency:
group: pr-upsert-${{ github.ref }}
cancel-in-progress: true
jobs:
pr-upsert:
name: Upsert PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: "dev"
# fetch all history so that git log can get all commit messages
fetch-depth: 0
# create a PR from dev to main, with title in form: Release <semver>
# where, <semver> is the next version number to be released, based on the last release in git tag
- name: Upsert PR Content
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT_FOR_RELEASE_TAGGER }}
script: |
const https = require('https')
const commitMessages = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: 'main',
head: 'dev'
}).then(res => res.data.commits.map(commit => commit.commit.message))
const summary = await new Promise((resolve, reject) => {
const req = https.request({
hostname: 'api.openai.com',
path: '/v1/chat/completions',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${{ secrets.OPENAI_API_KEY }}`
}
}, res => {
let data = ''
res.on('data', chunk => data += chunk)
res.on('end', () => {
resolve(JSON.parse(data).choices[0].message.content)
})
})
req.on('error', reject)
req.write(JSON.stringify({
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "You are now a git commit message summarizer. By analyzing commit messages, you should provide a concise summary, highlighting key changes and updates made in each commit. This can save time and improve clarity for developers working in collaborative projects.\n\nCommits are typically constructed using the Conventional Commit standard.\n\nYour summarized message should consist of 1-3 sentences that are short, concise and includes the overall intent of the PR. You should NOT use bullet points. You MAY omit merge commits in your response."
},
{
"role": "user",
"content": "feat: remove deleted required flag\nbuild: add workflow_dispatch\nfeat: add rowsAffected & fix json struct tag\nchore: add logs"
},
{
"role": "assistant",
"content": "Added: `workflow_dispatch`, `rowsAffected`, logs.\nFixed: JSON struct tag.\nRemoved: required flag of `deleted`."
},
{
"role": "user",
"content": commitMessages.join('\n')
}
],
temperature: 1,
max_tokens: 256,
top_p: 1,
frequency_penalty: 0.1,
presence_penalty: 0.2
}))
req.end()
})
const { data: { tag_name: lastRelease } } = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
})
const nextRelease = lastRelease.replace(/(\d+)$/, (match, p1) => Number(p1) + 1)
const prTitle = `Release ${nextRelease}`
let body = `> *This PR is automatically created by actions defined in this repository. To see the run log of this action, please click [here](/${{ github.repository }}/actions/runs/${{ github.run_id }})*\n\n---\n\n## Summary\n\n${summary.replace(/\n/g, '\n\n')}`
const existedPR = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:dev`,
base: 'main'
})
if (existedPR.data.length > 0) {
core.info(`PR already exists: ${existedPR.data[0].html_url}. Updating body...`)
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: existedPR.data[0].number,
body: body
})
core.info(`PR updated: ${existedPR.data[0].html_url}`)
return
}
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: prTitle,
body: body,
head: context.ref,
base: 'main',
draft: true
})