@@ -5,11 +5,11 @@ import { defu } from 'defu'
55import type {
66 ModuleOptions
77} from '../../../module'
8- import { GithubRawRelease , GithubRepositoryOptions , GithubRawContributor , GithubContributorsQuery , GithubReleasesQuery , GithubRepositoryReadme , GithubRepository } from '../../types'
8+ import { GithubRawRelease , GithubRepositoryOptions , GithubRawContributor , GithubContributorsQuery , GithubReleasesQuery , GithubRepositoryReadme , GithubRepository , GithubCommitsQuery } from '../../types'
99// @ts -ignore
1010import { parseContent } from '#content/server'
1111
12- export function decodeParams ( params : string = '' ) {
12+ export function decodeParams ( params = '' ) {
1313 const result = { }
1414 params = params . replace ( / \. j s o n $ / , '' )
1515 for ( const param of params . split ( ':' ) ) {
@@ -151,6 +151,57 @@ export async function fetchRepositoryContributors ({ max }: Partial<GithubContri
151151 return contributors . map ( ( { avatar_url, login } ) => ( { avatar_url, login } ) )
152152}
153153
154+ export async function fetchCommits ( { date, source } : Partial < Omit < GithubCommitsQuery , 'date' > & { date : Date } > , { owner, repo, branch, token } : GithubRepositoryOptions ) {
155+ const daysAgo = ( ) => {
156+ if ( date ) { return date . toISOString ( ) }
157+
158+ const now = new Date ( )
159+ now . setDate ( now . getDate ( ) - 30 ) // get from 30 days ago
160+ return now . toISOString ( )
161+ }
162+
163+ const path = source ? `path: "${ source } ",` : ''
164+ const data = await githubGraphqlQuery (
165+ `
166+ query {
167+ repository(owner: "${ owner } ", name: "${ repo } ") {
168+ object(expression: "${ branch } ") {
169+ ... on Commit {
170+ history(since: "${ daysAgo ( ) } ", ${ path } ) {
171+ nodes {
172+ oid
173+ messageHeadlineHTML
174+ authors(first: ${ 5 } ) {
175+ nodes {
176+ user {
177+ name
178+ avatarUrl
179+ login
180+ }
181+ }
182+ }
183+ }
184+ }
185+ }
186+ }
187+ }
188+ }
189+ ` , { token }
190+ )
191+
192+ if ( ! data ?. repository ?. object ?. history ?. nodes ) { return [ ] }
193+
194+ const commits = data . repository . object . history . nodes . map ( node => ( {
195+ hash : node . oid ,
196+ message : node . messageHeadlineHTML ,
197+ authors : node . authors . nodes
198+ . map ( author => author . user )
199+ . filter ( user => user ?. name && ! isBot ( user ) )
200+ } ) )
201+
202+ return commits
203+ }
204+
154205export async function fetchFileContributors ( { source, max } : Partial < GithubContributorsQuery > , { owner, repo, branch, token } : GithubRepositoryOptions & { maxContributors ?: number } ) {
155206 const data = await githubGraphqlQuery (
156207 `
0 commit comments