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

Fix: Adds title of tool to feedback commit #226

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions tools/src/lib/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const TEMPLATES = {
disclaimer:
'## Disclaimer\nThe following feedback was submitted by an user of https://idg.tools. This has not yet been reviewed or approved by the contributors.\n\n---\n',
},
// NOTE: Seems like this template is currently not used anywhere - in case it is used in future, the call to createIssue() also requires a <name> parameter.
CONTENT_SUGGESTION: {
title: 'App Content Suggestion',
labelIds: [LABEL_IDS.NEEDS_REVIEW, LABEL_IDS.CONTENT_SUGGESTION],
Expand All @@ -45,27 +46,35 @@ type ISSUE_TYPES = keyof typeof TEMPLATES

// NOTE: Seems like there's a rate limiting of 5000/requests per hour, so it might be worth to write multiple issues at once in the future to scale up.
export async function createIssue({
name,
userContent,
type,
url,
}: {
userContent: string
type: ISSUE_TYPES
url: string
}) {
name: string
userContent: string
type: ISSUE_TYPES
url: string
}) {
const { title, labelIds, disclaimer } = TEMPLATES[type]
Greenheart marked this conversation as resolved.
Show resolved Hide resolved

const body = `${disclaimer}
${userContent}
---
- URL: ${url}
- Git commit: \`${GIT_COMMIT}\`

---

${userContent}`
`
Comment on lines 65 to +73
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works just as expected - nice work!

I'm changing the formatting slightly to clearly separate the disclaimer from the userContent.

Suggested change
const body = `${disclaimer}
${userContent}
---
- URL: ${url}
- Git commit: \`${GIT_COMMIT}\`
---
${userContent}`
`
const body = `${disclaimer}
---
${userContent}
---
- URL: ${url}
- Git commit: \`${GIT_COMMIT}\``

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes it look nicer! 👍


const newIssue = {
repositoryId: REPOSITORY.id,
title: `[${title}]: ${new Date().toISOString()}`,
title: `[${title}]: ${name}`,
body,
labelIds,
}
Expand Down
3 changes: 2 additions & 1 deletion tools/src/routes/[link]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import stripMarkdown from 'strip-markdown'

import { content } from '$lib/content-backend'
import { getSkill, getTag, getToolByLink } from '$shared/content-utils'
import type { Actions, PageServerLoad } from './$types'
import type { Tool, Actions, PageServerLoad } from './$types'
import { createIssue } from '$lib/github'

const sanitizer = remark().use(stripMarkdown)
Expand Down Expand Up @@ -51,6 +51,7 @@ export const actions: Actions = {
if (!Boolean(data.liked || data.improve)) return { success: false }

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can load the specific tool referenced for this request, and then use the name when submitting the issue.

To accomplish this, we need to

  1. update the parameters for the default action to include params: { link }.
-      default: async ({ request, url }) => {
+      default: async ({ request, url, params: { link } }) => {
  1. load the tool, and verify that it exists before continuing.
Suggested change
const tool = getToolByLink(link, content)
if (!tool) return { success: false }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will load the tool twice for each page from the store: once in the load() function and then again for the feedback submit form via actions.

I have defined tool globally, but the way I did it, the load() function is required to run before actions - not a nice dependency either, because as soon as load() changes, the actions might be broken. Is there a way to only load the tool once for each page? Or is it less of importance how many reads we do to the database? 🤔

await createIssue({
name: tool.name,
userContent: `## What do you like?\n> ${data.liked}\n\n## What can be improved?\n> ${data.improve}`,
type: 'FEEDBACK',
url: url.href,
Expand Down