File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Octokit } from "octokit" ;
2+
3+ const octokit = new Octokit ( {
4+ auth : process . env . GITHUB_TOKEN ,
5+ } ) ;
6+
7+ export async function getLatestRelease ( owner : string , repo : string ) {
8+ const { data : latestRelease } = await octokit . rest . repos . getLatestRelease ( {
9+ owner,
10+ repo,
11+ } ) ;
12+ return latestRelease ;
13+ }
14+
15+ export async function getCommit ( owner : string , repo : string , ref : string ) {
16+ const { data : commit } = await octokit . rest . repos . getCommit ( {
17+ owner,
18+ repo,
19+ ref,
20+ } ) ;
21+ return commit ;
22+ }
23+
24+ export async function getFileContent (
25+ owner : string ,
26+ repo : string ,
27+ ref : string ,
28+ path : string ,
29+ ) {
30+ const { data : content } = await octokit . rest . repos . getContent ( {
31+ owner,
32+ repo,
33+ ref,
34+ path,
35+ } ) ;
36+
37+ if ( Array . isArray ( content ) ) {
38+ throw new Error ( "Expected a single file, got a directory" ) ;
39+ }
40+
41+ if ( content . type !== "file" ) {
42+ throw new Error ( `Expected a file, got a ${ content . type } ` ) ;
43+ }
44+
45+ if ( content . encoding !== "base64" ) {
46+ throw new Error ( `Expected base64 encoding, got ${ content . encoding } ` ) ;
47+ }
48+
49+ return Buffer . from ( content . content , "base64" ) . toString ( "utf-8" ) ;
50+ }
You can’t perform that action at this time.
0 commit comments