Skip to content

Commit

Permalink
Refactor summary processing
Browse files Browse the repository at this point in the history
Co-authored-by: Kaspar Emanuel <[email protected]>
  • Loading branch information
2 people authored and AbdulrhmnGhanem committed Oct 27, 2022
1 parent a459ce5 commit 026cf4d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
4 changes: 2 additions & 2 deletions e2e/cypress/integration/readme.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Readme style', () => {
})
})

it('should render :emoji: in readme and project description', () => {
it('renders :emoji: in readme and project description', () => {
const username = getFakeUsername()
const email = faker.unique(faker.internet.email)
const password = '123456'
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('Readme style', () => {
cy.get('[data-cy=readme]').should('contain.text', '🤓')
})

it('should not modify the urls for GitHub Actions badges', () => {
it('preserves URLs for GitHub Actions badges', () => {
const username = getFakeUsername()
const email = faker.unique(faker.internet.email)
const password = '123456'
Expand Down
50 changes: 26 additions & 24 deletions processor/src/tasks/writeKitspaceYaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,48 @@ import remarkRehype from 'remark-rehype'
import { JobData } from '../jobData.js'
import * as utils from '../utils.js'


export default async function writeKitspaceYaml(
job,
{ kitspaceYaml, outputDir }: Partial<JobData>,
) {
const kitspaceYamlJson = path.join(outputDir, 'kitspace-yaml.json')
job.updateProgress({ status: 'in_progress', file: kitspaceYamlJson })
const KitspaceYamlJsonLinkified = await linkifyKitspaceYaml(kitspaceYaml)

const rendered = await renderKitspaceYamlSummaries(kitspaceYaml)

return utils
.writeFile(kitspaceYamlJson, JSON.stringify(KitspaceYamlJsonLinkified, null, 2))
.writeFile(kitspaceYamlJson, JSON.stringify(rendered, null, 2))
.then(() => job.updateProgress({ status: 'done', file: kitspaceYamlJson }))
.catch(error =>
job.updateProgress({ status: 'failed', file: kitspaceYamlJson, error }),
)
}

async function linkifyKitspaceYaml(kitspaceYaml) {
async function renderKitspaceYamlSummaries(kitspaceYaml) {
if (kitspaceYaml.multi) {
const linkifiedKitspaceYaml = kitspaceYaml
Object.keys(kitspaceYaml.multi).forEach(async subProject => {
linkifiedKitspaceYaml.multi[subProject] = await renderProjectSummary(kitspaceYaml.multi[subProject])
})
return linkifiedKitspaceYaml
const rendered = { multi: {} }
for (const key of kitspaceYaml.multi) {
const subProject = kitspaceYaml.multi[key]
rendered.multi[subProject] = {
...subProject,
summary: await renderSummary(subProject.summary),
}
}
return rendered
}
return renderProjectSummary(kitspaceYaml)
return { ...kitspaceYaml, summary: await renderSummary(kitspaceYaml.summary) }
}

async function renderProjectSummary(kitspaceYaml) {
const summary = kitspaceYaml.summary || ''
const Remarker = unified()
.use(remarkParse)
.use(remarkEmoji)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeHighlight)
.use(rehypeSanitize)
.use(rehypeStringify)

const processedMarkdown = await Remarker.process(summary)
kitspaceYaml.summary = String(processedMarkdown)
return kitspaceYaml
const Remarker = unified()
.use(remarkParse)
.use(remarkEmoji)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeHighlight)
.use(rehypeSanitize)
.use(rehypeStringify)

async function renderSummary(summary = ''): Promise<string> {
const rendered = await Remarker.process(summary)
return String(rendered)
}
2 changes: 1 addition & 1 deletion processor/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function toGitHubRawUrl(url: string) {
if (parsedUrl.hostname === 'github.com') {
parsedUrl.hostname = 'raw.githubusercontent.com'
const urlPath = parsedUrl.pathname.split('/')
// Avoid using modifying github actions status badges.
// Avoid modifying github actions status badges.
const isWorkflowPath = ['workflows', 'actions'].includes(urlPath?.[3])

if (!isWorkflowPath) {
Expand Down

0 comments on commit 026cf4d

Please sign in to comment.