From d8d0a63d6b340b97f950c6283f5eb2cebf12aa2c Mon Sep 17 00:00:00 2001 From: David Butenhof Date: Thu, 1 Oct 2026 07:31:11 -0400 Subject: [PATCH 1/5] Fix planning view REFRESH Signed-off-by: David Butenhof --- frontend/src/App.jsx | 63 ++----------------- frontend/src/App.test.jsx | 54 ++++++++-------- frontend/src/components/MilestoneCard.jsx | 27 ++------ .../src/components/MilestoneCard.test.jsx | 27 ++------ 4 files changed, 42 insertions(+), 129 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index d9b1306..85dd7aa 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -69,39 +69,12 @@ const App = () => { } }); - const [issueMilestoneRefresh, setIssueMilestoneRefresh] = useState({ - key: 0, - milestoneNumbers: [], - }); - // Milestone numbers whose issue/PR lists may be stale after local edits. - const [dirtyMilestoneNumbers, setDirtyMilestoneNumbers] = useState([]); + // A refresh cycle is global so it also catches changes made outside this UI. + const [issueMilestoneRefresh, setIssueMilestoneRefresh] = useState(0); const [hierarchyAction, setHierarchyAction] = useState(null); - const markMilestonesDirty = (numbers) => { - const normalized = numbers - .map((n) => (n == null ? 0 : n)) - .filter((n) => typeof n === 'number'); - if (normalized.length === 0) return; - setDirtyMilestoneNumbers((prev) => [...new Set([...prev, ...normalized])]); - }; - const handleHierarchyChanged = (action) => { setHierarchyAction({ ...action, key: Date.now() }); - if (action.type === 'relink') { - markMilestonesDirty([ - action.sourceMilestoneNumber, - action.targetMilestoneNumber, - action.fromMilestone, - action.toMilestone, - ]); - } else if (action.type === 'unlink') { - markMilestonesDirty([action.sourceMilestoneNumber]); - } else if (action.type === 'error') { - markMilestonesDirty([ - action.sourceMilestoneNumber, - action.targetMilestoneNumber, - ]); - } }; // MilestoneCards apply hierarchyAction in their effects (children run first). @@ -267,24 +240,8 @@ const App = () => { } }; - const handleIssueMilestoneMoved = ({ - fromMilestoneNumber, - toMilestoneNumber, - }) => { - markMilestonesDirty([fromMilestoneNumber, toMilestoneNumber]); - }; - - const handleIssueLabelsChanged = ({ milestoneNumber }) => { - markMilestonesDirty([milestoneNumber]); - }; - - const handleRefreshDirtyMilestones = () => { - if (dirtyMilestoneNumbers.length === 0) return; - setIssueMilestoneRefresh((s) => ({ - key: s.key + 1, - milestoneNumbers: [...dirtyMilestoneNumbers], - })); - setDirtyMilestoneNumbers([]); + const handleRefresh = () => { + setIssueMilestoneRefresh((key) => key + 1); }; const handleLabelChange = () => { @@ -332,8 +289,6 @@ const App = () => { sortOrder={sortOrder} issueMilestoneRefresh={issueMilestoneRefresh} hierarchyAction={hierarchyAction} - onIssueMilestoneMoved={handleIssueMilestoneMoved} - onIssueLabelsChanged={handleIssueLabelsChanged} onMilestoneUpdated={handleMilestoneUpdated} /> ))} @@ -386,14 +341,8 @@ const App = () => {
- + + )} + {milestone.number !== 0 && milestoneFilter === 'closed' && ( + + + + )} , + , + ]} + > + {closeCounts.open_issues === 0 && + closeCounts.open_pull_requests === 0 ? ( +

There are no open issues or PRs against this milestone.

+ ) : ( +

+ There are {closeCounts.open_issues} open issue + {closeCounts.open_issues === 1 ? '' : 's'} and{' '} + {closeCounts.open_pull_requests} open PR + {closeCounts.open_pull_requests === 1 ? '' : 's'} against this + milestone. +

+ )} + + Closing this milestone will not close its issues or pull requests. + + + )} ); }; diff --git a/frontend/src/components/ManageMilestones.test.jsx b/frontend/src/components/ManageMilestones.test.jsx new file mode 100644 index 0000000..402f074 --- /dev/null +++ b/frontend/src/components/ManageMilestones.test.jsx @@ -0,0 +1,97 @@ +// Generated-by: openai-code-assist +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { render, screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import ManageMilestones from './ManageMilestones'; +import * as api from '../services/api'; +import { clearMilestonesCache } from '../utils/milestonesCache'; + +vi.mock('../services/api'); + +describe('ManageMilestones state actions', () => { + const openMilestone = { + number: 6, + title: 'v0.6.0', + description: 'Version 0.6.0', + due_on: null, + state: 'open', + }; + const closedMilestone = { ...openMilestone, state: 'closed' }; + let openResults; + let closedResults; + + beforeEach(() => { + vi.clearAllMocks(); + clearMilestonesCache(); + openResults = [openMilestone]; + closedResults = [closedMilestone]; + api.fetchMilestones.mockImplementation((state = 'open') => + Promise.resolve(state === 'closed' ? closedResults : openResults) + ); + api.fetchMilestoneOpenCounts.mockResolvedValue({ + open_issues: 2, + open_pull_requests: 1, + }); + api.updateMilestoneState.mockResolvedValue({ + ...closedMilestone, + }); + }); + + it('confirms close with open issue and pull-request counts', async () => { + const user = userEvent.setup(); + render( + + ); + + await waitFor(() => expect(screen.getByText('v0.6.0')).toBeInTheDocument()); + await user.click( + screen.getByRole('button', { name: 'Close v0.6.0 milestone' }) + ); + + await waitFor(() => { + expect(api.fetchMilestoneOpenCounts).toHaveBeenCalledWith(6); + expect( + screen.getByText( + 'There are 2 open issues and 1 open PR against this milestone.' + ) + ).toBeInTheDocument(); + }); + expect( + screen.getByText(/will not close its issues or pull requests/i) + ).toBeInTheDocument(); + openResults = []; + await user.click(screen.getByRole('button', { name: 'Close milestone' })); + + await waitFor(() => { + expect(api.updateMilestoneState).toHaveBeenCalledWith(6, 'closed'); + expect(screen.queryByText('v0.6.0')).not.toBeInTheDocument(); + }); + }); + + it('loads closed milestones and can reopen one', async () => { + const user = userEvent.setup(); + render( + + ); + + await waitFor(() => expect(screen.getByText('v0.6.0')).toBeInTheDocument()); + await user.selectOptions( + screen.getByLabelText('Milestone filter'), + 'closed' + ); + + await waitFor(() => { + expect(api.fetchMilestones).toHaveBeenCalledWith('closed'); + expect(screen.getByText('Closed')).toBeInTheDocument(); + }); + closedResults = []; + await user.click( + screen.getByRole('button', { name: 'Reopen v0.6.0 milestone' }) + ); + + await waitFor(() => { + expect(api.updateMilestoneState).toHaveBeenCalledWith(6, 'open'); + expect(screen.queryByText('v0.6.0')).not.toBeInTheDocument(); + }); + }); +}); diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js index a9a6e3e..475ded1 100644 --- a/frontend/src/services/api.js +++ b/frontend/src/services/api.js @@ -27,14 +27,28 @@ const raiseForResponse = async (response, fallback) => { throw new Error(`${fallback}: ${detail}`); }; -export const fetchMilestones = async () => { - const response = await fetch(`${API_BASE}/milestones`); +export const fetchMilestones = async (state = 'open') => { + const query = state === 'open' ? '' : `?state=${encodeURIComponent(state)}`; + const response = await fetch(`${API_BASE}/milestones${query}`); if (!response.ok) { throw new Error(`Failed to fetch milestones: ${response.statusText}`); } return response.json(); }; +// Assisted-by: openai-code-assist +export const fetchMilestoneOpenCounts = async (milestoneNumber) => { + const response = await fetch( + `${API_BASE}/milestones/${milestoneNumber}/open-counts` + ); + if (!response.ok) { + throw new Error( + `Failed to fetch milestone open counts: ${response.statusText}` + ); + } + return response.json(); +}; + export const fetchIssues = async (milestoneNumber, sortOrder = []) => { let url = `${API_BASE}/issues/${milestoneNumber}`; if (sortOrder && sortOrder.length > 0) { @@ -228,6 +242,24 @@ export const updateMilestone = async (milestoneNumber, milestoneData) => { return response.json(); }; +// Assisted-by: openai-code-assist +export const updateMilestoneState = async (milestoneNumber, state) => { + const response = await fetch( + `${API_BASE}/milestones/${milestoneNumber}/state`, + { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ state }), + } + ); + if (!response.ok) { + throw new Error(`Failed to update milestone state: ${response.statusText}`); + } + return response.json(); +}; + export const deleteMilestone = async (milestoneNumber) => { const response = await fetch(`${API_BASE}/milestones/${milestoneNumber}`, { method: 'DELETE', diff --git a/frontend/src/services/api.test.js b/frontend/src/services/api.test.js index b6b1578..f581bf6 100644 --- a/frontend/src/services/api.test.js +++ b/frontend/src/services/api.test.js @@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { fetchMilestones, + fetchMilestoneOpenCounts, fetchIssues, fetchComments, fetchProject, @@ -23,6 +24,7 @@ import { updateComment, updateIssueBody, updateIssueTitle, + updateMilestoneState, } from './api'; describe('api', () => { @@ -55,6 +57,53 @@ describe('api', () => { 'Failed to fetch milestones' ); }); + + it('fetches closed milestones with a state filter', async () => { + global.fetch.mockResolvedValue({ + ok: true, + json: async () => [{ number: 1, title: 'Completed' }], + }); + + await fetchMilestones('closed'); + + expect(global.fetch).toHaveBeenCalledWith( + '/api/v1/milestones?state=closed' + ); + }); + }); + + describe('milestone state APIs', () => { + it('fetches open issue and pull-request counts', async () => { + const counts = { open_issues: 2, open_pull_requests: 1 }; + global.fetch.mockResolvedValue({ + ok: true, + json: async () => counts, + }); + + const result = await fetchMilestoneOpenCounts(6); + + expect(result).toEqual(counts); + expect(global.fetch).toHaveBeenCalledWith( + '/api/v1/milestones/6/open-counts' + ); + }); + + it('updates milestone state', async () => { + const milestone = { number: 6, state: 'closed' }; + global.fetch.mockResolvedValue({ + ok: true, + json: async () => milestone, + }); + + const result = await updateMilestoneState(6, 'closed'); + + expect(result).toEqual(milestone); + expect(global.fetch).toHaveBeenCalledWith('/api/v1/milestones/6/state', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ state: 'closed' }), + }); + }); }); describe('fetchIssues', () => { From 5524b1fca14384125ac26ad3a2911e194e5b7af8 Mon Sep 17 00:00:00 2001 From: David Butenhof Date: Thu, 1 Oct 2026 10:22:26 -0400 Subject: [PATCH 5/5] Allow editing existing labels Signed-off-by: David Butenhof --- backend/src/github_pm/api.py | 33 +++++ backend/tests/test_api.py | 36 +++++ frontend/src/components/ManageLabels.jsx | 123 +++++++++++++++--- frontend/src/components/ManageLabels.test.jsx | 76 +++++++++++ frontend/src/components/ManageMilestones.jsx | 5 + frontend/src/services/api.js | 15 +++ frontend/src/services/api.test.js | 28 ++++ 7 files changed, 298 insertions(+), 18 deletions(-) create mode 100644 frontend/src/components/ManageLabels.test.jsx diff --git a/backend/src/github_pm/api.py b/backend/src/github_pm/api.py index e6fa28e..2a89779 100644 --- a/backend/src/github_pm/api.py +++ b/backend/src/github_pm/api.py @@ -1191,6 +1191,17 @@ class CreateLabel(BaseModel): description: str | None = Field(default=None, title="Label Description") +class UpdateLabel(BaseModel): + """Body for updating a repository label. + + Assisted-by: openai-code-assist + """ + + name: str = Field(title="Label Name") + color: str | None = Field(default=None, title="Label Color") + description: str | None = Field(default=None, title="Label Description") + + @api_router.post("/labels") async def create_label( gitctx: Annotated[Connector, Depends(connection)], @@ -1207,6 +1218,28 @@ async def create_label( return response +@api_router.patch("/labels/{label_name}") +async def update_label( + gitctx: Annotated[Connector, Depends(connection)], + label_name: str, + label: Annotated[UpdateLabel, Body(title="Label")], +): + """Update a repository label, including its name, color, or description. + + Assisted-by: openai-code-assist + """ + + response = gitctx.patch( + f"/repos/{context.github_repo}/labels/{label_name}", + data={ + "new_name": label.name, + "color": label.color, + "description": label.description, + }, + ) + return response + + @api_router.delete("/labels/{label_name}") async def delete_label( gitctx: Annotated[Connector, Depends(connection)], label_name: str diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index c837541..1b9ce57 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -52,10 +52,12 @@ update_comment, update_issue_body, update_issue_title, + update_label, update_milestone_state, UpdateComment, UpdateIssueBody, UpdateIssueTitle, + UpdateLabel, UpdateMilestoneState, ) from github_pm.app import app @@ -1607,6 +1609,40 @@ async def test_delete_label_not_found(self): await delete_label(mock_gitctx, label_name="nonexistent") +class TestUpdateLabel: + """Test the update_label endpoint.""" + + @pytest.mark.asyncio + async def test_update_label_success(self): + """Test successfully updating a label, including its name.""" + mock_label_response = { + "id": 1, + "name": "updated-label", + "color": "green", + "description": "Updated label", + } + label_data = UpdateLabel( + name="updated-label", color="green", description="Updated label" + ) + mock_gitctx = Mock(spec=Connector) + mock_gitctx.patch = Mock(return_value=mock_label_response) + + with patch("github_pm.api.context") as mock_context: + mock_context.github_repo = "test/repo" + + result = await update_label(mock_gitctx, "old-label", label_data) + + assert result == mock_label_response + mock_gitctx.patch.assert_called_once_with( + "/repos/test/repo/labels/old-label", + data={ + "new_name": "updated-label", + "color": "green", + "description": "Updated label", + }, + ) + + class TestAddLabelToIssue: """Test the add_label_to_issue endpoint.""" diff --git a/frontend/src/components/ManageLabels.jsx b/frontend/src/components/ManageLabels.jsx index 68eed72..81abea7 100644 --- a/frontend/src/components/ManageLabels.jsx +++ b/frontend/src/components/ManageLabels.jsx @@ -1,4 +1,5 @@ // Generated-by: Cursor +// Assisted-by: openai-code-assist import React, { useState, useEffect } from 'react'; import { Modal, @@ -11,15 +12,22 @@ import { Form, FormGroup, } from '@patternfly/react-core'; -import { fetchLabels, createLabel, deleteLabel } from '../services/api'; -import labelsCache, { clearLabelsCache } from '../utils/labelsCache'; +import { + fetchLabels, + createLabel, + updateLabel, + deleteLabel, +} from '../services/api'; +import labelsCache from '../utils/labelsCache'; import LabelColorInput from './LabelColorInput'; +import { PencilAltIcon } from '@patternfly/react-icons'; const ManageLabels = ({ isOpen, onClose, onLabelChange }) => { const [labels, setLabels] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false); + const [editingLabelName, setEditingLabelName] = useState(null); const [newLabel, setNewLabel] = useState({ name: '', color: '', @@ -129,7 +137,26 @@ const ManageLabels = ({ isOpen, onClose, onLabelChange }) => { } }; - const handleCreateLabel = async () => { + const handleOpenCreateDialog = () => { + setEditingLabelName(null); + setNewLabel({ name: '', color: '', description: '' }); + setCreateError(null); + setIsCreateDialogOpen(true); + }; + + const handleEditLabel = (label) => { + setEditingLabelName(label.name); + setNewLabel({ + name: label.name || '', + color: label.color || '', + description: label.description || '', + }); + setCreateError(null); + setIsCreateDialogOpen(true); + }; + + // Assisted-by: openai-code-assist + const handleSaveLabel = async () => { const name = String(newLabel.name || '').trim(); if (!name) { setCreateError('Name is required'); @@ -151,20 +178,42 @@ const ManageLabels = ({ isOpen, onClose, onLabelChange }) => { } const description = String(newLabel.description || '').trim(); - if (description) { + if (editingLabelName) { + // Sending an empty description lets an edit clear the current value. + labelData.description = description; + } else if (description) { labelData.description = description; } - const newLabelData = await createLabel(labelData); - // Optimistically add to UI - setLabels( - [...labels, newLabelData].sort((a, b) => a.name.localeCompare(b.name)) - ); - labelsCache.data = [...labelsCache.data, newLabelData].sort((a, b) => - a.name.localeCompare(b.name) - ); + const savedLabel = editingLabelName + ? await updateLabel(editingLabelName, labelData) + : await createLabel(labelData); + const updatedLabel = { ...newLabel, ...savedLabel, name }; + + if (editingLabelName) { + setLabels( + labels + .map((label) => + label.name === editingLabelName ? updatedLabel : label + ) + .sort((a, b) => a.name.localeCompare(b.name)) + ); + labelsCache.data = labelsCache.data + .map((label) => + label.name === editingLabelName ? updatedLabel : label + ) + .sort((a, b) => a.name.localeCompare(b.name)); + } else { + setLabels( + [...labels, updatedLabel].sort((a, b) => a.name.localeCompare(b.name)) + ); + labelsCache.data = [...labelsCache.data, updatedLabel].sort((a, b) => + a.name.localeCompare(b.name) + ); + } setIsCreateDialogOpen(false); + setEditingLabelName(null); setNewLabel({ name: '', color: '', description: '' }); setCreateError(null); @@ -182,6 +231,7 @@ const ManageLabels = ({ isOpen, onClose, onLabelChange }) => { const handleCancelCreate = () => { setIsCreateDialogOpen(false); + setEditingLabelName(null); setNewLabel({ name: '', color: '', description: '' }); setCreateError(null); }; @@ -215,7 +265,7 @@ const ManageLabels = ({ isOpen, onClose, onLabelChange }) => {
, , ]} > + {actionError && ( + + {actionError} + + )} {closeCounts.open_issues === 0 && closeCounts.open_pull_requests === 0 ? (

There are no open issues or PRs against this milestone.

diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js index 475ded1..08b9308 100644 --- a/frontend/src/services/api.js +++ b/frontend/src/services/api.js @@ -284,6 +284,21 @@ export const createLabel = async (labelData) => { return response.json(); }; +// Assisted-by: openai-code-assist +export const updateLabel = async (labelName, labelData) => { + const response = await fetch(`${API_BASE}/labels/${labelName}`, { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(labelData), + }); + if (!response.ok) { + throw new Error(`Failed to update label: ${response.statusText}`); + } + return response.json(); +}; + export const deleteLabel = async (labelName) => { const response = await fetch(`${API_BASE}/labels/${labelName}`, { method: 'DELETE', diff --git a/frontend/src/services/api.test.js b/frontend/src/services/api.test.js index f581bf6..1e55200 100644 --- a/frontend/src/services/api.test.js +++ b/frontend/src/services/api.test.js @@ -24,6 +24,7 @@ import { updateComment, updateIssueBody, updateIssueTitle, + updateLabel, updateMilestoneState, } from './api'; @@ -106,6 +107,33 @@ describe('api', () => { }); }); + describe('label APIs', () => { + it('updates a label', async () => { + const updatedLabel = { id: 1, name: 'defect', color: 'b60205' }; + global.fetch.mockResolvedValue({ + ok: true, + json: async () => updatedLabel, + }); + + const result = await updateLabel('bug', { + name: 'defect', + color: 'b60205', + description: 'Something is broken', + }); + + expect(result).toEqual(updatedLabel); + expect(global.fetch).toHaveBeenCalledWith('/api/v1/labels/bug', { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + name: 'defect', + color: 'b60205', + description: 'Something is broken', + }), + }); + }); + }); + describe('fetchIssues', () => { it('fetches issues successfully', async () => { const mockPayload = {