@@ -21,7 +21,7 @@ import {
21
21
RequestError ,
22
22
} from "./github-glue.js" ;
23
23
import { toPrettyJSON } from "./json-util.js" ;
24
- import { MailArchiveGitHelper } from "./mail-archive-helper.js" ;
24
+ import { MailArchiveGitHelper , stateKey as mailArchiveStateKey } from "./mail-archive-helper.js" ;
25
25
import { MailCommitMapping } from "./mail-commit-mapping.js" ;
26
26
import { IMailMetadata } from "./mail-metadata.js" ;
27
27
import { IPatchSeriesMetadata } from "./patch-series-metadata.js" ;
@@ -103,6 +103,7 @@ export class CIHelper {
103
103
needsUpstreamBranches ?: boolean ;
104
104
needsMailToCommitNotes ?: boolean ;
105
105
createOrUpdateCheckRun ?: boolean | "post" ;
106
+ createGitNotes ?: boolean ;
106
107
} ) : Promise < void > {
107
108
// configure the Git committer information
108
109
process . env . GIT_CONFIG_PARAMETERS = [
@@ -136,6 +137,9 @@ export class CIHelper {
136
137
}
137
138
138
139
if ( setupOptions ?. createOrUpdateCheckRun ) {
140
+ if ( setupOptions ?. createGitNotes ) {
141
+ throw new Error ( `Cannot use createOrUpdateCheckRun and createGitNotes at the same time` ) ;
142
+ }
139
143
return await this . createOrUpdateCheckRun ( setupOptions . createOrUpdateCheckRun === "post" ) ;
140
144
}
141
145
@@ -169,6 +173,56 @@ export class CIHelper {
169
173
] ) {
170
174
await git ( [ "config" , key , value ] , { workDir : this . workDir } ) ;
171
175
}
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
+
172
226
console . time ( "fetch Git notes" ) ;
173
227
const notesRefs = [ GitNotes . defaultNotesRef ] ;
174
228
if ( setupOptions ?. needsMailToCommitNotes ) {
0 commit comments