Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,14 @@ type CachedPullRequest struct {
HeadRepositoryOwner string `yaml:"headRepositoryOwner"`
}

// MarshalYAML trims fields that break YAML round-trips when cached to state.yml.
func (pr CachedPullRequest) MarshalYAML() (interface{}, error) {
type cachedPullRequest CachedPullRequest
sanitized := cachedPullRequest(pr)
sanitized.Title = strings.TrimSpace(pr.Title)
return sanitized, nil
}

func getDefaultAppState() *AppState {
return &AppState{
GithubPullRequests: make(map[string][]CachedPullRequest),
Expand Down
32 changes: 32 additions & 0 deletions pkg/config/cached_pull_request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package config

import (
"testing"

"gopkg.in/yaml.v3"
)

func TestCachedPullRequestTitleYAMLRoundTrip(t *testing.T) {
t.Parallel()

state := AppState{
GithubPullRequests: map[string][]CachedPullRequest{
"/tmp/repo": {{
HeadRefName: "example-branch",
Number: 9,
Title: "\nExample pull request title",
State: "MERGED",
}},
},
}

data, err := yaml.Marshal(&state)
if err != nil {
t.Fatal(err)
}

var decoded AppState
if err := yaml.Unmarshal(data, &decoded); err != nil {
t.Fatalf("yaml unmarshal failed: %v\n%s", err, data)
}
}
2 changes: 1 addition & 1 deletion pkg/gui/controllers/helpers/refresh_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ func (self *RefreshHelper) savePullRequestsToCache(prs []*models.GithubPullReque
return config.CachedPullRequest{
HeadRefName: pr.HeadRefName,
Number: pr.Number,
Title: pr.Title,
Title: strings.TrimSpace(pr.Title),
State: pr.State,
Url: pr.Url,
HeadRepositoryOwner: pr.HeadRepositoryOwner.Login,
Expand Down