@@ -21,7 +21,7 @@ import {
2121 RequestError ,
2222} from "./github-glue.js" ;
2323import { toPrettyJSON } from "./json-util.js" ;
24- import { MailArchiveGitHelper } from "./mail-archive-helper.js" ;
24+ import { MailArchiveGitHelper , stateKey as mailArchiveStateKey } from "./mail-archive-helper.js" ;
2525import { MailCommitMapping } from "./mail-commit-mapping.js" ;
2626import { IMailMetadata } from "./mail-metadata.js" ;
2727import { IPatchSeriesMetadata } from "./patch-series-metadata.js" ;
@@ -103,6 +103,7 @@ export class CIHelper {
103103 needsUpstreamBranches ?: boolean ;
104104 needsMailToCommitNotes ?: boolean ;
105105 createOrUpdateCheckRun ?: boolean | "post" ;
106+ createGitNotes ?: boolean ;
106107 } ) : Promise < void > {
107108 // configure the Git committer information
108109 process . env . GIT_CONFIG_PARAMETERS = [
@@ -136,6 +137,9 @@ export class CIHelper {
136137 }
137138
138139 if ( setupOptions ?. createOrUpdateCheckRun ) {
140+ if ( setupOptions ?. createGitNotes ) {
141+ throw new Error ( `Cannot use createOrUpdateCheckRun and createGitNotes at the same time` ) ;
142+ }
139143 return await this . createOrUpdateCheckRun ( setupOptions . createOrUpdateCheckRun === "post" ) ;
140144 }
141145
@@ -169,6 +173,56 @@ export class CIHelper {
169173 ] ) {
170174 await git ( [ "config" , key , value ] , { workDir : this . workDir } ) ;
171175 }
176+ if ( setupOptions ?. createGitNotes ) {
177+ if (
178+ setupOptions . needsMailToCommitNotes ||
179+ setupOptions . needsUpstreamBranches ||
180+ setupOptions . needsMailingListMirror
181+ ) {
182+ throw new Error ( "`createGitNotes` cannot be combined with any other options" ) ;
183+ }
184+ const initialUser = core . getInput ( "initial-user" ) ;
185+ console . time ( "Retrieving latest mail repo revision" ) ;
186+ const fetchLatestMailRepoRevision = await git ( [
187+ "ls-remote" ,
188+ `${ this . config . mailrepo . url } /${ this . config . mailrepo . public_inbox_epoch ?? 1 } ` ,
189+ this . config . mailrepo . branch ,
190+ ] ) ;
191+ const latestMailRepoRevision = fetchLatestMailRepoRevision . split ( "\t" ) [ 0 ] ;
192+ console . timeEnd ( "Retrieving latest mail repo revision" ) ;
193+ console . time ( "verify that Git notes do not yet exist" ) ;
194+ const existingNotes = await git (
195+ [
196+ "ls-remote" ,
197+ "origin" ,
198+ GitNotes . defaultNotesRef ,
199+ "refs/notes/mail-to-commit" ,
200+ "refs/notes/commit-to-mail" ,
201+ ] ,
202+ {
203+ workDir : this . workDir ,
204+ } ,
205+ ) ;
206+ if ( existingNotes !== "" ) {
207+ throw new Error ( `Git notes already exist in ${ this . workDir } :\n${ existingNotes } ` ) ;
208+ }
209+ console . timeEnd ( "verify that Git notes do not yet exist" ) ;
210+ console . time ( "create the initial Git notes and push them" ) ;
211+ for ( const key of [ "mail-to-commit" , "commit-to-mail" ] ) {
212+ const notes = new GitNotes ( this . workDir , `refs/notes/${ key } ` ) ;
213+ await notes . initializeWithEmptyCommit ( ) ;
214+ await notes . push ( this . urlRepo , this . notesPushToken ) ;
215+ }
216+ const options : IGitGitGadgetOptions = {
217+ allowedUsers : [ initialUser ] ,
218+ } ;
219+ await this . notes . set ( "" , options , true ) ;
220+ await this . notes . set ( mailArchiveStateKey , latestMailRepoRevision , false ) ;
221+ await this . notes . push ( this . urlRepo , this . notesPushToken ) ;
222+ console . timeEnd ( "create the initial Git notes and push them" ) ;
223+ return ;
224+ }
225+
172226 console . time ( "fetch Git notes" ) ;
173227 const notesRefs = [ GitNotes . defaultNotesRef ] ;
174228 if ( setupOptions ?. needsMailToCommitNotes ) {
0 commit comments