Skip to content

Commit

Permalink
Merge pull request #11 from ubiquibot/return-data
Browse files Browse the repository at this point in the history
return data to kernel
  • Loading branch information
whilefoo authored Apr 15, 2024
2 parents 5673641 + 5dd237a commit ae6866f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
25 changes: 1 addition & 24 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,5 @@ jobs:

- name: Generate Permit
run: npx tsx ./src/index.ts
id: permit
env:
STATE_ID: ${{ github.event.inputs.stateId }}
EVENT_NAME: ${{ github.event.inputs.eventName }}
EVENT_PAYLOAD: ${{ github.event.inputs.eventPayload }}
SETTINGS: ${{ github.event.inputs.settings }}
AUTH_TOKEN: ${{ github.event.inputs.authToken }}
REF: ${{ github.event.inputs.ref }}

- name: Return Permit To The Kernel
uses: actions/github-script@v7
with:
script: |
const permitStr = '${{ steps.permit.outputs.result }}';
const permitObj = JSON.parse(permitStr);
await github.rest.repos.createDispatchEvent({
owner: "${{ github.repository }}".split("/")[0],
repo: "${{ github.repository }}".split("/")[1],
event_type: "return_data_to_ubiquibot_kernel",
client_payload: {
state_id: "${{ inputs.stateId }}",
output: JSON.stringify(permitObj),
},
});
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Binary file modified bun.lockb
Binary file not shown.
18 changes: 16 additions & 2 deletions src/generate-permits-from-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,27 @@ export async function generatePermitsFromContext() {
if (context.eventName === "issue_comment.created") {
await handleSlashCommands(context, octokit);
} else {
// TODO: return permits to kernel
return await generatePayoutPermit(context, settings.permitRequests);
const permits = await generatePayoutPermit(context, settings.permitRequests);
await returnDataToKernel(env.GITHUB_TOKEN, inputs.stateId, permits);
return JSON.stringify(permits);
}

return null;
}

async function returnDataToKernel(repoToken: string, stateId: string, output: object) {
const octokit = new Octokit({ auth: repoToken });
await octokit.repos.createDispatchEvent({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
event_type: "return_data_to_ubiquibot_kernel",
client_payload: {
state_id: stateId,
output: JSON.stringify(output),
},
});
}

async function handleSlashCommands(context: Context, octokit: Octokit) {
const payload = context.payload as Context<"issue_comment.created">["payload"];
const body = payload.comment.body;
Expand Down
1 change: 1 addition & 0 deletions src/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { StaticDecode } from "@sinclair/typebox";
import "dotenv/config";

export const envSchema = T.Object({
GITHUB_TOKEN: T.String(),
SUPABASE_URL: T.String(),
SUPABASE_KEY: T.String(),
NFT_MINTER_PRIVATE_KEY: T.String(),
Expand Down

0 comments on commit ae6866f

Please sign in to comment.