MikeM
Windmillโ€ข2y agoโ€ข
41 replies
Mike

Trouble committing file to GitHub but only in bun runtime

I'm trying to create a script to commit font files into my github repository. This is code that is migrated over from airplane.dev. Initially i created the code using the Deno runtime, this works but I want to use fontkit, which does not support the "import ... from ..." imports.

So the following code WORKS:

import * as wmill from "npm:windmill-client@1";
import { Octokit } from "npm:@octokit/rest@20.0.2";

export async function main(
  font_file: wmill.Base64,
  font_name: string,
  font_type: string,
) {
  const octokit = new Octokit({
    auth: (await wmill.getVariable("f/COMPANY/GITHUB_TOKEN")),
  });

  const acceptedFileTypes = ["otf", "ttf"];

  if (acceptedFileTypes.includes(font_type) && font_name && font_name !== "") {
    const result = await octokit.repos.createOrUpdateFileContents({
      owner: "OWNER",
      repo: "REPO",
      path: 'PATH',
      message: 'MESSAGE',
      content: font_file,
    });

    const res = await fetch(
      "ENDPOINT TO NOTIFY FILE IS UPLOAD, NOT RELEVANT FOR THIS ISSUE",
    );

    const responseText = res.text();

    return responseText || 500;
  } else {
    return "error: unsupported file extension, must be otf or ttf.";
  }
}
Was this page helpful?