Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jill64/octoflare

🌤️ A framework for building GitHub Apps with Cloudflare Worker
https://github.com/jill64/octoflare

actions cloudflare framework github worker

Last synced: 5 days ago
JSON representation

🌤️ A framework for building GitHub Apps with Cloudflare Worker

Awesome Lists containing this project

README

        

# octoflare

ci.yml

🌤️ A framework for building GitHub Apps with Cloudflare Worker

[Example Apps](https://github.com/jill64?tab=repositories&q=github-app&type=&language=&sort=stargazers)

![workflow](./docs/workflow.png)

## Start New Project with CLI

```sh
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.

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

or Using [Web Tool](https://decoder.link/rsa_converter)

## 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

```js
// 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](./packages/octoflare/src/types/OctoflareHandler.ts)

### Action

```js
// 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](LICENSE)