feat: author on GitHub issues and PR cards

zio/stable
patak 2022-12-20 20:42:28 +01:00
parent 60a8673757
commit 2e97780899
1 changed files with 16 additions and 27 deletions

View File

@ -14,14 +14,11 @@ interface Meta {
details: string
repo?: string
number?: string
extra?: {
state: string
author?: {
avatar: string
user: string
}
}
}
const meta = $computed(() => {
const { url } = props.card
@ -43,8 +40,10 @@ const meta = $computed(() => {
type = 'pull'
}
}
const avatar = `https://github.com/${user}.png`
const avatar = `https://github.com/${user}.png?size=256`
const details = (props.card.title ?? '').replace('GitHub - ', '').replace(`${repoPath}: `, '').split(' · ')[0]
const author = props.card.authorName
const info = $ref<Meta>({
type,
user,
@ -53,23 +52,13 @@ const meta = $computed(() => {
repo,
number,
avatar,
})
/* It is rate limited for anonymous usage, leaving this to play, but for now it is probably better to avoid the call
We can't show the author of the PR or issue without this info, because the handle isn't in the meta. I think we
could ask GitHub to add it.
if (number) {
fetch(`https://api.github.com/repos/${user}/${repo}/issues/${number}`).then(res => res.json()).then((data) => {
info.extra = {
state: data.state as string,
author: {
avatar: data.user.avatar_url as string,
user: data.user.login as string,
},
author: author
? {
avatar: `https://github.com/${author}.png?size=64`,
user: author,
}
: undefined,
})
}
*/
return info
})
</script>
@ -112,14 +101,14 @@ const meta = $computed(() => {
</div>
</div>
<div flex justify-between>
<div v-if="meta.extra" flex gap-2 items-center>
<div v-if="meta.author" flex class="gap-2.5" items-center>
<div>
<img w-6 aspect-square width="20" height="20" rounded-full :src="meta.extra?.author?.avatar">
<img w-8 aspect-square width="25" height="25" rounded-full :src="meta.author?.avatar">
</div>
<span text-xl text-primary font-bold>@{{ meta.extra?.author?.user }}</span>
<span text-lg text-primary>@{{ meta.author?.user }}</span>
</div>
<div v-else />
<div text-2xl i-ri:github-fill text-secondary />
<div text-3xl i-ri:github-fill text-secondary />
</div>
</div>
</div>