Fetch templates and header files according to selection.
This commit is contained in:
@@ -4,6 +4,8 @@ import state from '../index';
|
||||
|
||||
const octokit = new Octokit();
|
||||
|
||||
const HEADER_GIST_ID = '9b448e8a55fab11ef5d1274cb59f9cf3'
|
||||
|
||||
/* Fetches Gist files from Githug Gists based on
|
||||
* gistId and stores the content in global state
|
||||
*/
|
||||
@@ -17,6 +19,14 @@ export const fetchFiles = (gistId: string) => {
|
||||
|
||||
octokit
|
||||
.request("GET /gists/{gist_id}", { gist_id: gistId })
|
||||
.then(res => {
|
||||
// fetch header file(s) and append to res
|
||||
return octokit.request("GET /gists/{gist_id}", { gist_id: HEADER_GIST_ID }).then(({ data: { files: headerFiles } }) => {
|
||||
const files = { ...res.data.files, ...headerFiles }
|
||||
res.data.files = files
|
||||
return res
|
||||
})
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.files && Object.keys(res.data.files).length > 0) {
|
||||
const files = Object.keys(res.data.files).map((filename) => ({
|
||||
@@ -44,6 +54,7 @@ export const fetchFiles = (gistId: string) => {
|
||||
state.loading = false;
|
||||
})
|
||||
.catch((err) => {
|
||||
// console.error(err)
|
||||
state.loading = false;
|
||||
state.logs.push({
|
||||
type: "error",
|
||||
|
||||
Reference in New Issue
Block a user