Skip to content

Commit 839e266

Browse files
committed
feat: sort configuration
1 parent 2de8a3a commit 839e266

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

config/config.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"os"
88
"path"
99
"path/filepath"
10+
"slices"
11+
"strings"
1012

1113
"github.com/ldez/prm/v3/local"
1214
"github.com/ldez/prm/v3/types"
@@ -22,7 +24,7 @@ type Configuration struct {
2224

2325
var getPathFunc = GetPath
2426

25-
// RemovePullRequest remove a pull request.
27+
// RemovePullRequest removes a pull request.
2628
func (c *Configuration) RemovePullRequest(pull *types.PullRequest) int {
2729
prs := c.PullRequests[pull.Owner]
2830

@@ -54,7 +56,7 @@ func (c *Configuration) findPullRequestIndex(pull *types.PullRequest) int {
5456
return -1
5557
}
5658

57-
// FindPullRequests find a pull request by number.
59+
// FindPullRequests finds a pull request by number.
5860
func (c *Configuration) FindPullRequests(number int) (*types.PullRequest, error) {
5961
for _, prs := range c.PullRequests {
6062
for _, pr := range prs {
@@ -93,7 +95,7 @@ func Find(configurations []Configuration, directory string) (*Configuration, err
9395
return nil, fmt.Errorf("no existing configuration for: %s", directory)
9496
}
9597

96-
// ReadFile read or create the configuration file and load the configuration into an array.
98+
// ReadFile reads or creates the configuration file and load the configuration into an array.
9799
func ReadFile() ([]Configuration, error) {
98100
var configs []Configuration
99101

@@ -146,13 +148,17 @@ func ReadFile() ([]Configuration, error) {
146148
return configs, nil
147149
}
148150

149-
// Save save the configuration into a file.
151+
// Save saves the configuration into a file.
150152
func Save(configs []Configuration) error {
151153
filePath, err := getPathFunc()
152154
if err != nil {
153155
return err
154156
}
155157

158+
slices.SortFunc(configs, func(a, b Configuration) int {
159+
return strings.Compare(a.Directory, b.Directory)
160+
})
161+
156162
confJSON, err := json.MarshalIndent(configs, "", " ")
157163
if err != nil {
158164
return err

0 commit comments

Comments
 (0)