GitHubSync
Script
999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { decodeBase64 } from "jsr:@std/encoding/base64";
import { ValTown } from "npm:@valtown/sdk";
import { Octokit } from "npm:@octokit/rest";
import config from "../config.json" with { type: "json" };
import type { Context, Next } from "npm:hono";
const GITHUB_TOKEN = Deno.env.get("GITHUB_TOKEN");
const VALTOWN_TOKEN = Deno.env.get("VALTOWN_TOKEN");
const valtown = new ValTown({
bearerToken: VALTOWN_TOKEN,
});
const octokit = new Octokit({ auth: GITHUB_TOKEN });
const td = new TextDecoder();
////
export default async function valTownDeploy(c: Context) {
console.log("deploy to valtown");
const body = await c.req.json();
const { ref, repository, after, commits } = body;
if (ref !== config.branch) {
console.log(`Update not on ${config.branch} branch (${ref})`);
return c.json({ ok: true });
}
try {
const updates = await getContents(repository, after, commits);
console.log(`${updates.length} updates`);
const user = await valtown.me.profile.retrieve();
if (!user.username) {
throw new Error("User not found: check your VALTOWN_TOKEN");
}
console.log("got val.town user:", user.username);
H
index