( owner: string, repo: string, from: string, to: string, )
| 53 | } |
| 54 | |
| 55 | export async function fetchCommits( |
| 56 | owner: string, |
| 57 | repo: string, |
| 58 | from: string, |
| 59 | to: string, |
| 60 | ) { |
| 61 | const client = getRequestClient(); |
| 62 | |
| 63 | const comparison = await client( |
| 64 | "GET /repos/{owner}/{repo}/compare/{base}...{head}", |
| 65 | { |
| 66 | owner, |
| 67 | repo, |
| 68 | base: from, |
| 69 | head: to, |
| 70 | }, |
| 71 | ); |
| 72 | |
| 73 | const comparisonData = comparison.data as { |
| 74 | commits?: Array<{ |
| 75 | sha: string; |
| 76 | commit?: { message?: string }; |
| 77 | }>; |
| 78 | }; |
| 79 | |
| 80 | const commits = Array.isArray(comparisonData.commits) |
| 81 | ? comparisonData.commits |
| 82 | : []; |
| 83 | |
| 84 | if (commits.length === 0) { |
| 85 | return []; |
| 86 | } |
| 87 | |
| 88 | const results = await Promise.all( |
| 89 | commits.map(async (commit) => { |
| 90 | const sha = commit.sha; |
| 91 | const title = |
| 92 | commit.commit?.message?.split("\n", 1)[0]?.trim() || |
| 93 | "(no commit title)"; |
| 94 | |
| 95 | try { |
| 96 | const diffResponse = await client( |
| 97 | "GET /repos/{owner}/{repo}/commits/{ref}", |
| 98 | { |
| 99 | owner, |
| 100 | repo, |
| 101 | ref: sha, |
| 102 | headers: { |
| 103 | accept: DIFF_ACCEPT_HEADER, |
| 104 | }, |
| 105 | }, |
| 106 | ); |
| 107 | |
| 108 | const diff = String(diffResponse.data); |
| 109 | if (diff.trim().length === 0) { |
| 110 | return null; |
| 111 | } |
| 112 |
no test coverage detected