-
-
Notifications
You must be signed in to change notification settings - Fork 527
feat: changelog add support for gitea, bitbucket, sourcehut & gitee #3221
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4973633
36d2ac9
0756d22
cc30bd0
d04de2a
36c408f
be0c0ba
dcb22eb
f80b041
3b3e2ce
9090c84
444487b
29e36c6
ca52fec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,15 @@ import * as v from 'valibot' | |
| import { ERROR_THROW_INCOMPLETE_PARAM } from '~~/shared/utils/constants' | ||
| import { | ||
| ForgejoReleaseSchama, | ||
| GiteaReleaseSchema, | ||
| GiteeReleaseSchema, | ||
| GithubReleaseCollectionSchama, | ||
| GitlabReleaseSchame, | ||
| } from '~~/shared/schemas/changelog/release' | ||
| import { validateHostWithValibot } from '~~/server/utils/changelog/validateHost' | ||
|
|
||
| const TIMEOUT_TIME = 15_000 | ||
|
|
||
| export default defineCachedEventHandler( | ||
| async event => { | ||
| const provider = getRouterParam(event, 'provider') as ProviderId | ||
|
|
@@ -40,6 +44,10 @@ export default defineCachedEventHandler( | |
| return await getMarkdownFromForgejo(owner, repo, encodedTag, host) | ||
| case 'gitlab': | ||
| return await getMarkdownFromGitlab(owner, repo, encodedTag, host) | ||
| case 'gitea': | ||
| return await getMarkdownFromGitea(owner, repo, encodedTag, host) | ||
| case 'gitee': | ||
| return await getMarkdownFromGitee(owner, repo, encodedTag) | ||
| default: | ||
| throw createError({ | ||
| status: 404, | ||
|
|
@@ -84,8 +92,9 @@ async function getMarkdownFromGithub(owner: string, repo: string, tag: string, e | |
| 'User-Agent': 'npmx.dev', | ||
| }, | ||
| ignoreResponseError: true, | ||
| timeout: TIMEOUT_TIME, | ||
| }, | ||
| ) | ||
| ).catch(() => null) | ||
|
|
||
| const parsed = v.safeParse(v.object({ body: v.string() }), responseGithub) | ||
|
|
||
|
|
@@ -101,6 +110,7 @@ async function getMarkdownFromGithub(owner: string, repo: string, tag: string, e | |
| 'Accept': '*/*', | ||
| 'User-Agent': 'npmx.dev', | ||
| }, | ||
| timeout: TIMEOUT_TIME, | ||
| }) | ||
|
|
||
| const { releases } = v.parse(GithubReleaseCollectionSchama, responseUngh) | ||
|
|
@@ -129,6 +139,7 @@ async function getMarkdownFromForgejo( | |
| headers: { | ||
| 'User-Agent': 'npmx.dev', | ||
| }, | ||
| timeout: TIMEOUT_TIME, | ||
| }) | ||
|
|
||
| const release = v.parse(ForgejoReleaseSchama, data) | ||
|
|
@@ -150,9 +161,50 @@ async function getMarkdownFromGitlab( | |
| headers: { | ||
| 'User-Agent': 'npmx.dev', | ||
| }, | ||
| timeout: TIMEOUT_TIME, | ||
| }) | ||
|
|
||
| const release = v.parse(GitlabReleaseSchame, data) | ||
|
|
||
| return release.description | ||
| } | ||
|
|
||
| async function getMarkdownFromGitea( | ||
| owner: string, | ||
| repo: string, | ||
| /** tag should be encoded */ | ||
| tag: string, | ||
| host: string = 'gitea.com', | ||
| ) { | ||
| const data = await $fetch(`https://${host}/api/v1/repos/${owner}/${repo}/releases/tags/${tag}`, { | ||
| headers: { | ||
| 'User-Agent': 'npmx.dev', | ||
| }, | ||
| timeout: TIMEOUT_TIME, | ||
| }) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add the same |
||
|
|
||
| const release = v.parse(GiteaReleaseSchema, data) | ||
|
|
||
| return release.body | ||
| } | ||
|
|
||
| async function getMarkdownFromGitee( | ||
| owner: string, | ||
| repo: string, | ||
| /** tag should be encoded */ | ||
| tag: string, | ||
| ) { | ||
| const data = await $fetch( | ||
| `https://gitee.com/api/v5/repos/${owner}/${repo}/releases/tags/${tag}`, | ||
| { | ||
| headers: { | ||
| 'User-Agent': 'npmx.dev', | ||
| }, | ||
| timeout: TIMEOUT_TIME, | ||
| }, | ||
| ) | ||
|
|
||
| const release = v.parse(GiteeReleaseSchema, data) | ||
|
|
||
| return release.body | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,14 @@ export function getBaseFileUrl(ref: RepoRef): RepoFileUrl | null { | |||||||||
| raw: `https://codeberg.org/${ref.owner}/${ref.repo}/raw/branch/HEAD`, | ||||||||||
| } | ||||||||||
| case 'forgejo': { | ||||||||||
| const host = ref.host | ||||||||||
| return { | ||||||||||
| blob: `https://${ref.host}/${ref.owner}/${ref.repo}/src/branch/HEAD`, | ||||||||||
| raw: `https://${ref.host}/${ref.owner}/${ref.repo}/raw/branch/HEAD`, | ||||||||||
| } | ||||||||||
| } | ||||||||||
| case 'gitea': { | ||||||||||
| // although similar to forgejo, we keep these seperate because they're seperately maintained projects | ||||||||||
| const host = ref.host ?? 'gitea.com' | ||||||||||
| return { | ||||||||||
| blob: `https://${host}/${ref.owner}/${ref.repo}/src/branch/HEAD`, | ||||||||||
| raw: `https://${host}/${ref.owner}/${ref.repo}/raw/branch/HEAD`, | ||||||||||
|
|
@@ -35,6 +42,24 @@ export function getBaseFileUrl(ref: RepoRef): RepoFileUrl | null { | |||||||||
| raw: `https://tangled.org/${ref.owner}/${ref.repo}/raw/HEAD`, | ||||||||||
| } | ||||||||||
| } | ||||||||||
| case 'bitbucket': { | ||||||||||
| return { | ||||||||||
| blob: `https://bitbucket.org/${ref.owner}/${ref.repo}/src/HEAD`, | ||||||||||
| raw: `https://bitbucket.org/${ref.owner}/${ref.repo}/raw/HEAD`, | ||||||||||
| } | ||||||||||
| } | ||||||||||
| case 'sourcehut': { | ||||||||||
| return { | ||||||||||
| blob: `https://git.sr.ht/${ref.owner}/${ref.repo}/tree/HEAD/item`, | ||||||||||
| raw: `https://git.sr.ht/${ref.owner}/${ref.repo}/blob/HEAD`, | ||||||||||
| } | ||||||||||
| } | ||||||||||
| case 'gitee': { | ||||||||||
| return { | ||||||||||
| blob: `https://gitee.com/${ref.owner}/${ref.repo}/blob/main`, | ||||||||||
| raw: `https://gitee.com/${ref.owner}/${ref.repo}/raw/main`, | ||||||||||
|
Comment on lines
+59
to
+60
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intentional that this hardcodes
Suggested change
|
||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| return null | ||||||||||
| } | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.