Skip to content

feat: add automation #93

feat: add automation

feat: add automation #93

Workflow file for this run

name: Auto PR
on:
push:
branches:
- staging
jobs:
create-pull-request:
runs-on: ubuntu-latest
steps:
- name: Create Pull Request
uses: actions/github-script@v6
with:
script: |
const { repo, owner } = context.repo;
const title = '[Auto] Staging to main';
const {data:openPRs} = await await github.rest.pulls.list({
owner,
repo
});
const previouslyOpenedAutoPR = openPRs.filter(({title:_title}) => _title.includes(title));
if(previouslyOpenedAutoPR.length === 1) {
const pull_number = previouslyOpenedAutoPR[0].number;
await github.rest.pulls.update({
title,
owner,
repo,
pull_number,
head: '${{ github.ref_name }}',
base: 'main',
body: [
'This PR is auto-generated and updated by',
'[actions/github-script](https://github.com/actions/github-script).'
].join('\n')
});
return;
}
const result = await github.rest.pulls.create({
title,
owner,
repo,
head: '${{ github.ref_name }}',
base: 'main',
body: [
'This PR is auto-generated by',
'[actions/github-script](https://github.com/actions/github-script).'
].join('\n')
});
github.rest.issues.addLabels({
owner,
repo,
issue_number: result.data.number,
labels: ['automated']
});