55 * function is provided by the user, it is used to filter the commits that are
66 * to be shown. Otherwise, all commits are shown.
77 *
8+ * Optionally, a `path` parameter can be provided to filter commits to only
9+ * those that affected a specific file or folder (useful for monorepos).
10+ *
811 * @typedef {{message: string, hash: string} } Commit
912 */
1013import { github } from "../github.js" ;
@@ -19,6 +22,7 @@ export const element = class ChangelogElement extends HTMLElement {
1922 this . props = {
2023 from : this . getAttribute ( "from" ) ,
2124 to : this . getAttribute ( "to" ) || "HEAD" ,
25+ path : this . getAttribute ( "path" ) ,
2226 /** @type {(commit: Commit) => boolean } */
2327 filter :
2428 typeof window [ this . getAttribute ( "filter" ) ] === "function"
@@ -28,11 +32,11 @@ export const element = class ChangelogElement extends HTMLElement {
2832 }
2933
3034 connectedCallback ( ) {
31- const { from, to, filter } = this . props ;
35+ const { from, to, filter, path } = this . props ;
3236 html . bind ( this ) `
3337 <ul>
3438 ${ {
35- any : fetchCommits ( from , to , filter )
39+ any : fetchCommits ( from , to , filter , path )
3640 . then ( commits => toHTML ( commits ) )
3741 . catch ( error =>
3842 showError ( error . message , name , { elements : [ this ] , cause : error } )
@@ -47,7 +51,7 @@ export const element = class ChangelogElement extends HTMLElement {
4751 }
4852} ;
4953
50- async function fetchCommits ( from , to , filter ) {
54+ async function fetchCommits ( from , to , filter , path ) {
5155 /** @type {Commit[] } */
5256 let commits ;
5357 try {
@@ -58,6 +62,9 @@ async function fetchCommits(from, to, filter) {
5862 const url = new URL ( "commits" , `${ gh . apiBase } /${ gh . fullName } /` ) ;
5963 url . searchParams . set ( "from" , from ) ;
6064 url . searchParams . set ( "to" , to ) ;
65+ if ( path ) {
66+ url . searchParams . set ( "path" , path ) ;
67+ }
6168
6269 const res = await fetch ( url . href ) ;
6370 if ( ! res . ok ) {
0 commit comments