Skip to content

jill64/octoflare

Repository files navigation

octoflare

ci.yml

🌤️ A framework for building GitHub Apps with Cloudflare Worker

Example Apps

workflow

Start New Project with CLI

npm create octoflare

Setup

The following must be set as environment variables for Cloudflare Workers

Key Value Recommend Encryption Auto Set by CLI
OCTOFLARE_APP_ID GitHub App ID
OCTOFLARE_PRIVATE_KEY_PKCS8 GitHub App private key converted to PKCS8 format ✔︎
OCTOFLARE_WEBHOOK_SECRET GitHub App Webhook Secret ✔︎
OCTOFLARE_APP_REPO GitHub App Repository Name ✔︎
OCTOFLARE_APP_OWNER GitHub App Repository Owner Name ✔︎

Convert Privatekey

Before using the private key provided by GitHub, you need to convert it to PKCS8 format with the command below.

openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in private-key.pem -out private-key-pkcs8.key

or Using Web Tool

Commands

npm script Description
npm run lint Lint
npm run format Format by Prettier
npm run build Build worker script
npm run deploy Deploy worker script to cloudflare
npm run build:action Build GitHub javascript action

Example

Worker

// src/index.js
import { octoflare } from 'octoflare'

export default octoflare(
  async ({ request, env, app, payload, installation }) => {
    // Application Code

    // Create Status Check for Target SHA
    const { dispatchWorkflow } = await installation.createCheckRun({
      repo: 'repository-name',
      owner: 'repository-owner',
      name: 'workflow-name',
      head_sha: 'target-sha'
    })

    await dispatchWorkflow({
      // ...
    })

    return new Response('Workflow Dispatched', {
      status: 200
    })
  }
)

Handler Type Definition

Action

// action/src/index.js
import { action } from 'octoflare'

action(({ request, env, app, payload }) => {
  // Application Code

  // Return Checks Status
  return {
    conclusion: 'success',
    output: {
      title: 'Check Success',
      summary: 'The check conclude as success'
    }
  }
})

License

MIT