Skip to content

Commit

Permalink
ci: add create pull request action
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonos committed Dec 18, 2023
1 parent b713d10 commit 5a95b12
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,62 @@ jobs:

- name: Verify
run: yarn verify:android

create-pr:
runs-on: ubuntu-latest
needs: [lint, verify-ios, verify-android]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Create pull or update pull request
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const head = context.payload.ref.replace('refs/heads/', '');
const base = 'main';
const title = 'Merge ' + head + ' into ' + base + ' 🔀';
const body = 'This is an automated PR';
async function run() {
try {
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: context.repo.owner + ':' + head,
base: base
});
if (pulls.length > 0) {
const pullNumber = pulls[0].number;
console.log(`Updating existing PR #${pullNumber}`);
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullNumber,
title: title,
body: body
});
} else {
console.log('Creating new PR');
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
head: head,
base: base
});
}
} catch (error) {
console.error('Error processing pull request:', error);
throw error;
}
}
run();

0 comments on commit 5a95b12

Please sign in to comment.