-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (32 loc) · 1.52 KB
/
index.js
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
37
38
39
40
41
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({
auth: GH_AUTH,
});
addEventListener('fetch', event => {
const { request } = event
return event.respondWith(handleRequest(request))
})
async function handleRequest(request) {
// Handled by the Guild Scribe: Get the {owner: string; repo: string;} & First Issue information from POST coming from Guild Scribe
// The following steps are handled by the worker:
//* TODO:
//* 1. Use First Issue Config to know what data to parse (file types) (other configs Raid Leader, Repo Name, Raid Name)
//* 2. Take parsed repo from GH Octokit (content URL to Array [{RawUrl}]: DirectoriesInRepo RawURL gives the file content)
// Get the contents URL for the passed repo
const rawResponse = await octokit.repos.getContent({ owner: 'OpenSourceRaidGuild', repo: 'TEST', path: '' })
const { data: allRefs } = rawResponse;
// Get the download URLS for each file at that path
const downloadURLs = allRefs.map(ref => ref.download_url);
// Get the contents of those files
const rawFileContents = downloadURLs.map(async url => await (await fetch(url)));
// settle array of Promises for rawFileContents
const settlePromisesFiles = await Promise.all(rawFileContents);
const fileContents = settlePromisesFiles.map(rawFile => rawFile.body)
console.log(fileContents)
return new Response(fileContents, {
headers: { 'Content-Type': 'application/json' },
})
// TODO:
//* 3. Utilize the file content and file name to generate a issue using the GH Octokit
// octokit.issues.create()
}