Skip to content

danillouz/github-pr-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub PR Bot

🤖 commits a single file and sends a pull request.

It requires a GitHub App to be configured.

How

The bot creates a new commit from a base on a separate branch (referenced as head). It then creates a pull request that will pull in the changes from the head branch, e.g. feature-a, to the base branch, e.g. master.

Configuration

The bot is configured with the following environment variables, which are all required:

NAME DESCRIPTION
APP_ID The ID of the GitHub App you wish to use for this workflow. The App ID can be retrieved after creating the GitHub App from the settings page (in the "About" section). More information can be found here.
PRIVATE_KEY* The private key of the GitHub App you wish to use for this workflow. GitHub Apps require a private key to sign access token requests. GitHub allows you to create and download private keys in PEM format. More information can be found here.
REPO_NAME The name of the GitHub repository onto which this workflow will be applied to.
BRANCH_BASE The name of the branch you want the changes pulled into. More information can be found here.
BRANCH_HEAD The name of the branch where the changes will be implemented. More information can be found here.
COMMIT_PATH The path of the file to be commited. More information can be found here.
COMMIT_CONTENT The new content of the file to be commited, which must contain the entire file content. More information can be found here.
COMMIT_MSG The message that describes the commit. More information can be found here.
PR_TITLE The title of the pull request. More information can be found here.
PR_TEXT The textual body of the pull request. More information can be found here.

* The easiest way to pass the PRIVATE_KEY is by loading it from a path, for example:

PRIVATE_KEY="$(cat ./private-key.pem)"

If you can't load the private key from a path, you can convert your PEM file to a string by running:

$ awk '$1=$1' ORS='\\n' ./private-key.pem

Note that when the PRIVATE_KEY is passed as a string, the contents of the PEM file must be a single string with escaped newlines. For example:

PRIVATE_KEY='-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAtyHGso4MKnOStVYItxY+tDF1rY4QNdr34vqH9HfYen5A/wL+\nKczXb75pZ80Skq1M8PmhC2KXHRsBT6GujF2mjCVkjyJRxmLN8JYh8aQFHTS5YxFK\nQMHhbJ7jnPMFr7El7Z5UrsURFGJGSIPdl8/wsLCbrwGBp5OLQy0qPvD6X/WTstHy\ndf6fSfp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rbdD3CKxtQWCv9B7iWxdxIkt5K66ad1aINRm\ncwnBnUKXdjWVG9hmFzm7hAoefkw1te6kfuBCvKIr5yw3HKgoXhaL+Hqw+G35u+g2\nyu0K8KvQ4zdhBLSSHVk+r6OkgrjKeXfznqIu01/2StKBP5YQwm/A9sv4GLMOhpae\nuFHHeQKBgCL+i7BL/yQ/Hyo3PmtRgJq4Gfr/OMTKFF+usjhRA07u0zqZMZT0orUY\nzyZRB4awwlkhsOcjn2aPU/fj6uHg4e6tmsoSTaBbK/PArrN9ClYgeh/zlTj1dI5m\nWW39azEwfga5UnZEJJbNTIt1/Rq7nhW3+73QMCxkeM7mwT8ZfBcN\n-----END RSA PRIVATE KEY-----\n'

The private key is not active and just serves for example purposes.

Example NodeJS

APP_ID='12345' \
PRIVATE_KEY="$(cat ./private-key.pem)"
REPO_NAME='my-repo' \
BRANCH_BASE='master' \
BRANCH_HEAD='update-config-1234567890' \
COMMIT_PATH='k8s/deployment.yaml' \
COMMIT_CONTENT='apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test
  namespace: test
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: test
        version: v1
    spec:
      containers:
      - image: danillouz/docker-say:1.0.1
        name: test
        ports:
        - containerPort: 8888' \
COMMIT_MSG='Update infra config with new image' \
PR_TITLE='Update Infra Config' \
PR_TEXT='This commit updates the deployment image to `danillouz/docker-say:1.0.1`.' \
node src/index.js

Example Docker

docker run \
-e APP_ID='12345' \
-e PRIVATE_KEY="$(cat ./private-key.pem)"
-e REPO_NAME='my-repo' \
-e BRANCH_BASE='master' \
-e BRANCH_HEAD='update-config-1234567890' \
-e COMMIT_PATH='k8s/deployment.yaml' \
-e COMMIT_CONTENT='apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test
  namespace: test
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: test
        version: v1
    spec:
      containers:
      - image: danillouz/docker-say:1.0.1
        name: test
        ports:
        - containerPort: 8888' \
-e COMMIT_MSG='Update infra config with new image' \
-e PR_TITLE='Update Infra Config' \
-e PR_TEXT='This commit updates the deployment image to `danillouz/docker-say:1.0.1`.' \
danillouz/github-pr-bot

Releases

No releases published

Packages

No packages published