Skip to content

Commit

Permalink
feat: remove the token prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Sep 20, 2023
1 parent f2463a1 commit b6b5cf9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/command/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ const resolveAuthorInfo = async (options: ChangelogOption, info: AuthorInfo) =>
}

const headers: { [x: string]: string } = { accept: 'application/vnd.github+json' }
options.token && (headers.authorization = `token ${ options.token }`)
options.token && (headers.authorization = `${ options.token }`)


/* eslint-disable @typescript-eslint/no-unsafe-assignment, require-atomic-updates, @typescript-eslint/no-unsafe-member-access */
let errorDetail
try {
const data = await $fetch(`https://api.github.com/search/users?q=${ encodeURIComponent(info.email) }`, { headers })
info.login = data.items[0].login
}
catch {
catch (e: any) {
errorDetail = e
}

if (!info.login && info.commits.length && options.github) {
Expand All @@ -77,7 +80,8 @@ const resolveAuthorInfo = async (options: ChangelogOption, info: AuthorInfo) =>
const data = await $fetch(`https://api.github.com/repos/${ options.github }/commits/${ commit }`, { headers })
info.login = data.author.login
break
} catch {
} catch (e: any) {
errorDetail = e
continue
}
}
Expand All @@ -86,6 +90,7 @@ const resolveAuthorInfo = async (options: ChangelogOption, info: AuthorInfo) =>

if (!info.login) {
console.log(pc.yellow(`Failed to resolve the ${ info.name } author info, fallback to the origin data.`))
console.error(errorDetail)
}

globalAuthorCache.set(info.email, info)
Expand Down

0 comments on commit b6b5cf9

Please sign in to comment.