* Reopen the notes issue when an entry is unpublished
(collectionName: string, slug: string)
| 1828 | * Reopen the notes issue when an entry is unpublished |
| 1829 | */ |
| 1830 | async reopenIssueOnUnpublish(collectionName: string, slug: string): Promise<void> { |
| 1831 | try { |
| 1832 | const searchQuery = `repo:${this.repo} label:${API.NOTES_LABEL} "${collectionName}/${slug}" in:body`; |
| 1833 | const searchResponse = await this.request('/search/issues', { |
| 1834 | params: { q: searchQuery }, |
| 1835 | }); |
| 1836 | |
| 1837 | if (searchResponse.items && searchResponse.items.length > 0) { |
| 1838 | const issue = searchResponse.items[0]; |
| 1839 | // Remove 'entry-published' or 'entry-deleted' labels and reopen |
| 1840 | const updatedLabels = (issue.labels || []) |
| 1841 | .map((l: { name: string }) => l.name) |
| 1842 | .filter((name: string) => name !== 'entry-published' && name !== 'entry-deleted'); |
| 1843 | |
| 1844 | await this.request(`${this.repoURL}/issues/${issue.number}`, { |
| 1845 | method: 'PATCH', |
| 1846 | body: JSON.stringify({ |
| 1847 | state: 'open', |
| 1848 | labels: updatedLabels, |
| 1849 | }), |
| 1850 | }); |
| 1851 | } |
| 1852 | } catch (error) { |
| 1853 | console.warn('Failed to reopen notes issue on unpublish:', error); |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | /** |
| 1858 | * Get all notes for an entry |
no test coverage detected