@@ -12,18 +12,35 @@ interface Actor {
1212
1313type AuthorizeMutation = ( transaction : Prisma . TransactionClient ) => Promise < boolean >
1414
15+ function reviewablePrototypeWhere (
16+ repositoryId : string ,
17+ prototypeId : string ,
18+ defaultBranch : string ,
19+ ) : Prisma . PrototypeWhereInput {
20+ return {
21+ id : prototypeId ,
22+ repositoryId,
23+ registeredAt : { not : null } ,
24+ branchDeletedAt : null ,
25+ replica : false ,
26+ branchName : { notIn : [ defaultBranch , "replica/install-workflow" ] } ,
27+ }
28+ }
29+
1530async function findStoredThread (
1631 transaction : Prisma . TransactionClient ,
1732 repositoryId : string ,
1833 prototypeId : string ,
1934 threadId : string ,
35+ defaultBranch : string ,
2036) {
2137 return transaction . reviewThread . findFirst ( {
2238 where : {
2339 id : threadId ,
2440 repositoryId,
2541 prototypeId,
2642 repository : { removedAt : null } ,
43+ prototype : reviewablePrototypeWhere ( repositoryId , prototypeId , defaultBranch ) ,
2744 } ,
2845 include : reviewThreadInclude ,
2946 } )
@@ -34,12 +51,14 @@ async function findStoredThreadByPublicId(
3451 repositoryId : string ,
3552 prototypeId : string ,
3653 threadId : number ,
54+ defaultBranch : string ,
3755) {
3856 return transaction . reviewThread . findFirst ( {
3957 where : {
4058 repositoryId,
4159 prototypeId,
4260 repository : { removedAt : null } ,
61+ prototype : reviewablePrototypeWhere ( repositoryId , prototypeId , defaultBranch ) ,
4362 comments : { some : { publicId : threadId , rootId : null } } ,
4463 } ,
4564 include : reviewThreadInclude ,
@@ -159,11 +178,17 @@ export function createReviewCommentRepository(database: Database) {
159178 if ( ! ( await input . authorize ( transaction ) ) ) {
160179 return { ok : false , reason : "session_invalid" }
161180 }
181+ const repository = await transaction . repository . findFirst ( {
182+ where : { id : input . repositoryId , removedAt : null } ,
183+ select : { defaultBranch : true } ,
184+ } )
185+ if ( ! repository ) return { ok : false , reason : "repository_not_found" }
162186 const thread = await findStoredThreadByPublicId (
163187 transaction ,
164188 input . repositoryId ,
165189 input . prototypeId ,
166190 input . threadId ,
191+ repository . defaultBranch ,
167192 )
168193 if ( ! thread ) return { ok : false , reason : "thread_not_found" }
169194 const root = thread . comments . find ( ( comment ) => comment . rootId === null )
@@ -191,6 +216,7 @@ export function createReviewCommentRepository(database: Database) {
191216 input . repositoryId ,
192217 input . prototypeId ,
193218 thread . id ,
219+ repository . defaultBranch ,
194220 )
195221 return stored ? { ok : true , value : stored } : { ok : false , reason : "thread_not_found" }
196222 } ,
@@ -211,13 +237,23 @@ export function createReviewCommentRepository(database: Database) {
211237 if ( ! ( await input . authorize ( transaction ) ) ) {
212238 return { ok : false , reason : "session_invalid" }
213239 }
240+ const repository = await transaction . repository . findFirst ( {
241+ where : { id : input . repositoryId , removedAt : null } ,
242+ select : { defaultBranch : true } ,
243+ } )
244+ if ( ! repository ) return { ok : false , reason : "repository_not_found" }
214245 const comment = await transaction . reviewComment . findFirst ( {
215246 where : {
216247 publicId : input . commentId ,
217248 thread : {
218249 repositoryId : input . repositoryId ,
219250 prototypeId : input . prototypeId ,
220251 repository : { removedAt : null } ,
252+ prototype : reviewablePrototypeWhere (
253+ input . repositoryId ,
254+ input . prototypeId ,
255+ repository . defaultBranch ,
256+ ) ,
221257 } ,
222258 } ,
223259 select : {
@@ -250,6 +286,7 @@ export function createReviewCommentRepository(database: Database) {
250286 input . repositoryId ,
251287 input . prototypeId ,
252288 comment . threadId ,
289+ repository . defaultBranch ,
253290 )
254291 return stored ? { ok : true , value : stored } : { ok : false , reason : "thread_not_found" }
255292 } ,
@@ -269,13 +306,23 @@ export function createReviewCommentRepository(database: Database) {
269306 if ( ! ( await input . authorize ( transaction ) ) ) {
270307 return { ok : false , reason : "session_invalid" }
271308 }
309+ const repository = await transaction . repository . findFirst ( {
310+ where : { id : input . repositoryId , removedAt : null } ,
311+ select : { defaultBranch : true } ,
312+ } )
313+ if ( ! repository ) return { ok : false , reason : "repository_not_found" }
272314 const comment = await transaction . reviewComment . findFirst ( {
273315 where : {
274316 publicId : input . commentId ,
275317 thread : {
276318 repositoryId : input . repositoryId ,
277319 prototypeId : input . prototypeId ,
278320 repository : { removedAt : null } ,
321+ prototype : reviewablePrototypeWhere (
322+ input . repositoryId ,
323+ input . prototypeId ,
324+ repository . defaultBranch ,
325+ ) ,
279326 } ,
280327 } ,
281328 select : {
@@ -306,6 +353,7 @@ export function createReviewCommentRepository(database: Database) {
306353 input . repositoryId ,
307354 input . prototypeId ,
308355 comment . threadId ,
356+ repository . defaultBranch ,
309357 )
310358 return stored ? { ok : true , value : stored } : { ok : false , reason : "thread_not_found" }
311359 } ,
@@ -326,11 +374,17 @@ export function createReviewCommentRepository(database: Database) {
326374 if ( ! ( await input . authorize ( transaction ) ) ) {
327375 return { ok : false , reason : "session_invalid" }
328376 }
377+ const repository = await transaction . repository . findFirst ( {
378+ where : { id : input . repositoryId , removedAt : null } ,
379+ select : { defaultBranch : true } ,
380+ } )
381+ if ( ! repository ) return { ok : false , reason : "repository_not_found" }
329382 const thread = await findStoredThreadByPublicId (
330383 transaction ,
331384 input . repositoryId ,
332385 input . prototypeId ,
333386 input . threadId ,
387+ repository . defaultBranch ,
334388 )
335389 if ( ! thread ) return { ok : false , reason : "thread_not_found" }
336390 const alreadyDesired = input . resolved
@@ -368,6 +422,7 @@ export function createReviewCommentRepository(database: Database) {
368422 input . repositoryId ,
369423 input . prototypeId ,
370424 thread . id ,
425+ repository . defaultBranch ,
371426 )
372427 return stored ? { ok : true , value : stored } : { ok : false , reason : "thread_not_found" }
373428 } ,
0 commit comments