Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix adding/removing projects using flags for edit commands #6955

Merged
merged 1 commit into from Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/cmd/issue/edit/edit_test.go
Expand Up @@ -284,8 +284,8 @@ func Test_editRun(t *testing.T) {
},
Projects: prShared.EditableProjects{
EditableSlice: prShared.EditableSlice{
Add: []string{"Cleanup", "RoadmapV2"},
Remove: []string{"Roadmap", "CleanupV2"},
Add: []string{"Cleanup", "CleanupV2"},
Remove: []string{"Roadmap", "RoadmapV2"},
Edited: true,
},
},
Expand Down Expand Up @@ -332,7 +332,7 @@ func Test_editRun(t *testing.T) {
eo.Labels.Value = []string{"feature", "TODO", "bug"}
eo.Labels.Add = []string{"feature", "TODO", "bug"}
eo.Labels.Remove = []string{"docs"}
eo.Projects.Value = []string{"Cleanup", "RoadmapV2"}
eo.Projects.Value = []string{"Cleanup", "CleanupV2"}
eo.Milestone.Value = "GA"
return nil
},
Expand Down Expand Up @@ -404,7 +404,7 @@ func mockIssueProjectItemsGet(_ *testing.T, reg *httpmock.Registry) {
{ "data": { "repository": { "issue": {
"projectItems": {
"nodes": [
{ "id": "ITEMID", "project": { "title": "CleanupV2" } }
{ "id": "ITEMID", "project": { "title": "RoadmapV2" } }
]
}
} } } }`),
Expand Down
12 changes: 5 additions & 7 deletions pkg/cmd/pr/edit/edit_test.go
Expand Up @@ -347,8 +347,8 @@ func Test_editRun(t *testing.T) {
},
Projects: shared.EditableProjects{
EditableSlice: shared.EditableSlice{
Add: []string{"Cleanup", "RoadmapV2"},
Remove: []string{"CleanupV2", "Roadmap"},
Add: []string{"Cleanup", "CleanupV2"},
Remove: []string{"Roadmap", "RoadmapV2"},
Edited: true,
},
},
Expand Down Expand Up @@ -401,8 +401,8 @@ func Test_editRun(t *testing.T) {
},
Projects: shared.EditableProjects{
EditableSlice: shared.EditableSlice{
Add: []string{"Cleanup", "RoadmapV2"},
Remove: []string{"CleanupV2", "Roadmap"},
Add: []string{"Cleanup", "CleanupV2"},
Remove: []string{"Roadmap", "RoadmapV2"},
Edited: true,
},
},
Expand Down Expand Up @@ -655,9 +655,7 @@ func (s testSurveyor) EditFields(e *shared.Editable, _ string) error {
e.Labels.Value = []string{"feature", "TODO", "bug"}
e.Labels.Add = []string{"feature", "TODO", "bug"}
e.Labels.Remove = []string{"docs"}
e.Projects.Value = []string{"Cleanup", "RoadmapV2"}
e.Projects.Add = []string{"Cleanup", "RoadmapV2"}
e.Projects.Remove = []string{"CleanupV2", "Roadmap"}
e.Projects.Value = []string{"Cleanup", "CleanupV2"}
e.Milestone.Value = "GA"
return nil
}
Expand Down
21 changes: 12 additions & 9 deletions pkg/cmd/pr/shared/editable.go
Expand Up @@ -153,17 +153,20 @@ func (e Editable) ProjectV2Ids() (*[]string, *[]string, error) {

// titles of projects to add
addTitles := set.NewStringSet()
addTitles.AddValues(e.Projects.Value)
addTitles.AddValues(e.Projects.Add)
addTitles.RemoveValues(e.Projects.Default)
addTitles.RemoveValues(e.Projects.Remove)

// titles of projects to remove
removeTitles := set.NewStringSet()
removeTitles.AddValues(e.Projects.Default)
removeTitles.AddValues(e.Projects.Remove)
removeTitles.RemoveValues(e.Projects.Value)
removeTitles.RemoveValues(e.Projects.Add)

if len(e.Projects.Add) != 0 || len(e.Projects.Remove) != 0 {
// Projects were selected using flags.
addTitles.AddValues(e.Projects.Add)
removeTitles.AddValues(e.Projects.Remove)
} else {
// Projects were selected interactively.
addTitles.AddValues(e.Projects.Value)
addTitles.RemoveValues(e.Projects.Default)
removeTitles.AddValues(e.Projects.Default)
removeTitles.RemoveValues(e.Projects.Value)
}

var addIds []string
var removeIds []string
Expand Down