Skip to content

Commit

Permalink
chore: create combined PR using GitHub app (#803)
Browse files Browse the repository at this point in the history
* Create combined PR using GitHub app

* Fix token attribute

* Fix API for creating pull request

Reference: https://octokit.github.io/rest.js/v18#pulls-create

* Grant token to push branch

* Revert "Grant token to push branch"

* Create branch via API

* Fix syntax

* Remove creation of ref

Signed-off-by: Aman Sharma <mannu.poski10@gmail.com>

* Prepend head with username

Signed-off-by: Aman Sharma <mannu.poski10@gmail.com>

* Revert "Prepend head with username"

This reverts commit 969f877.

* Revert "Remove creation of ref"

This reverts commit 89995b3.

* Fix sha to be the revision the branch has to be created from

Signed-off-by: Aman Sharma <mannu.poski10@gmail.com>

* Use fully qualified name of `master`

Signed-off-by: Aman Sharma <mannu.poski10@gmail.com>

* Fix syntax

Signed-off-by: Aman Sharma <mannu.poski10@gmail.com>

* Hardcode master's SHA1 hash

Signed-off-by: Aman Sharma <mannu.poski10@gmail.com>

* Simplify pushing branch

Signed-off-by: Aman Sharma <mannu.poski10@gmail.com>

* Configure GitHub App's token

Signed-off-by: Aman Sharma <mannu.poski10@gmail.com>

* Pass token

Signed-off-by: Aman Sharma <mannu.poski10@gmail.com>
  • Loading branch information
algomaster99 authored Jun 2, 2022
1 parent 51188f0 commit 44a9eb3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/combine-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ jobs:
# The type of runner that the job will run on
runs-on: ubuntu-latest

environment: 'Combine PR'

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- uses: actions/github-script@v6
id: fetch-branch-names
name: Fetch branch names
with:
github-token: ${{secrets.GITHUB_TOKEN}}
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const CI_TEST_THAT_NEEDS_TO_BE_GREEN = [
'codecov/patch',
Expand Down Expand Up @@ -111,8 +119,10 @@ jobs:
- uses: actions/checkout@v2.3.3
with:
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}
# Creates a branch with other PR branches merged together
- name: Created combined branch
id: combined-branch
env:
BASE_BRANCH: ${{ steps.fetch-branch-names.outputs.base-branch }}
BRANCHES_TO_COMBINE: ${{ steps.fetch-branch-names.outputs.result }}
Expand Down Expand Up @@ -141,11 +151,11 @@ jobs:
env:
PRS_STRING: ${{ steps.fetch-branch-names.outputs.prs-string }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const prString = process.env.PRS_STRING;
const body = 'This PR was created by the Combine PRs action by combining the following PRs:\n' + prString;
await github.pulls.create({
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Combined PR',
Expand Down

0 comments on commit 44a9eb3

Please sign in to comment.