@@ -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,47 @@ 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 ( "verify that Git notes do not yet exist" ) ;
186
+ const existingNotes = await git (
187
+ [
188
+ "ls-remote" ,
189
+ "origin" ,
190
+ GitNotes . defaultNotesRef ,
191
+ "refs/notes/mail-to-commit" ,
192
+ "refs/notes/commit-to-mail" ,
193
+ ] ,
194
+ {
195
+ workDir : this . workDir ,
196
+ } ,
197
+ ) ;
198
+ if ( existingNotes !== "" ) {
199
+ throw new Error ( `Git notes already exist in ${ this . workDir } :\n${ existingNotes } ` ) ;
200
+ }
201
+ console . timeEnd ( "verify that Git notes do not yet exist" ) ;
202
+ console . time ( "create the initial Git notes and push them" ) ;
203
+ for ( const key of [ "mail-to-commit" , "commit-to-mail" ] ) {
204
+ const notes = new GitNotes ( this . workDir , `refs/notes/${ key } ` ) ;
205
+ await notes . initializeWithEmptyCommit ( ) ;
206
+ await notes . push ( this . urlRepo , this . notesPushToken ) ;
207
+ }
208
+ const options : IGitGitGadgetOptions = {
209
+ allowedUsers : [ initialUser ] ,
210
+ } ;
211
+ await this . notes . set ( "" , options , true ) ;
212
+ await this . notes . push ( this . urlRepo , this . notesPushToken ) ;
213
+ console . timeEnd ( "create the initial Git notes and push them" ) ;
214
+ return ;
215
+ }
216
+
172
217
console . time ( "fetch Git notes" ) ;
173
218
const notesRefs = [ GitNotes . defaultNotesRef ] ;
174
219
if ( setupOptions ?. needsMailToCommitNotes ) {
0 commit comments