collavre_github 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/collavre_github/webhooks_controller.rb +1 -7
- data/app/javascript/collavre_github.js +32 -123
- data/app/jobs/collavre_github/initial_markdown_sync_job.rb +6 -4
- data/app/jobs/collavre_github/markdown_sync_job.rb +6 -4
- data/app/jobs/collavre_github/pr_blocker_sweep_job.rb +18 -0
- data/app/models/collavre_github/github_pr_channel.rb +52 -21
- data/app/models/collavre_github/repository_link.rb +2 -2
- data/app/services/collavre_github/client.rb +23 -0
- data/app/services/collavre_github/markdown_sync/content_creative.rb +56 -0
- data/app/services/collavre_github/markdown_sync/content_processor.rb +16 -1
- data/app/services/collavre_github/markdown_sync/incremental_sync_service.rb +12 -34
- data/app/services/collavre_github/markdown_sync/initial_import_service.rb +6 -19
- data/app/services/collavre_github/pr_blocker_monitor.rb +93 -0
- data/app/services/collavre_github/pr_discussion_event.rb +25 -0
- data/app/services/collavre_github/tools/pr_monitor_service.rb +4 -3
- data/app/services/collavre_github/webhook_provisioner.rb +1 -1
- data/config/locales/en.yml +3 -0
- data/config/locales/ko.yml +3 -0
- data/config/locales/tool_descriptions.en.yml +20 -0
- data/config/locales/tool_descriptions.ko.yml +20 -0
- data/db/seeds.rb +1 -1
- data/lib/collavre_github/engine.rb +9 -0
- data/lib/collavre_github/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3eec516f575a22f8743a1b21ec8d9b9c81a3550183d3056c12cbead67c89f9c
|
|
4
|
+
data.tar.gz: 0ce665ac4aa33e1b14323e856f9e1966ef33df9d6c61bfeb6a5e0f2d31800e6c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d3f388a8d902dc6d5717517d86ea3da263fa1977520faa7e2e690567ba6c9007b3791bf9c3b1b412569d0a99e388795b5e3afe220d2b92d4ea9c2fe0d2fa0a0
|
|
7
|
+
data.tar.gz: 674076ed8e23fd08f61397587c54a42c00048214930f4bf2c5533a2354e5e3d34e35bf62e0310c73081d94e8e9e4c6571c196272972a5978725b7b5cfeffc294
|
|
@@ -366,13 +366,7 @@ module CollavreGithub
|
|
|
366
366
|
channel.with_lock do
|
|
367
367
|
next unless channel.active?
|
|
368
368
|
|
|
369
|
-
|
|
370
|
-
next if injected.nil?
|
|
371
|
-
|
|
372
|
-
channel.inject_into_topic!(injected)
|
|
373
|
-
# Detach AFTER injecting the closing message so the chip remains
|
|
374
|
-
# visible (now with merged/closed badge) until dismissed by the user.
|
|
375
|
-
channel.detach! if event == "pull_request" && payload["action"] == "closed"
|
|
369
|
+
channel.deliver_event!(event: event, payload: payload)
|
|
376
370
|
end
|
|
377
371
|
rescue => e
|
|
378
372
|
# Isolate per-channel failures so one broken channel does not block
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { csrfToken, showError, clearError, updateStepVisibility,
|
|
1
|
+
import { csrfToken, showError, clearError, updateStepVisibility, requireCreativeId, resetConnectView, sendJson, appendLabeledInput } from 'collavre/modules/integration_wizard';
|
|
2
2
|
import { alertDialog, confirmDialog } from 'collavre/lib/utils/dialog';
|
|
3
3
|
import { deriveConnectState, shouldShowConnectNext } from './github_wizard_state.js';
|
|
4
4
|
|
|
@@ -72,23 +72,11 @@ if (!githubIntegrationInitialized) {
|
|
|
72
72
|
userConnected = false;
|
|
73
73
|
selectedReposForDeletion = new Set();
|
|
74
74
|
statusEl.textContent = '';
|
|
75
|
-
errorEl
|
|
76
|
-
errorEl.textContent = '';
|
|
75
|
+
clearError(errorEl);
|
|
77
76
|
if (summaryInstructions) summaryInstructions.style.display = 'none';
|
|
78
|
-
|
|
79
|
-
if (existingContainer) {
|
|
80
|
-
existingContainer.style.display = 'none';
|
|
81
|
-
}
|
|
82
|
-
if (existingList) {
|
|
83
|
-
existingList.innerHTML = '';
|
|
84
|
-
}
|
|
85
|
-
if (connectMessage) {
|
|
86
|
-
connectMessage.style.display = '';
|
|
87
|
-
}
|
|
88
|
-
if (deleteBtn) deleteBtn.style.display = 'none';
|
|
77
|
+
resetConnectView({ existingContainer, existingList, connectMessage, deleteBtn, loginBtn });
|
|
89
78
|
if (resyncBtn) resyncBtn.style.display = 'none';
|
|
90
79
|
updateDeleteButtonState();
|
|
91
|
-
if (loginBtn) loginBtn.style.display = 'inline-block';
|
|
92
80
|
updateStep();
|
|
93
81
|
}
|
|
94
82
|
|
|
@@ -98,12 +86,7 @@ if (!githubIntegrationInitialized) {
|
|
|
98
86
|
}
|
|
99
87
|
|
|
100
88
|
function updateStep() {
|
|
101
|
-
['connect', 'organization', 'repositories', 'markdown-sync', 'summary']
|
|
102
|
-
.forEach(function (step) {
|
|
103
|
-
const el = document.getElementById(`github-step-${step}`);
|
|
104
|
-
if (!el) return;
|
|
105
|
-
el.style.display = (step === currentStep) ? 'block' : 'none';
|
|
106
|
-
});
|
|
89
|
+
updateStepVisibility(currentStep, ['connect', 'organization', 'repositories', 'markdown-sync', 'summary'], 'github-step');
|
|
107
90
|
|
|
108
91
|
if (currentStep === 'connect') {
|
|
109
92
|
prevBtn.style.display = 'none';
|
|
@@ -149,13 +132,6 @@ if (!githubIntegrationInitialized) {
|
|
|
149
132
|
return;
|
|
150
133
|
}
|
|
151
134
|
repos.forEach(function (fullName) {
|
|
152
|
-
const label = document.createElement('label');
|
|
153
|
-
label.style.display = 'flex';
|
|
154
|
-
label.style.alignItems = 'center';
|
|
155
|
-
label.style.gap = '0.5em';
|
|
156
|
-
label.style.marginBottom = '0.5em';
|
|
157
|
-
label.style.cursor = 'pointer';
|
|
158
|
-
|
|
159
135
|
const input = document.createElement('input');
|
|
160
136
|
input.type = 'checkbox';
|
|
161
137
|
input.value = fullName;
|
|
@@ -168,12 +144,7 @@ if (!githubIntegrationInitialized) {
|
|
|
168
144
|
}
|
|
169
145
|
});
|
|
170
146
|
|
|
171
|
-
|
|
172
|
-
span.textContent = fullName + ' — Markdown Sync';
|
|
173
|
-
|
|
174
|
-
label.appendChild(input);
|
|
175
|
-
label.appendChild(span);
|
|
176
|
-
markdownSyncList.appendChild(label);
|
|
147
|
+
appendLabeledInput(markdownSyncList, input, fullName + ' — Markdown Sync');
|
|
177
148
|
});
|
|
178
149
|
}
|
|
179
150
|
|
|
@@ -187,23 +158,12 @@ if (!githubIntegrationInitialized) {
|
|
|
187
158
|
document.body.classList.remove('no-scroll');
|
|
188
159
|
}
|
|
189
160
|
|
|
190
|
-
function showError(message) {
|
|
191
|
-
if (!message) return;
|
|
192
|
-
errorEl.textContent = message;
|
|
193
|
-
errorEl.style.display = 'block';
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function clearError() {
|
|
197
|
-
errorEl.textContent = '';
|
|
198
|
-
errorEl.style.display = 'none';
|
|
199
|
-
}
|
|
200
|
-
|
|
201
161
|
function fetchStatus() {
|
|
202
162
|
if (!creativeId) {
|
|
203
|
-
showError(modal.dataset.noCreative);
|
|
163
|
+
showError(errorEl, modal.dataset.noCreative);
|
|
204
164
|
return;
|
|
205
165
|
}
|
|
206
|
-
clearError();
|
|
166
|
+
clearError(errorEl);
|
|
207
167
|
fetch(`/github/creatives/${creativeId}/integration`, { headers: { Accept: 'application/json' } })
|
|
208
168
|
.then(function (response) { return response.json(); })
|
|
209
169
|
.then(function (data) {
|
|
@@ -261,7 +221,7 @@ if (!githubIntegrationInitialized) {
|
|
|
261
221
|
}
|
|
262
222
|
})
|
|
263
223
|
.catch(function () {
|
|
264
|
-
showError('Github 연동 정보를 불러오지 못했습니다.');
|
|
224
|
+
showError(errorEl, 'Github 연동 정보를 불러오지 못했습니다.');
|
|
265
225
|
});
|
|
266
226
|
}
|
|
267
227
|
|
|
@@ -338,7 +298,7 @@ if (!githubIntegrationInitialized) {
|
|
|
338
298
|
renderOrganizations();
|
|
339
299
|
})
|
|
340
300
|
.catch(function () {
|
|
341
|
-
showError('Organization 목록을 불러오지 못했습니다.');
|
|
301
|
+
showError(errorEl, 'Organization 목록을 불러오지 못했습니다.');
|
|
342
302
|
});
|
|
343
303
|
}
|
|
344
304
|
|
|
@@ -352,13 +312,6 @@ if (!githubIntegrationInitialized) {
|
|
|
352
312
|
return;
|
|
353
313
|
}
|
|
354
314
|
organizations.forEach(function (org) {
|
|
355
|
-
const label = document.createElement('label');
|
|
356
|
-
label.style.display = 'flex';
|
|
357
|
-
label.style.alignItems = 'center';
|
|
358
|
-
label.style.gap = '0.5em';
|
|
359
|
-
label.style.marginBottom = '0.5em';
|
|
360
|
-
label.style.cursor = 'pointer';
|
|
361
|
-
|
|
362
315
|
const input = document.createElement('input');
|
|
363
316
|
input.type = 'radio';
|
|
364
317
|
input.name = 'github-organization';
|
|
@@ -371,19 +324,14 @@ if (!githubIntegrationInitialized) {
|
|
|
371
324
|
nextBtn.disabled = false;
|
|
372
325
|
});
|
|
373
326
|
|
|
374
|
-
|
|
375
|
-
span.textContent = org.name || org.login;
|
|
376
|
-
|
|
377
|
-
label.appendChild(input);
|
|
378
|
-
label.appendChild(span);
|
|
379
|
-
orgList.appendChild(label);
|
|
327
|
+
appendLabeledInput(orgList, input, org.name || org.login);
|
|
380
328
|
});
|
|
381
329
|
nextBtn.disabled = !selectedOrg;
|
|
382
330
|
}
|
|
383
331
|
|
|
384
332
|
function loadRepositories() {
|
|
385
333
|
if (!selectedOrg) return;
|
|
386
|
-
clearError();
|
|
334
|
+
clearError(errorEl);
|
|
387
335
|
if (repoList) {
|
|
388
336
|
repoList.textContent = '...';
|
|
389
337
|
}
|
|
@@ -396,7 +344,7 @@ if (!githubIntegrationInitialized) {
|
|
|
396
344
|
})
|
|
397
345
|
.catch(function () {
|
|
398
346
|
if (repoList) repoList.textContent = '';
|
|
399
|
-
showError('Repository 목록을 불러오지 못했습니다.');
|
|
347
|
+
showError(errorEl, 'Repository 목록을 불러오지 못했습니다.');
|
|
400
348
|
});
|
|
401
349
|
}
|
|
402
350
|
|
|
@@ -410,13 +358,6 @@ if (!githubIntegrationInitialized) {
|
|
|
410
358
|
return;
|
|
411
359
|
}
|
|
412
360
|
repositories.forEach(function (repo) {
|
|
413
|
-
const label = document.createElement('label');
|
|
414
|
-
label.style.display = 'flex';
|
|
415
|
-
label.style.alignItems = 'center';
|
|
416
|
-
label.style.gap = '0.5em';
|
|
417
|
-
label.style.marginBottom = '0.5em';
|
|
418
|
-
label.style.cursor = 'pointer';
|
|
419
|
-
|
|
420
361
|
const input = document.createElement('input');
|
|
421
362
|
input.type = 'checkbox';
|
|
422
363
|
input.value = repo.full_name;
|
|
@@ -429,12 +370,7 @@ if (!githubIntegrationInitialized) {
|
|
|
429
370
|
}
|
|
430
371
|
});
|
|
431
372
|
|
|
432
|
-
|
|
433
|
-
span.textContent = repo.full_name;
|
|
434
|
-
|
|
435
|
-
label.appendChild(input);
|
|
436
|
-
label.appendChild(span);
|
|
437
|
-
repoList.appendChild(label);
|
|
373
|
+
appendLabeledInput(repoList, input, repo.full_name);
|
|
438
374
|
});
|
|
439
375
|
}
|
|
440
376
|
|
|
@@ -497,25 +433,17 @@ if (!githubIntegrationInitialized) {
|
|
|
497
433
|
}
|
|
498
434
|
|
|
499
435
|
function saveSelection() {
|
|
500
|
-
clearError();
|
|
436
|
+
clearError(errorEl);
|
|
501
437
|
const markdownSync = {};
|
|
502
438
|
Array.from(selectedRepos).forEach(function (repo) {
|
|
503
439
|
markdownSync[repo] = markdownSyncRepos.has(repo);
|
|
504
440
|
});
|
|
505
441
|
const payload = { repositories: Array.from(selectedRepos), markdown_sync: markdownSync };
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
method: 'PATCH',
|
|
509
|
-
headers: {
|
|
510
|
-
'Content-Type': 'application/json',
|
|
511
|
-
'X-CSRF-Token': csrfToken()
|
|
512
|
-
},
|
|
513
|
-
body: JSON.stringify(payload)
|
|
514
|
-
})
|
|
515
|
-
.then(function (response) { return response.json().then(function (body) { return { ok: response.ok, body: body }; }); })
|
|
442
|
+
|
|
443
|
+
sendJson(`/github/creatives/${creativeId}/integration`, 'PATCH', payload)
|
|
516
444
|
.then(function (result) {
|
|
517
445
|
if (!result.ok) {
|
|
518
|
-
showError(result.body.error || '연동 저장 중 오류가 발생했습니다.');
|
|
446
|
+
showError(errorEl, result.body.error || '연동 저장 중 오류가 발생했습니다.');
|
|
519
447
|
return;
|
|
520
448
|
}
|
|
521
449
|
selectedRepos = new Set(result.body.selected_repositories || []);
|
|
@@ -526,16 +454,13 @@ if (!githubIntegrationInitialized) {
|
|
|
526
454
|
alertDialog(modal.dataset.successMessage);
|
|
527
455
|
})
|
|
528
456
|
.catch(function () {
|
|
529
|
-
showError('연동 정보를 저장하지 못했습니다.');
|
|
457
|
+
showError(errorEl, '연동 정보를 저장하지 못했습니다.');
|
|
530
458
|
});
|
|
531
459
|
}
|
|
532
460
|
|
|
533
461
|
openBtn.addEventListener('click', function () {
|
|
534
|
-
creativeId = openBtn
|
|
535
|
-
if (!creativeId)
|
|
536
|
-
alertDialog(modal.dataset.noCreative);
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
462
|
+
creativeId = requireCreativeId(openBtn, modal);
|
|
463
|
+
if (!creativeId) return;
|
|
539
464
|
resetWizard();
|
|
540
465
|
showModal();
|
|
541
466
|
fetchStatus();
|
|
@@ -547,7 +472,7 @@ if (!githubIntegrationInitialized) {
|
|
|
547
472
|
});
|
|
548
473
|
|
|
549
474
|
prevBtn.addEventListener('click', function () {
|
|
550
|
-
clearError();
|
|
475
|
+
clearError(errorEl);
|
|
551
476
|
if (currentStep === 'organization') {
|
|
552
477
|
currentStep = 'connect';
|
|
553
478
|
} else if (currentStep === 'repositories') {
|
|
@@ -563,7 +488,7 @@ if (!githubIntegrationInitialized) {
|
|
|
563
488
|
});
|
|
564
489
|
|
|
565
490
|
nextBtn.addEventListener('click', function () {
|
|
566
|
-
clearError();
|
|
491
|
+
clearError(errorEl);
|
|
567
492
|
if (currentStep === 'connect') {
|
|
568
493
|
currentStep = 'organization';
|
|
569
494
|
updateStep();
|
|
@@ -613,26 +538,18 @@ if (!githubIntegrationInitialized) {
|
|
|
613
538
|
alertDialog(modal.dataset.noCreative);
|
|
614
539
|
return;
|
|
615
540
|
}
|
|
616
|
-
clearError();
|
|
541
|
+
clearError(errorEl);
|
|
617
542
|
const selectedToDelete = Array.from(selectedReposForDeletion);
|
|
618
543
|
if (!selectedToDelete.length) {
|
|
619
|
-
showError(deleteSelectWarning);
|
|
544
|
+
showError(errorEl, deleteSelectWarning);
|
|
620
545
|
return;
|
|
621
546
|
}
|
|
622
547
|
if (!(await confirmDialog(deleteConfirm, { danger: true }))) return;
|
|
623
548
|
|
|
624
|
-
|
|
625
|
-
method: 'DELETE',
|
|
626
|
-
headers: {
|
|
627
|
-
'Content-Type': 'application/json',
|
|
628
|
-
'X-CSRF-Token': csrfToken()
|
|
629
|
-
},
|
|
630
|
-
body: JSON.stringify({ repositories: selectedToDelete })
|
|
631
|
-
})
|
|
632
|
-
.then(function (response) { return response.json().then(function (body) { return { ok: response.ok, body: body }; }); })
|
|
549
|
+
sendJson(`/github/creatives/${creativeId}/integration`, 'DELETE', { repositories: selectedToDelete })
|
|
633
550
|
.then(function (result) {
|
|
634
551
|
if (!result.ok) {
|
|
635
|
-
showError(result.body.error || deleteError);
|
|
552
|
+
showError(errorEl, result.body.error || deleteError);
|
|
636
553
|
return;
|
|
637
554
|
}
|
|
638
555
|
|
|
@@ -654,17 +571,17 @@ if (!githubIntegrationInitialized) {
|
|
|
654
571
|
}
|
|
655
572
|
})
|
|
656
573
|
.catch(function () {
|
|
657
|
-
showError(deleteError);
|
|
574
|
+
showError(errorEl, deleteError);
|
|
658
575
|
});
|
|
659
576
|
});
|
|
660
577
|
|
|
661
578
|
resyncBtn?.addEventListener('click', async function () {
|
|
662
579
|
if (!creativeId) return;
|
|
663
|
-
clearError();
|
|
580
|
+
clearError(errorEl);
|
|
664
581
|
const checkboxes = existingList ? existingList.querySelectorAll('.github-existing-repo-checkbox:checked') : [];
|
|
665
582
|
const selectedToResync = Array.from(checkboxes).map(cb => cb.value);
|
|
666
583
|
if (!selectedToResync.length) {
|
|
667
|
-
showError(resyncSelectWarning);
|
|
584
|
+
showError(errorEl, resyncSelectWarning);
|
|
668
585
|
return;
|
|
669
586
|
}
|
|
670
587
|
if (!(await confirmDialog(resyncConfirm))) return;
|
|
@@ -674,21 +591,13 @@ if (!githubIntegrationInitialized) {
|
|
|
674
591
|
let failed = 0;
|
|
675
592
|
|
|
676
593
|
selectedToResync.forEach(function (repo) {
|
|
677
|
-
|
|
678
|
-
method: 'POST',
|
|
679
|
-
headers: {
|
|
680
|
-
'Content-Type': 'application/json',
|
|
681
|
-
'X-CSRF-Token': csrfToken()
|
|
682
|
-
},
|
|
683
|
-
body: JSON.stringify({ repository: repo })
|
|
684
|
-
})
|
|
685
|
-
.then(function (response) { return response.json().then(function (body) { return { ok: response.ok, body: body }; }); })
|
|
594
|
+
sendJson(`/github/creatives/${creativeId}/integration/resync`, 'POST', { repository: repo })
|
|
686
595
|
.then(function (result) {
|
|
687
596
|
completed++;
|
|
688
597
|
if (!result.ok) failed++;
|
|
689
598
|
if (completed === selectedToResync.length) {
|
|
690
599
|
if (failed > 0) {
|
|
691
|
-
showError(resyncError);
|
|
600
|
+
showError(errorEl, resyncError);
|
|
692
601
|
} else {
|
|
693
602
|
statusEl.textContent = resyncSuccess;
|
|
694
603
|
}
|
|
@@ -699,7 +608,7 @@ if (!githubIntegrationInitialized) {
|
|
|
699
608
|
completed++;
|
|
700
609
|
failed++;
|
|
701
610
|
if (completed === selectedToResync.length) {
|
|
702
|
-
showError(resyncError);
|
|
611
|
+
showError(errorEl, resyncError);
|
|
703
612
|
resyncBtn.disabled = false;
|
|
704
613
|
}
|
|
705
614
|
});
|
|
@@ -10,10 +10,12 @@ module CollavreGithub
|
|
|
10
10
|
user = link.creative.user
|
|
11
11
|
return unless user
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
Collavre::Creatives::History.track(actor: nil, origin: :sync) do
|
|
14
|
+
CollavreGithub::MarkdownSync::InitialImportService.new(
|
|
15
|
+
repository_link: link,
|
|
16
|
+
user: user
|
|
17
|
+
).call
|
|
18
|
+
end
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -7,10 +7,12 @@ module CollavreGithub
|
|
|
7
7
|
link = CollavreGithub::RepositoryLink.find_by(id: repository_link_id)
|
|
8
8
|
return unless link&.markdown_sync_enabled?
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
Collavre::Creatives::History.track(actor: nil, origin: :sync) do
|
|
11
|
+
CollavreGithub::MarkdownSync::IncrementalSyncService.new(
|
|
12
|
+
repository_link: link,
|
|
13
|
+
push_payload: push_payload
|
|
14
|
+
).call
|
|
15
|
+
end
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module CollavreGithub
|
|
2
|
+
class PrBlockerSweepJob < ApplicationJob
|
|
3
|
+
queue_as :default
|
|
4
|
+
|
|
5
|
+
limits_concurrency to: 1,
|
|
6
|
+
key: -> { "github-pr-blocker-sweep" },
|
|
7
|
+
duration: 1.hour,
|
|
8
|
+
on_conflict: :discard
|
|
9
|
+
|
|
10
|
+
def perform
|
|
11
|
+
GithubPrChannel.active.not_dismissed.find_each do |channel|
|
|
12
|
+
PrBlockerMonitor.new(channel).call
|
|
13
|
+
rescue StandardError => e
|
|
14
|
+
Rails.logger.warn("[CollavreGithub] PR blocker check failed for channel #{channel.id}: #{e.class}")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -2,6 +2,7 @@ module CollavreGithub
|
|
|
2
2
|
class GithubPrChannel < Collavre::Channel
|
|
3
3
|
self.table_name = "channels"
|
|
4
4
|
|
|
5
|
+
before_create :initialize_discussion_tracking
|
|
5
6
|
after_destroy_commit :broadcast_chips_changed
|
|
6
7
|
|
|
7
8
|
def repo_full_name
|
|
@@ -136,21 +137,59 @@ module CollavreGithub
|
|
|
136
137
|
)
|
|
137
138
|
end
|
|
138
139
|
|
|
140
|
+
def blocker_message(key, **options)
|
|
141
|
+
Collavre::Channel::InjectedMessage.new(
|
|
142
|
+
speaker: channel_bot_user,
|
|
143
|
+
message: t(key, label: label, url: pr_url, **options),
|
|
144
|
+
label: label,
|
|
145
|
+
link: pr_url
|
|
146
|
+
)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def discussion_poll_since
|
|
150
|
+
config["discussion_poll_since"]&.to_time || last_event_at || created_at
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def start_discussion_tracking!(since = discussion_poll_since)
|
|
154
|
+
return if config.key?("discussion_poll_since")
|
|
155
|
+
|
|
156
|
+
update!(config: config.merge("discussion_poll_since" => since.iso8601(6)))
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Both callers hold the channel lock so the message and its GitHub ID commit together.
|
|
160
|
+
def deliver_event!(event:, payload:)
|
|
161
|
+
definition = PrDiscussionEvent::EVENTS[event]
|
|
162
|
+
external_id = payload.dig(definition.resource, "id") if definition
|
|
163
|
+
key = "#{event}:#{external_id}" if external_id.present?
|
|
164
|
+
delivered = config.fetch("discussion_event_ids", [])
|
|
165
|
+
return if key && delivered.include?(key)
|
|
166
|
+
|
|
167
|
+
injected = handle(event: event, payload: payload)
|
|
168
|
+
return unless injected
|
|
169
|
+
|
|
170
|
+
start_discussion_tracking! if definition
|
|
171
|
+
inject_into_topic!(injected)
|
|
172
|
+
update!(config: config.merge("discussion_event_ids" => delivered + [ key ])) if key
|
|
173
|
+
detach! if event == "pull_request" && payload["action"] == "closed"
|
|
174
|
+
end
|
|
175
|
+
|
|
139
176
|
def handle(event:, payload:)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
when "pull_request"
|
|
148
|
-
handle_pull_request(payload)
|
|
149
|
-
end
|
|
177
|
+
return handle_pull_request(payload) if event == "pull_request"
|
|
178
|
+
|
|
179
|
+
definition = PrDiscussionEvent::EVENTS[event]
|
|
180
|
+
return unless definition && payload["action"] == definition.action
|
|
181
|
+
return if event == "issue_comment" && !payload.dig("issue", "pull_request")
|
|
182
|
+
|
|
183
|
+
send(definition.handler, payload.fetch(definition.resource))
|
|
150
184
|
end
|
|
151
185
|
|
|
152
186
|
private
|
|
153
187
|
|
|
188
|
+
def initialize_discussion_tracking
|
|
189
|
+
# GitHub event timestamps have second precision.
|
|
190
|
+
self.config = config.reverse_merge("discussion_poll_since" => (created_at || Time.current).iso8601)
|
|
191
|
+
end
|
|
192
|
+
|
|
154
193
|
def preferred_over?(other)
|
|
155
194
|
(lifecycle_priority(self) <=> lifecycle_priority(other)) == 1
|
|
156
195
|
end
|
|
@@ -180,9 +219,7 @@ module CollavreGithub
|
|
|
180
219
|
# message, so the chip stays visible until the closing comment lands.
|
|
181
220
|
end
|
|
182
221
|
|
|
183
|
-
def handle_review_submitted(
|
|
184
|
-
return nil unless payload["action"] == "submitted"
|
|
185
|
-
review = payload["review"]
|
|
222
|
+
def handle_review_submitted(review)
|
|
186
223
|
body = review["body"].to_s
|
|
187
224
|
return nil if body.strip.empty?
|
|
188
225
|
|
|
@@ -197,9 +234,7 @@ module CollavreGithub
|
|
|
197
234
|
)
|
|
198
235
|
end
|
|
199
236
|
|
|
200
|
-
def handle_review_comment(
|
|
201
|
-
return nil unless payload["action"] == "created"
|
|
202
|
-
comment = payload["comment"]
|
|
237
|
+
def handle_review_comment(comment)
|
|
203
238
|
author = comment.dig("user", "login")
|
|
204
239
|
return nil if ignored_actor?(author)
|
|
205
240
|
path = comment["path"]
|
|
@@ -222,11 +257,7 @@ module CollavreGithub
|
|
|
222
257
|
)
|
|
223
258
|
end
|
|
224
259
|
|
|
225
|
-
def handle_issue_comment(
|
|
226
|
-
return nil unless payload["action"] == "created"
|
|
227
|
-
return nil unless payload.dig("issue", "pull_request") # PR comments only
|
|
228
|
-
|
|
229
|
-
comment = payload["comment"]
|
|
260
|
+
def handle_issue_comment(comment)
|
|
230
261
|
author = comment.dig("user", "login")
|
|
231
262
|
return nil if ignored_actor?(author)
|
|
232
263
|
body = comment["body"].to_s
|
|
@@ -7,8 +7,8 @@ module CollavreGithub
|
|
|
7
7
|
belongs_to :markdown_root_creative, class_name: "Collavre::Creative", optional: true
|
|
8
8
|
|
|
9
9
|
# HMAC secret GitHub signs webhook deliveries with. Encrypted at rest so a
|
|
10
|
-
# DB/backup leak can't forge webhooks (mirrors CollavreGithub::Account#token
|
|
11
|
-
#
|
|
10
|
+
# DB/backup leak can't forge webhooks (mirrors CollavreGithub::Account#token).
|
|
11
|
+
# Non-deterministic: the
|
|
12
12
|
# value is only ever read back decrypted (WebhooksController, provisioner),
|
|
13
13
|
# never queried by ciphertext. A backfill migration re-encrypts pre-existing
|
|
14
14
|
# plaintext rows.
|
|
@@ -39,6 +39,29 @@ module CollavreGithub
|
|
|
39
39
|
nil
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
def pull_request_discussion(repo_full_name, endpoint)
|
|
43
|
+
client.paginate("repos/#{repo_full_name}/#{endpoint}").map { |item| item.to_h.deep_stringify_keys }
|
|
44
|
+
rescue Octokit::Error, Faraday::Error => e
|
|
45
|
+
Rails.logger.warn("GitHub PR discussion fetch failed: #{e.class}")
|
|
46
|
+
[]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def pull_request_check_runs(repo_full_name, sha)
|
|
50
|
+
client.check_runs_for_ref(repo_full_name, sha).check_runs
|
|
51
|
+
rescue Octokit::Error, Faraday::Error => e
|
|
52
|
+
Rails.logger.warn("GitHub check runs fetch failed: #{e.class}")
|
|
53
|
+
[]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def pull_request_commit_statuses(repo_full_name, sha)
|
|
57
|
+
client.paginate("repos/#{repo_full_name}/commits/#{sha}/status") do |data, response|
|
|
58
|
+
data.statuses.concat(response.data.statuses)
|
|
59
|
+
end.statuses
|
|
60
|
+
rescue Octokit::Error, Faraday::Error => e
|
|
61
|
+
Rails.logger.warn("GitHub commit statuses fetch failed: #{e.class}")
|
|
62
|
+
[]
|
|
63
|
+
end
|
|
64
|
+
|
|
42
65
|
def pull_request_commit_messages(repo_full_name, number)
|
|
43
66
|
client
|
|
44
67
|
.pull_request_commits(repo_full_name, number)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module CollavreGithub
|
|
2
|
+
module MarkdownSync
|
|
3
|
+
# A synced markdown file is two creatives: the file creative (filename,
|
|
4
|
+
# path anchor) and a single child content creative holding the file body
|
|
5
|
+
# as markdown_source. Both are github_markdown sources, so the body stays
|
|
6
|
+
# read-only until reverse sync lands.
|
|
7
|
+
module ContentCreative
|
|
8
|
+
ROLE = "content".freeze
|
|
9
|
+
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def content?(creative)
|
|
13
|
+
creative.data.is_a?(Hash) && creative.data.dig("source", "role") == ROLE
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def find(file_creative)
|
|
17
|
+
file_creative.children.where(archived_at: nil).detect { |child| content?(child) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Creates or updates the content creative under file_creative.
|
|
21
|
+
# Returns the creative when it was newly created, nil otherwise.
|
|
22
|
+
def upsert!(file_creative, markdown, user:)
|
|
23
|
+
existing = find(file_creative)
|
|
24
|
+
if existing
|
|
25
|
+
update!(existing, markdown)
|
|
26
|
+
return nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
creative = Collavre::Creative.new(
|
|
30
|
+
parent: file_creative,
|
|
31
|
+
user: user,
|
|
32
|
+
data: { "source" => source_for(file_creative) }
|
|
33
|
+
)
|
|
34
|
+
assign_markdown(creative, markdown)
|
|
35
|
+
creative.save!
|
|
36
|
+
creative
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def update!(creative, markdown)
|
|
40
|
+
assign_markdown(creative, markdown)
|
|
41
|
+
creative.skip_read_only_source_validation = true
|
|
42
|
+
creative.save!
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def source_for(file_creative)
|
|
46
|
+
file_creative.data["source"].slice("type", "repo", "path", "repository_link_id").merge("role" => ROLE)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def assign_markdown(creative, markdown)
|
|
50
|
+
creative.content_type_input = "markdown"
|
|
51
|
+
creative.markdown_editor = "source"
|
|
52
|
+
creative.markdown_source = markdown
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -38,7 +38,10 @@ module CollavreGithub
|
|
|
38
38
|
|
|
39
39
|
def process_image(match, alt, url, dir, blobs)
|
|
40
40
|
url_path = strip_fragment_and_query(url)
|
|
41
|
+
return match if url_path.include?("\0")
|
|
42
|
+
|
|
41
43
|
resolved = resolve_path(dir, url_path)
|
|
44
|
+
return match unless repository_image_path?(resolved)
|
|
42
45
|
|
|
43
46
|
blob = download_and_upload(resolved)
|
|
44
47
|
return match unless blob
|
|
@@ -48,6 +51,18 @@ module CollavreGithub
|
|
|
48
51
|
""
|
|
49
52
|
end
|
|
50
53
|
|
|
54
|
+
def repository_image_path?(path)
|
|
55
|
+
return false if path.empty?
|
|
56
|
+
|
|
57
|
+
# Check the URL-decoded form as well because Octokit interpolates the path into a URL.
|
|
58
|
+
decoded = URI::DEFAULT_PARSER.unescape(path).b.tr("\\", "/")
|
|
59
|
+
return false if decoded.include?("\0")
|
|
60
|
+
|
|
61
|
+
[ path, Pathname.new(decoded).cleanpath.to_s ].none? do |candidate|
|
|
62
|
+
candidate.match?(%r{\A(?:/|\.\.?(?:/|\z))})
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
51
66
|
def process_link(match, label, url, dir)
|
|
52
67
|
url_path, fragment = url.split("#", 2)
|
|
53
68
|
url_path = strip_query(url_path)
|
|
@@ -102,7 +117,7 @@ module CollavreGithub
|
|
|
102
117
|
end
|
|
103
118
|
|
|
104
119
|
def strip_fragment_and_query(url)
|
|
105
|
-
url.
|
|
120
|
+
url.partition("#").first.partition("?").first
|
|
106
121
|
end
|
|
107
122
|
|
|
108
123
|
def strip_query(url)
|
|
@@ -76,8 +76,9 @@ module CollavreGithub
|
|
|
76
76
|
creative.skip_read_only_source_validation = true
|
|
77
77
|
creative.update!(data: creative.data.merge("source" => source))
|
|
78
78
|
|
|
79
|
-
processed,
|
|
80
|
-
|
|
79
|
+
processed, _blobs = processor.process(content, path)
|
|
80
|
+
content_creative = ContentCreative.upsert!(creative, processed, user: @user)
|
|
81
|
+
created << content_creative if content_creative
|
|
81
82
|
end
|
|
82
83
|
|
|
83
84
|
added_paths.each do |path|
|
|
@@ -111,10 +112,9 @@ module CollavreGithub
|
|
|
111
112
|
creative.save!
|
|
112
113
|
@synced_creatives[path] = creative
|
|
113
114
|
|
|
114
|
-
processed,
|
|
115
|
-
comment = create_content_comment(creative, processed)
|
|
116
|
-
attach_blobs(comment, blobs) if blobs.any?
|
|
115
|
+
processed, _blobs = processor.process(content, path)
|
|
117
116
|
created << creative
|
|
117
|
+
created << ContentCreative.upsert!(creative, processed, user: @user)
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
resequence_affected_parents(created)
|
|
@@ -143,36 +143,11 @@ module CollavreGithub
|
|
|
143
143
|
.where(archived_at: nil)
|
|
144
144
|
.where("CAST(data -> 'source' ->> 'repository_link_id' AS INTEGER) = ?", @link.id)
|
|
145
145
|
|
|
146
|
-
scope.each_with_object({})
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def create_content_comment(creative, markdown_content)
|
|
150
|
-
topic = creative.content_topic(fallback_user: @user)
|
|
151
|
-
creative.comments.create!(
|
|
152
|
-
content: markdown_content,
|
|
153
|
-
topic: topic,
|
|
154
|
-
user: @user,
|
|
155
|
-
skip_dispatch: true
|
|
156
|
-
)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def update_content_comment(creative, markdown_content, blobs = [])
|
|
160
|
-
topic = creative.content_topic(fallback_user: @user)
|
|
161
|
-
comment = creative.comments.where(topic: topic).order(:created_at).first
|
|
162
|
-
if comment
|
|
163
|
-
comment.images.purge if comment.images.attached?
|
|
164
|
-
comment.update!(content: markdown_content)
|
|
165
|
-
attach_blobs(comment, blobs) if blobs.any?
|
|
166
|
-
else
|
|
167
|
-
comment = create_content_comment(creative, markdown_content)
|
|
168
|
-
attach_blobs(comment, blobs) if blobs.any?
|
|
146
|
+
scope.each_with_object({}) do |c, h|
|
|
147
|
+
h[c.data.dig("source", "path")] = c unless ContentCreative.content?(c)
|
|
169
148
|
end
|
|
170
149
|
end
|
|
171
150
|
|
|
172
|
-
def attach_blobs(comment, blobs)
|
|
173
|
-
blobs.each { |blob| comment.images.attach(blob) }
|
|
174
|
-
end
|
|
175
|
-
|
|
176
151
|
def resequence_affected_parents(new_creatives)
|
|
177
152
|
parent_ids = new_creatives.map(&:parent_id).compact.uniq
|
|
178
153
|
Collavre::Creative.transaction do
|
|
@@ -184,8 +159,11 @@ module CollavreGithub
|
|
|
184
159
|
is_dir = path.end_with?("/") || path == ""
|
|
185
160
|
[ is_dir ? 0 : 1, c.description.to_s.downcase ]
|
|
186
161
|
end
|
|
187
|
-
sorted.each_with_index do |
|
|
188
|
-
|
|
162
|
+
changes = sorted.each_with_index.filter_map do |creative, index|
|
|
163
|
+
[ creative, index ] if creative.sequence != index
|
|
164
|
+
end
|
|
165
|
+
Collavre::Creatives::History.record_bulk(changes.map(&:first), operation: "reorder") do
|
|
166
|
+
changes.each { |creative, index| creative.update_column(:sequence, index) }
|
|
189
167
|
end
|
|
190
168
|
end
|
|
191
169
|
end
|
|
@@ -77,9 +77,8 @@ module CollavreGithub
|
|
|
77
77
|
raw_md = creative.data.dig("source", "markdown")
|
|
78
78
|
next if raw_md.blank?
|
|
79
79
|
|
|
80
|
-
processed,
|
|
81
|
-
|
|
82
|
-
attach_blobs(comment, blobs) if blobs.any?
|
|
80
|
+
processed, _blobs = processor.process(raw_md, creative.data.dig("source", "path"))
|
|
81
|
+
created << ContentCreative.upsert!(creative, processed, user: @user)
|
|
83
82
|
end
|
|
84
83
|
|
|
85
84
|
resequence_directories_first(created)
|
|
@@ -126,20 +125,6 @@ module CollavreGithub
|
|
|
126
125
|
end
|
|
127
126
|
end
|
|
128
127
|
|
|
129
|
-
def create_content_comment(creative, markdown_content)
|
|
130
|
-
topic = creative.content_topic(fallback_user: @user)
|
|
131
|
-
creative.comments.create!(
|
|
132
|
-
content: markdown_content,
|
|
133
|
-
topic: topic,
|
|
134
|
-
user: @user,
|
|
135
|
-
skip_dispatch: true
|
|
136
|
-
)
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def attach_blobs(comment, blobs)
|
|
140
|
-
blobs.each { |blob| comment.images.attach(blob) }
|
|
141
|
-
end
|
|
142
|
-
|
|
143
128
|
def resequence_directories_first(creatives)
|
|
144
129
|
Collavre::Creative.transaction do
|
|
145
130
|
creatives.group_by(&:parent_id).each do |_parent_id, siblings|
|
|
@@ -148,8 +133,10 @@ module CollavreGithub
|
|
|
148
133
|
is_dir = path.end_with?("/") || path == ""
|
|
149
134
|
[ is_dir ? 0 : 1, c.description.to_s.downcase ]
|
|
150
135
|
end
|
|
151
|
-
sorted
|
|
152
|
-
|
|
136
|
+
Collavre::Creatives::History.record_bulk(sorted, operation: "reorder") do
|
|
137
|
+
sorted.each_with_index do |creative, index|
|
|
138
|
+
creative.update_column(:sequence, index)
|
|
139
|
+
end
|
|
153
140
|
end
|
|
154
141
|
end
|
|
155
142
|
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module CollavreGithub
|
|
2
|
+
class PrBlockerMonitor
|
|
3
|
+
FAILURE_CONCLUSIONS = %w[failure timed_out startup_failure action_required].freeze
|
|
4
|
+
FAILURE_STATES = %w[error failure].freeze
|
|
5
|
+
|
|
6
|
+
def initialize(channel)
|
|
7
|
+
@channel = channel
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def call
|
|
11
|
+
repo = channel.repo_full_name
|
|
12
|
+
number = channel.pr_number
|
|
13
|
+
link = repository_link(repo)
|
|
14
|
+
return unless link
|
|
15
|
+
|
|
16
|
+
client = Client.new(link.github_account)
|
|
17
|
+
pr = client.pull_request_details(repo, number)
|
|
18
|
+
return unless pr&.state == "open" && pr.base.repo.id.to_s == link.repository_id.to_s
|
|
19
|
+
|
|
20
|
+
head = pr.head.sha
|
|
21
|
+
return if head.blank?
|
|
22
|
+
|
|
23
|
+
poll_updates(client, link, pr, repo, number)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
attr_reader :channel
|
|
29
|
+
|
|
30
|
+
def poll_updates(client, link, pr, repo, number)
|
|
31
|
+
since = channel.discussion_poll_since
|
|
32
|
+
discussion = PrDiscussionEvent.poll(client, repo, number, since: since)
|
|
33
|
+
failures = check_failures(client, repo, pr.head.sha)
|
|
34
|
+
channel.with_lock do
|
|
35
|
+
next unless monitoring?(repo, number)
|
|
36
|
+
next unless repository_link(repo)&.repository_id == link.repository_id
|
|
37
|
+
|
|
38
|
+
channel.start_discussion_tracking!(since)
|
|
39
|
+
record_blockers(pr.head.sha, pr.mergeable, failures)
|
|
40
|
+
discussion.each do |_timestamp, event, payload|
|
|
41
|
+
channel.deliver_event!(event: event, payload: payload)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def monitoring?(repo, number)
|
|
47
|
+
channel.active? && !channel.dismissed? && channel.pr_state == "open" &&
|
|
48
|
+
channel.repo_full_name == repo && channel.pr_number == number
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def repository_link(repo)
|
|
52
|
+
creative = channel.topic.reload.creative
|
|
53
|
+
links = RepositoryLink.where(creative_id: [ creative.id ] + creative.ancestors.pluck(:id))
|
|
54
|
+
.where("LOWER(repository_full_name) = ?", repo.to_s.downcase)
|
|
55
|
+
.includes(:github_account).to_a
|
|
56
|
+
repo_ids = links.map(&:repository_id).uniq
|
|
57
|
+
links.first if repo_ids.one? && repo_ids.first.present?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def check_failures(client, repo, head)
|
|
61
|
+
runs = client.pull_request_check_runs(repo, head).filter_map do |run|
|
|
62
|
+
next unless run.status == "completed" && FAILURE_CONCLUSIONS.include?(run.conclusion)
|
|
63
|
+
|
|
64
|
+
[ "run:#{run.id}:#{run.completed_at}", run.name ]
|
|
65
|
+
end
|
|
66
|
+
statuses = client.pull_request_commit_statuses(repo, head).filter_map do |status|
|
|
67
|
+
next unless FAILURE_STATES.include?(status.state)
|
|
68
|
+
|
|
69
|
+
[ "status:#{status.id}", status.context ]
|
|
70
|
+
end
|
|
71
|
+
(runs + statuses).to_h
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def record_blockers(head, mergeable, failures)
|
|
75
|
+
previous = channel.config.fetch("pr_blockers", {})
|
|
76
|
+
notified = previous["head"] == head ? previous.fetch("check_ids", []) : []
|
|
77
|
+
new_failures = failures.except(*notified)
|
|
78
|
+
conflict = mergeable.nil? ? previous["conflict"] : !mergeable
|
|
79
|
+
|
|
80
|
+
if conflict && !previous["conflict"]
|
|
81
|
+
channel.inject_into_topic!(channel.blocker_message("merge_conflict_message"))
|
|
82
|
+
end
|
|
83
|
+
if new_failures.any?
|
|
84
|
+
channel.inject_into_topic!(
|
|
85
|
+
channel.blocker_message("failed_checks_message", checks: new_failures.values.map(&:squish).uniq.join(", "))
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
current = { "head" => head, "conflict" => conflict, "check_ids" => notified | failures.keys }
|
|
90
|
+
channel.update!(config: channel.config.merge("pr_blockers" => current)) if current != previous
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module CollavreGithub
|
|
2
|
+
class PrDiscussionEvent
|
|
3
|
+
Definition = Data.define(:resource, :action, :handler, :endpoint, :timestamp)
|
|
4
|
+
|
|
5
|
+
EVENTS = {
|
|
6
|
+
"issue_comment" => Definition.new("comment", "created", :handle_issue_comment, "issues/%s/comments", "created_at"),
|
|
7
|
+
"pull_request_review_comment" => Definition.new("comment", "created", :handle_review_comment, "pulls/%s/comments", "created_at"),
|
|
8
|
+
"pull_request_review" => Definition.new("review", "submitted", :handle_review_submitted, "pulls/%s/reviews", "submitted_at")
|
|
9
|
+
}.freeze
|
|
10
|
+
|
|
11
|
+
def self.poll(client, repo, number, since:)
|
|
12
|
+
EVENTS.flat_map do |event, definition|
|
|
13
|
+
client.pull_request_discussion(repo, format(definition.endpoint, number)).filter_map do |resource|
|
|
14
|
+
timestamp = resource[definition.timestamp]&.to_time
|
|
15
|
+
next unless resource["id"].present? && timestamp && timestamp >= since
|
|
16
|
+
|
|
17
|
+
resource["state"] = resource["state"].to_s.downcase if definition.resource == "review"
|
|
18
|
+
payload = { "action" => definition.action, definition.resource => resource }
|
|
19
|
+
payload["issue"] = { "number" => number, "pull_request" => {} } if event == "issue_comment"
|
|
20
|
+
[ timestamp, event, payload ]
|
|
21
|
+
end
|
|
22
|
+
end.sort_by(&:first)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -13,9 +13,10 @@ module CollavreGithub
|
|
|
13
13
|
tool_name "pr_monitor"
|
|
14
14
|
tool_description <<~DESC.strip
|
|
15
15
|
Attach a GitHub PR monitor to a Collavre topic. After attachment,
|
|
16
|
-
PR comments,
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
PR comments, reviews, merge conflicts, and failed CI checks are posted
|
|
17
|
+
as topic messages. Every five minutes, verified repository links are
|
|
18
|
+
checked for missed comments and reviews, merge conflicts, and failed
|
|
19
|
+
CI checks. Returns a typed channel reference. Idempotent.
|
|
19
20
|
DESC
|
|
20
21
|
|
|
21
22
|
tool_param :topic_id, description: "The Collavre topic id to attach the PR channel to."
|
|
@@ -5,7 +5,7 @@ module CollavreGithub
|
|
|
5
5
|
# GitHub never delivers the relevant deliveries, so pr_monitor would attach
|
|
6
6
|
# a channel that silently misses comments. `pull_request` is required by
|
|
7
7
|
# the auto-attach + close detection paths.
|
|
8
|
-
CHANNEL_EVENTS =
|
|
8
|
+
CHANNEL_EVENTS = PrDiscussionEvent::EVENTS.keys.freeze
|
|
9
9
|
|
|
10
10
|
# `repository` carries the `renamed` action. Without it a rename is
|
|
11
11
|
# invisible to this app: `repository_full_name` goes stale on every link at
|
data/config/locales/en.yml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
en:
|
|
2
2
|
collavre_github:
|
|
3
|
+
tool_category: "GitHub"
|
|
3
4
|
integration:
|
|
4
5
|
label: "GitHub"
|
|
5
6
|
description: "Connect repositories and receive webhook events"
|
|
@@ -106,6 +107,8 @@ en:
|
|
|
106
107
|
review_submitted_message: "**@%{author}** submitted a review (`%{state}`) on %{label}:\n\n%{body}"
|
|
107
108
|
closed_message: "%{label} was **%{verb}**. Detaching channel."
|
|
108
109
|
attached_message: "%{label} monitoring started.\n\n%{url}"
|
|
110
|
+
merge_conflict_message: "%{label} has a merge conflict.\n\n%{url}"
|
|
111
|
+
failed_checks_message: "%{label} has failed CI checks: %{checks}.\n\n%{url}/checks"
|
|
109
112
|
reopened_message: "%{label} was reopened. Monitoring resumed.\n\n%{url}"
|
|
110
113
|
auth_failure_message: "⚠️ A GitHub webhook delivery for `%{repo}` could not be verified, so events for %{label} are **not being received**.\n\nThis usually means the repository was renamed or its webhook secret was changed. Re-run the GitHub integration setup for this repository to restore delivery.\n\n%{url}"
|
|
111
114
|
badge:
|
data/config/locales/ko.yml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
ko:
|
|
2
2
|
collavre_github:
|
|
3
|
+
tool_category: "GitHub"
|
|
3
4
|
integration:
|
|
4
5
|
label: "GitHub"
|
|
5
6
|
description: "저장소를 연결하고 웹훅 이벤트를 받습니다"
|
|
@@ -106,6 +107,8 @@ ko:
|
|
|
106
107
|
review_submitted_message: "**@%{author}**님이 %{label}에 리뷰를 제출했습니다 (`%{state}`):\n\n%{body}"
|
|
107
108
|
closed_message: "%{label}이(가) **%{verb}** 되었습니다. 채널을 해제합니다."
|
|
108
109
|
attached_message: "%{label} 모니터링이 시작되었습니다.\n\n%{url}"
|
|
110
|
+
merge_conflict_message: "%{label}에 병합 충돌이 있습니다.\n\n%{url}"
|
|
111
|
+
failed_checks_message: "%{label}에서 CI 검사에 실패했습니다: %{checks}.\n\n%{url}/checks"
|
|
109
112
|
reopened_message: "%{label}이(가) 재오픈되어 모니터링이 재개되었습니다.\n\n%{url}"
|
|
110
113
|
auth_failure_message: "⚠️ `%{repo}` 저장소의 GitHub 웹훅 전달을 검증하지 못해 %{label}의 이벤트를 **수신하지 못하고 있습니다**.\n\n저장소 이름이 변경되었거나 웹훅 시크릿이 바뀐 경우입니다. 해당 저장소의 GitHub 연동 설정을 다시 실행하면 복구됩니다.\n\n%{url}"
|
|
111
114
|
badge:
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
en:
|
|
2
|
+
collavre:
|
|
3
|
+
tool_descriptions:
|
|
4
|
+
github_pr_commits:
|
|
5
|
+
summary: Get the commit messages of a GitHub pull request.
|
|
6
|
+
details: Requires the Creative to have a connected GitHub repository.
|
|
7
|
+
github_pr_details:
|
|
8
|
+
summary: Get a GitHub pull request's title, body, author, and changed files.
|
|
9
|
+
details: The PR body is truncated to 2,000 characters, so the end of a long description may be missing. Requires the Creative to have a connected GitHub repository.
|
|
10
|
+
github_pr_diff:
|
|
11
|
+
summary: Get the diff of a GitHub pull request.
|
|
12
|
+
details: Returns the combined patch of the changed files that have a text patch; files without one (such as binary or very large files) are left out. The result is truncated to max_length characters (default 10,000), so later files may be cut off in large PRs. Requires the Creative to have a connected GitHub repository.
|
|
13
|
+
pr_monitor:
|
|
14
|
+
summary: Follow a GitHub pull request in a topic.
|
|
15
|
+
details: PR comments, reviews, merge conflicts, and failed CI checks are posted as topic messages. For verified repository links, polling checks every five minutes for missed comments and reviews, merge conflicts, and failed CI checks. Calling it again for the same PR does not add a duplicate.
|
|
16
|
+
pr_state_set:
|
|
17
|
+
summary: Fix a monitored pull request's state when GitHub's update was missed.
|
|
18
|
+
details: |-
|
|
19
|
+
Without a state, the tool resynchronizes from GitHub, which is the preferred form. Pass a state only when no GitHub account is connected for the repository.
|
|
20
|
+
Marking the PR merged or closed posts the closing message and stops monitoring; reopening resumes it.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
ko:
|
|
2
|
+
collavre:
|
|
3
|
+
tool_descriptions:
|
|
4
|
+
github_pr_commits:
|
|
5
|
+
summary: GitHub 풀 리퀘스트의 커밋 메시지를 가져옵니다.
|
|
6
|
+
details: 크리에이티브에 GitHub 저장소가 연결되어 있어야 합니다.
|
|
7
|
+
github_pr_details:
|
|
8
|
+
summary: GitHub 풀 리퀘스트의 제목, 본문, 작성자, 변경 파일을 가져옵니다.
|
|
9
|
+
details: PR 본문은 2,000자에서 잘리므로 긴 설명은 뒷부분이 빠질 수 있습니다. 크리에이티브에 GitHub 저장소가 연결되어 있어야 합니다.
|
|
10
|
+
github_pr_diff:
|
|
11
|
+
summary: GitHub 풀 리퀘스트의 diff를 가져옵니다.
|
|
12
|
+
details: 텍스트 패치가 있는 변경 파일들의 패치를 합쳐 반환하며, 패치가 없는 파일(바이너리나 너무 큰 파일 등)은 제외됩니다. 결과는 max_length 글자(기본 10,000자)를 넘으면 잘리므로 큰 PR에서는 뒤쪽 파일이 빠질 수 있습니다. 크리에이티브에 GitHub 저장소가 연결되어 있어야 합니다.
|
|
13
|
+
pr_monitor:
|
|
14
|
+
summary: 토픽에서 GitHub 풀 리퀘스트를 모니터링합니다.
|
|
15
|
+
details: PR 코멘트, 리뷰, 병합 충돌, CI 검사 실패가 토픽 메시지로 게시됩니다. 확인된 저장소 연결에서는 5분마다 웹훅이 놓친 코멘트와 리뷰, 병합 충돌, CI 검사 실패를 확인합니다. 같은 PR로 다시 호출해도 중복되지 않습니다.
|
|
16
|
+
pr_state_set:
|
|
17
|
+
summary: GitHub 업데이트를 놓쳤을 때 모니터링 중인 풀 리퀘스트의 상태를 바로잡습니다.
|
|
18
|
+
details: |-
|
|
19
|
+
상태를 지정하지 않으면 GitHub에서 다시 동기화하며, 이 방식을 권장합니다. 저장소에 연결된 GitHub 계정이 없을 때만 상태를 직접 지정하세요.
|
|
20
|
+
머지 또는 닫힘으로 표시하면 종료 메시지를 게시하고 모니터링을 멈추며, 다시 열면 모니터링을 재개합니다.
|
data/db/seeds.rb
CHANGED
|
@@ -41,6 +41,15 @@ module CollavreGithub
|
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
initializer "collavre_github.register_tool_category", after: :load_config_initializers do
|
|
45
|
+
Rails.application.config.to_prepare do
|
|
46
|
+
if defined?(Collavre::McpToolCategories)
|
|
47
|
+
Collavre::McpToolCategories.register(:github, prefixes: %w[github_ pr_],
|
|
48
|
+
label_key: "collavre_github.tool_category")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
44
53
|
initializer "collavre_github.user_associations", after: :load_config_initializers do
|
|
45
54
|
Rails.application.config.to_prepare do
|
|
46
55
|
user_class = Collavre.user_class rescue nil
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: collavre_github
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Collavre
|
|
@@ -71,6 +71,7 @@ files:
|
|
|
71
71
|
- app/javascript/github_wizard_state.js
|
|
72
72
|
- app/jobs/collavre_github/initial_markdown_sync_job.rb
|
|
73
73
|
- app/jobs/collavre_github/markdown_sync_job.rb
|
|
74
|
+
- app/jobs/collavre_github/pr_blocker_sweep_job.rb
|
|
74
75
|
- app/jobs/collavre_github/webhook_delivery_prune_job.rb
|
|
75
76
|
- app/models/collavre_github/account.rb
|
|
76
77
|
- app/models/collavre_github/application_record.rb
|
|
@@ -78,10 +79,13 @@ files:
|
|
|
78
79
|
- app/models/collavre_github/repository_link.rb
|
|
79
80
|
- app/models/collavre_github/webhook_delivery.rb
|
|
80
81
|
- app/services/collavre_github/client.rb
|
|
82
|
+
- app/services/collavre_github/markdown_sync/content_creative.rb
|
|
81
83
|
- app/services/collavre_github/markdown_sync/content_processor.rb
|
|
82
84
|
- app/services/collavre_github/markdown_sync/incremental_sync_service.rb
|
|
83
85
|
- app/services/collavre_github/markdown_sync/initial_import_service.rb
|
|
86
|
+
- app/services/collavre_github/pr_blocker_monitor.rb
|
|
84
87
|
- app/services/collavre_github/pr_channel_state_updater.rb
|
|
88
|
+
- app/services/collavre_github/pr_discussion_event.rb
|
|
85
89
|
- app/services/collavre_github/pr_topic_link_parser.rb
|
|
86
90
|
- app/services/collavre_github/repository_identity_synchronizer.rb
|
|
87
91
|
- app/services/collavre_github/repository_provisioning_lock.rb
|
|
@@ -101,6 +105,8 @@ files:
|
|
|
101
105
|
- config/initializers/read_only_source.rb
|
|
102
106
|
- config/locales/en.yml
|
|
103
107
|
- config/locales/ko.yml
|
|
108
|
+
- config/locales/tool_descriptions.en.yml
|
|
109
|
+
- config/locales/tool_descriptions.ko.yml
|
|
104
110
|
- config/routes.rb
|
|
105
111
|
- db/migrate/20250925000000_create_github_integrations.rb
|
|
106
112
|
- db/migrate/20250927000000_add_webhook_secret_to_github_repository_links.rb
|
|
@@ -138,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
138
144
|
- !ruby/object:Gem::Version
|
|
139
145
|
version: '0'
|
|
140
146
|
requirements: []
|
|
141
|
-
rubygems_version: 3.6.
|
|
147
|
+
rubygems_version: 3.6.9
|
|
142
148
|
specification_version: 4
|
|
143
149
|
summary: GitHub integration for Collavre
|
|
144
150
|
test_files: []
|