Skip to content

Commit

Permalink
Fix adding/removing projects using flags for edit commands (#6955)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcoe committed Feb 5, 2023
1 parent c024e85 commit 138da0f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
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

0 comments on commit 138da0f

Please sign in to comment.