2020-05-25 21:30:55 -05:00
|
|
|
import * as DataModels from "../Contracts/DataModels";
|
|
|
|
import { config } from "../Config";
|
2020-05-26 13:53:41 -05:00
|
|
|
import { RepoListItem } from "../Explorer/Controls/GitHub/GitHubReposComponent";
|
|
|
|
import { IPinnedRepo } from "../Juno/JunoClient";
|
|
|
|
import { IGitHubRepo } from "../GitHub/GitHubClient";
|
2020-05-25 21:30:55 -05:00
|
|
|
|
|
|
|
export class JunoUtils {
|
|
|
|
public static async getLikedNotebooks(authorizationToken: string): Promise<DataModels.LikedNotebooksJunoResponse> {
|
|
|
|
//TODO: Add Get method once juno has it implemented
|
|
|
|
return {
|
2020-06-05 04:04:15 +02:00
|
|
|
likedNotebooksContent: [],
|
2020-05-25 21:30:55 -05:00
|
|
|
userMetadata: {
|
|
|
|
likedNotebooks: []
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-05 04:04:15 +02:00
|
|
|
public static async getOfficialSampleNotebooks(
|
|
|
|
authorizationToken: string
|
|
|
|
): Promise<DataModels.GitHubInfoJunoResponse[]> {
|
2020-05-25 21:30:55 -05:00
|
|
|
try {
|
2020-06-05 04:04:15 +02:00
|
|
|
const response = await window.fetch(config.JUNO_ENDPOINT + "/api/notebooks/galleries", {
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
authorization: authorizationToken
|
|
|
|
}
|
2020-05-25 21:30:55 -05:00
|
|
|
});
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error("Status code:" + response.status);
|
|
|
|
}
|
|
|
|
return await response.json();
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error("Official samples fetch failed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async updateUserMetadata(
|
|
|
|
authorizationToken: string,
|
|
|
|
userMetadata: DataModels.UserMetadata
|
|
|
|
): Promise<DataModels.UserMetadata> {
|
|
|
|
return undefined;
|
|
|
|
//TODO: add userMetadata updation code
|
2020-06-05 04:04:15 +02:00
|
|
|
// TODO: Make sure to throw error if failed
|
2020-05-25 21:30:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public static async updateNotebookMetadata(
|
|
|
|
authorizationToken: string,
|
2020-06-05 04:04:15 +02:00
|
|
|
notebookMetadata: DataModels.NotebookMetadata
|
2020-05-25 21:30:55 -05:00
|
|
|
): Promise<DataModels.NotebookMetadata> {
|
|
|
|
return undefined;
|
|
|
|
//TODO: add notebookMetadata updation code
|
2020-06-05 04:04:15 +02:00
|
|
|
// TODO: Make sure to throw error if failed
|
2020-05-25 21:30:55 -05:00
|
|
|
}
|
2020-05-26 13:53:41 -05:00
|
|
|
|
|
|
|
public static toPinnedRepo(item: RepoListItem): IPinnedRepo {
|
|
|
|
return {
|
|
|
|
owner: item.repo.owner.login,
|
|
|
|
name: item.repo.name,
|
|
|
|
private: item.repo.private,
|
|
|
|
branches: item.branches.map(element => ({ name: element.name }))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static toGitHubRepo(pinnedRepo: IPinnedRepo): IGitHubRepo {
|
|
|
|
return {
|
|
|
|
owner: {
|
|
|
|
login: pinnedRepo.owner
|
|
|
|
},
|
|
|
|
name: pinnedRepo.name,
|
|
|
|
private: pinnedRepo.private
|
|
|
|
};
|
|
|
|
}
|
2020-05-25 21:30:55 -05:00
|
|
|
}
|