-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a57e3af
commit 8ceab40
Showing
20 changed files
with
308 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/app/ecosystem-explorer/project-form/actions/buildMarkdownTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use server' | ||
|
||
import { encrypt } from '@/utils/encryption' | ||
|
||
import type { FormattedFormData } from '../utils/formatFormData' | ||
import { getEcosystemMarkdownTemplate } from '../utils/getEcosystemMarkdownTemplate' | ||
|
||
type Timestamps = { | ||
createdOn: Date | ||
updatedOn: Date | ||
publishedOn: Date | ||
} | ||
|
||
type MarkdownTemplateParams = { | ||
formattedData: FormattedFormData | ||
imagePath: string | ||
timestamps: Timestamps | ||
} | ||
|
||
export async function buildMarkdownTemplate({ | ||
formattedData, | ||
imagePath, | ||
timestamps, | ||
}: MarkdownTemplateParams) { | ||
return getEcosystemMarkdownTemplate({ | ||
encryptedEmail: encrypt(formattedData.email), | ||
encryptedName: encrypt(formattedData.name), | ||
projectName: formattedData.projectName, | ||
imagePath, | ||
category: formattedData.category, | ||
subcategories: formattedData.subcategories, | ||
tech: formattedData.tech, | ||
shortDescription: formattedData.shortDescription, | ||
longDescription: formattedData.longDescription, | ||
yearJoined: formattedData.yearJoinedISO, | ||
websiteUrl: formattedData.websiteUrl, | ||
youtubeUrl: formattedData.youtubeEmbedUrl, | ||
githubUrl: formattedData.githubUrl, | ||
xUrl: formattedData.xUrl, | ||
createdOn: timestamps.createdOn.toISOString(), | ||
updatedOn: timestamps.updatedOn.toISOString(), | ||
publishedOn: timestamps.publishedOn.toISOString(), | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 75 additions & 76 deletions
151
src/app/ecosystem-explorer/project-form/actions/submitProjectToGithub.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,114 @@ | ||
'use server' | ||
|
||
import slugify from 'slugify' | ||
import { ECOSYSTEM_PROJECTS_DIRECTORY_PATH } from '@/constants/paths' | ||
|
||
import { getTodayISO } from '@/utils/dateUtils' | ||
import { encrypt } from '@/utils/encryption' | ||
|
||
import { createBlob } from '../services/github/api/createBlob' | ||
import { createCommit } from '../services/github/api/createCommit' | ||
import { createPR } from '../services/github/api/createPr' | ||
import { createTreeBlobs } from '../services/github/api/createTreeBlobs' | ||
import { getLatestCommitOnMain } from '../services/github/api/getLatestCommitOnMain' | ||
import type { AllowedImageFormats } from '../services/github/utils/fileUtils' | ||
import { | ||
getMarkdownTemplate, | ||
type MarkdownTemplateParams, | ||
} from '../services/github/utils/markdownUtils' | ||
import { getFolderPaths } from '../services/github/utils/pathUtils' | ||
|
||
export type ProjectData = { | ||
name: string | ||
email: string | ||
timestampISO: string | ||
yearJoinedISO: string | ||
projectName: MarkdownTemplateParams['projectName'] | ||
category: MarkdownTemplateParams['category'] | ||
subcategories: MarkdownTemplateParams['subcategories'] | ||
tech: MarkdownTemplateParams['tech'] | ||
shortDescription: MarkdownTemplateParams['shortDescription'] | ||
longDescription: MarkdownTemplateParams['longDescription'] | ||
websiteUrl: MarkdownTemplateParams['websiteUrl'] | ||
youtubeEmbedUrl: MarkdownTemplateParams['youtubeUrl'] | ||
githubUrl: MarkdownTemplateParams['githubUrl'] | ||
xUrl: MarkdownTemplateParams['xUrl'] | ||
} | ||
|
||
type ProjectLogo = { | ||
base64: string | ||
format: AllowedImageFormats | ||
} | ||
import type { FormattedLogo } from '../utils/fileUtils' | ||
|
||
type SubmitProjectParams = { | ||
data: ProjectData | ||
logo: ProjectLogo | ||
slug: string | ||
markdownTemplate: string | ||
logo?: { | ||
path: string | ||
base64: FormattedLogo['base64'] | ||
} | ||
} | ||
|
||
export async function submitProjectToGithub({ | ||
data, | ||
slug, | ||
markdownTemplate, | ||
logo, | ||
}: SubmitProjectParams) { | ||
const { mediaFolder, ecosystemFolder, publicFolder } = getFolderPaths() | ||
const todayISO = getTodayISO() | ||
|
||
const slug = slugify(data.projectName, { | ||
lower: true, | ||
strict: true, | ||
}) | ||
|
||
const branchName = `ecosystem-submission/${slug}-${todayISO}` | ||
|
||
const markdownTemplate = getMarkdownTemplate({ | ||
encryptedEmail: encrypt(data.email), | ||
encryptedName: encrypt(data.name), | ||
projectName: data.projectName, | ||
imagePath: `${publicFolder}/${slug}.${logo.format}`, | ||
category: data.category, | ||
subcategories: data.subcategories, | ||
tech: data.tech, | ||
shortDescription: data.shortDescription, | ||
longDescription: data.longDescription, | ||
yearJoined: data.yearJoinedISO, | ||
websiteUrl: data.websiteUrl, | ||
youtubeUrl: data.youtubeEmbedUrl, | ||
githubUrl: data.githubUrl, | ||
xUrl: data.xUrl, | ||
createdOn: data.timestampISO, | ||
updatedOn: data.timestampISO, | ||
publishedOn: data.timestampISO, | ||
}) | ||
const markdownBlob = await createBlob(markdownTemplate, 'utf-8') | ||
const treeBlobs = [ | ||
{ | ||
path: `${ECOSYSTEM_PROJECTS_DIRECTORY_PATH}/${slug}.md`, | ||
sha: markdownBlob.sha, | ||
}, | ||
] | ||
|
||
if (logo) { | ||
const imageBlob = await createBlob(logo.base64, 'base64') | ||
treeBlobs.push({ | ||
sha: imageBlob.sha, | ||
path: logo.path, | ||
}) | ||
} | ||
|
||
const latestCommitOnMain = await getLatestCommitOnMain() | ||
|
||
const [markdownBlob, imageBlob] = await Promise.all([ | ||
createBlob(markdownTemplate, 'utf-8'), | ||
createBlob(logo.base64, 'base64'), | ||
]) | ||
|
||
const newTree = await createTreeBlobs({ | ||
baseTreeSha: latestCommitOnMain.commit.tree.sha, | ||
newBlobs: [ | ||
{ | ||
path: `${mediaFolder}/${slug}.${logo.format}`, | ||
sha: imageBlob.sha, | ||
}, | ||
{ | ||
path: `${ecosystemFolder}/${slug}.md`, | ||
sha: markdownBlob.sha, | ||
}, | ||
], | ||
newBlobs: treeBlobs, | ||
}) | ||
|
||
const newCommit = await createCommit({ | ||
parentCommitSha: latestCommitOnMain.sha, | ||
treeSha: newTree.sha, | ||
message: `Ecosystem Project Form Submission: ${data.projectName}`, | ||
message: `Ecosystem Project Form Submission: ${slug}`, | ||
}) | ||
|
||
const newPullRequest = await createPR({ | ||
title: `Ecosystem Project Form Submission: ${data.projectName}`, | ||
title: `Ecosystem Project Form Submission: ${slug}`, | ||
commitSha: newCommit.sha, | ||
branchName, | ||
}) | ||
|
||
return newPullRequest | ||
} | ||
|
||
// const markdownTemplate = getEcosystemMarkdownTemplate({ | ||
// encryptedEmail: encrypt(data.email), | ||
// encryptedName: encrypt(data.name), | ||
// projectName: projectName, | ||
// imagePath: `${assetsFolder}/${slug}.${formattedLogo.format}`, | ||
// category: data.category, | ||
// subcategories: data.subcategories, | ||
// tech: data.tech, | ||
// shortDescription: data.shortDescription, | ||
// longDescription: data.longDescription, | ||
// yearJoined: data.yearJoinedISO, | ||
// websiteUrl: data.websiteUrl, | ||
// youtubeUrl: data.youtubeEmbedUrl, | ||
// githubUrl: data.githubUrl, | ||
// xUrl: data.xUrl, | ||
// createdOn: data.timestampISO, | ||
// updatedOn: data.timestampISO, | ||
// publishedOn: data.timestampISO, | ||
// }) | ||
|
||
// import { | ||
// getEcosystemMarkdownTemplate, | ||
// type MarkdownTemplateParams, | ||
// } from '../utils/getEcosystemMarkdownTemplate' | ||
|
||
// type ProjectData = { | ||
// name: string | ||
// email: string | ||
// timestampISO: string | ||
// yearJoinedISO: string | ||
// projectName: MarkdownTemplateParams['projectName'] | ||
// category: MarkdownTemplateParams['category'] | ||
// subcategories: MarkdownTemplateParams['subcategories'] | ||
// tech: MarkdownTemplateParams['tech'] | ||
// shortDescription: MarkdownTemplateParams['shortDescription'] | ||
// longDescription: MarkdownTemplateParams['longDescription'] | ||
// websiteUrl: MarkdownTemplateParams['websiteUrl'] | ||
// youtubeEmbedUrl: MarkdownTemplateParams['youtubeUrl'] | ||
// githubUrl: MarkdownTemplateParams['githubUrl'] | ||
// xUrl: MarkdownTemplateParams['xUrl'] | ||
// } | ||
|
||
// type ProjectLogo = { | ||
// base64: string | ||
// format: AllowedImageFormats | ||
// } |
56 changes: 0 additions & 56 deletions
56
src/app/ecosystem-explorer/project-form/actions/updateProjectOnGitHub.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.