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,12 +14,9 @@ interface Meta {
details: string details: string
repo?: string repo?: string
number?: string number?: string
extra?: { author?: {
state: string avatar: string
author?: { user: string
avatar: string
user: string
}
} }
} }
@ -43,8 +40,10 @@ const meta = $computed(() => {
type = 'pull' 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 details = (props.card.title ?? '').replace('GitHub - ', '').replace(`${repoPath}: `, '').split(' · ')[0]
const author = props.card.authorName
const info = $ref<Meta>({ const info = $ref<Meta>({
type, type,
user, user,
@ -53,23 +52,13 @@ const meta = $computed(() => {
repo, repo,
number, number,
avatar, avatar,
author: author
? {
avatar: `https://github.com/${author}.png?size=64`,
user: author,
}
: undefined,
}) })
/* 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,
},
}
})
}
*/
return info return info
}) })
</script> </script>
@ -112,14 +101,14 @@ const meta = $computed(() => {
</div> </div>
</div> </div>
<div flex justify-between> <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> <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> </div>
<span text-xl text-primary font-bold>@{{ meta.extra?.author?.user }}</span> <span text-lg text-primary>@{{ meta.author?.user }}</span>
</div> </div>
<div v-else /> <div v-else />
<div text-2xl i-ri:github-fill text-secondary /> <div text-3xl i-ri:github-fill text-secondary />
</div> </div>
</div> </div>
</div> </div>