Vals using @octokit/rest
valToGH
A utility function for programmatically updating a GitHub repository with code retrieved from a Val.
NOTE: This function currently does not change the contents of a file if it is already present. I will however be adding that functionality.
Usage
Create valimport { valToGH } from 'https://esm.town/v/nbbaier/valToGH';
const repo = "yourGitHubUser/yourRepo";
const val = "valUser/valName"; // or vals = ["valUser/valName1","valUser/valName2", ...]
const ghToken = Deno.env.get("yourGitHubToken");
const result = await valToGH(repo, val, ghToken);
console.log(result);
Parameters
repo
: The GitHub repository in the format{user}/{repo}
.val
: A single repository in the format{user}/{val}
.ghToken
: Your GitHub token for authentication (must have write permission to the target repo)
Options
branch
: Optional target branch. Default ismain
.prefix
: Optional directory path prefix for each file.message
: Optional commit message. Default is the current date and time in the formatyyyy-MM-dd T HH:mm:ss UTC
.ts
: Optional flag to use a.ts
extension for the committed file instead of the default.tsx
.
githubRestClient
Does what it says! Defaults to using GITHUB_TOKEN
env var if none is passed to the function.
Submit a PR from Val Town
This val provides a (very) thin wrapper around the GH rest API methods for creating a pull request. It handles the creation of a Octokit client for you.
Usage
Create valimport { submitPR } from "https://esm.town/v/nbbaier/submitPR";
await submitPR(Deno.env.get("GH_REPO_TOKEN"), {
owner: "nbbaier",
repo: "test-ground",
head: "branch_2",
base: "main",
title: "trying another PR",
body: "cool stuff, take a look",
});
Parameters
The function takes two parameters: your gh access token and an object that's identical to the object submitted to the gh API. See GH's documentation for more info!
valToGH
A utility function for programmatically updating a GitHub repository with code retrieved from a Val.
NOTE: This function currently does not change the contents of a file if it is already present. I will however be adding that functionality.
Usage
Create valimport { valToGH } from 'https://esm.town/v/nbbaier/valToGH';
const repo = "yourGitHubUser/yourRepo";
const val = "valUser/valName"; // or vals = ["valUser/valName1","valUser/valName2", ...]
const ghToken = Deno.env.get("yourGitHubToken");
const result = await valToGH(repo, val, ghToken);
console.log(result);
Parameters
repo
: The GitHub repository in the format{user}/{repo}
.val
: A single repository in the format{user}/{val}
.ghToken
: Your GitHub token for authentication (must have write permission to the target repo)
Options
branch
: Optional target branch. Default ismain
.prefix
: Optional directory path prefix for each file.message
: Optional commit message. Default is the current date and time in the formatyyyy-MM-dd T HH:mm:ss UTC
.ts
: Optional flag to use a.ts
extension for the committed file instead of the default.tsx
.