Skip to content

Commit

Permalink
feat: add open issue binding to test
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslice committed Jan 19, 2024
1 parent 3b82b09 commit 4de9077
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
generate png | https://cdn.modsurfer.dylibso.com/api/v1/module/2c9eb901052b1e6397d2414bdb796975407cc87085e6b5fe9564932538d8af51.wasm | handle
- name: check output
run: |
echo '${{steps.actism-image.outputs.output}}' | jq '.value' | base64 -d -i > out.png
echo '${{ steps.actism-image.outputs.output }}' | jq '.value' | base64 -d -i > out.png
- uses: actions/upload-artifact@v4
with:
name: out.png
Expand All @@ -46,4 +46,14 @@ jobs:
count vowels | https://github.com/extism/plugins/releases/latest/download/count_vowels.wasm | count_vowels
- name: check output
run: |
echo '${{steps.actism-text.outputs.output}}' | grep '"count":4'
echo '${{ steps.actism-text.outputs.output }}' | grep '"count":4'
- uses: ./
id: actism-open-issue
with:
wasi: true
input: ''
output_type: text
github_token: ${{ secrets.GITHUB_TOKEN }}
steps: |-
test open issue | https://cdn.modsurfer.dylibso.com/api/v1/module/2ab8f671a0334e7da92c9cd8e0cca0dd710930e6019319126b6bed06aad342e9.wasm
26 changes: 23 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ async function actism(input, steps, wasi, outputType, test) {
}
steps = steps.trim();
outputType = outputType.trim();

let githubToken;
if (!test) {
githubToken = core.getInput('github_token');
}
if (githubToken) {
githubToken = githubToken.trim();
}

// for each step, run the step() function in the module with the input from the previous step
let pipelineData = input;
Expand All @@ -32,7 +40,7 @@ async function actism(input, steps, wasi, outputType, test) {
console.log(`Starting step: ${step.name} from ${step.source}`)
const plugin = await createPlugin(step.source, {
useWasi: wasi,
functions: { "extism:host/user": ActionsBindings() }
functions: { "extism:host/user": ActionsBindings(githubToken) }
});
const output = await plugin.call(step.entrypoint, pipelineData);
pipelineData = output.bytes();
Expand Down Expand Up @@ -63,12 +71,24 @@ const Steps = (input) => {
})
}

const ActionsBindings = () => {
const ActionsBindings = (githubToken) => {
const hostFuncs = {};

const octokit = github.getOktokit(githubToken);

hostFuncs.github_context = (pluginCaller, offset) => {
hostFuncs.github_context = (plugin) => {
return pluginCaller.store("githubContext = " + JSON.stringify(github.context));
};

hostFuncs.github_open_issue = (plugin, titleOffs, bodyOffs) => {
const title = plugin.read(titleOffs).text();
const body = plugin.read(bodyOffs).text();
octokit.rest.issues.create({
...github.context.repo,
title,
body
});
}

return hostFuncs;
}
Expand Down

0 comments on commit 4de9077

Please sign in to comment.