Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding static website application #2481

Merged
merged 20 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playground/src/constants/deployment_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const deploymentListEnvironments = {

static_website: {
SSH_KEY: _ssh,
GITHUB_URL: "Cloned Repository URL",
GITHUB_URL: "Cloned Repository https URL",
zaelgohary marked this conversation as resolved.
Show resolved Hide resolved
ROOT: "HTML Directory",
},

Expand Down
8 changes: 0 additions & 8 deletions packages/playground/src/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ export function maxLength(msg: string, max: number) {
};
}

export function isGithubRepo(msg: string) {
return (value: string) => {
const githubRepoRegex = /^https:\/\/github\.com\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)\.git$/;
if (!githubRepoRegex.test(value)) {
return { message: msg };
}
};
}
export function equal(msg: string, length: number) {
return (value: string) => {
if (value.length !== length) {
Expand Down
44 changes: 24 additions & 20 deletions packages/playground/src/weblets/tf_staticwebsite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,23 @@
</input-validator>

<input-validator
:value="githubUrl"
:value="gitUrl"
:rules="[
validators.required('Github Repository is required.'),
validators.isGithubRepo('Github Repository must be a valid URL'),
validators.required('Git https URL is required.'),
validators.isURL('Git URL must be a valid https URL.', {
protocols: ['https'],
}),
]"
:async-rules="[isGithubRepoExist]"
#="{ props }"
>
<input-tooltip tooltip="Github Repository https url to serve.">
<v-text-field label="Github Repository" v-model="githubUrl" v-bind="props" />
<input-tooltip tooltip="Git https url to serve.">
<v-text-field label="Git URL" v-model="gitUrl" v-bind="props" />
</input-tooltip>
</input-validator>

<input-tooltip tooltip="Github Branch name to serve (optional).">
<v-text-field label="Github Branch" v-model="githubBranch" />
<input-tooltip tooltip="Git Branch name to serve (optional).">
<v-text-field label="Git Branch" v-model="gitBranch" />
</input-tooltip>
<input-tooltip
tooltip="HTML directory to be served. Please ensure correct casing, as this field is case-sensitive. If the directory is the root of the repository, it should not be added."
Expand Down Expand Up @@ -113,8 +115,8 @@ const layout = useLayout();
const valid = ref(false);
const profileManager = useProfileManager();
const name = ref(generateName({ prefix: "sw" }));
const githubUrl = ref("");
const githubBranch = ref("");
const gitUrl = ref("");
const gitBranch = ref("");
const root = ref("");
const domain = ref();

Expand Down Expand Up @@ -193,8 +195,8 @@ async function deploy() {
mycelium: mycelium.value,
envs: [
{ key: "SSH_KEY", value: selectedSSHKeys.value },
{ key: "GITHUB_URL", value: githubUrl.value },
{ key: "GITHUB_BRANCH", value: githubBranch.value },
{ key: "GITHUB_URL", value: gitUrl.value },
{ key: "GITHUB_BRANCH", value: gitBranch.value },
{ key: "HTML_DIR", value: root.value ? "website/" + root.value : "website" },
{ key: "USER_DOMAIN", value: selectionDetails.value?.domain?.enabledCustomDomain ? domain.value : "" },
{ key: "STATICWEBSITE_DOMAIN", value: domain.value },
Expand Down Expand Up @@ -235,16 +237,18 @@ async function deploy() {
finalize(vm);
}

async function isGithubRepoExist(githubUrl: string) {
try {
const username = githubUrl.substring("https://github.com/".length, githubUrl.lastIndexOf("/"));

const reponame = githubUrl.substring(githubUrl.lastIndexOf("/") + 1, githubUrl.lastIndexOf(".git"));
async function isGithubRepoExist(gitUrl: string) {
if (gitUrl.includes("github.com")) {
try {
gitUrl = gitUrl.replace("https://github.com", "");
gitUrl = gitUrl.replace("/", "");
gitUrl = gitUrl.replace(".git", "");

const res = await fetch("https://api.github.com/repos/" + username + "/" + reponame);
if (res.status !== 200) throw new Error();
} catch (error) {
return { message: `Github repository doesn't exist.`, isExist: false };
const res = await fetch("https://api.github.com/repos/" + gitUrl);
if (res.status !== 200) throw new Error();
} catch (error) {
return { message: `Github repository doesn't exist.`, isExist: false };
}
}
}
</script>
Expand Down
Loading