7
7
"os"
8
8
"path"
9
9
"path/filepath"
10
+ "slices"
11
+ "strings"
10
12
11
13
"github.com/ldez/prm/v3/local"
12
14
"github.com/ldez/prm/v3/types"
@@ -22,7 +24,7 @@ type Configuration struct {
22
24
23
25
var getPathFunc = GetPath
24
26
25
- // RemovePullRequest remove a pull request.
27
+ // RemovePullRequest removes a pull request.
26
28
func (c * Configuration ) RemovePullRequest (pull * types.PullRequest ) int {
27
29
prs := c .PullRequests [pull .Owner ]
28
30
@@ -54,7 +56,7 @@ func (c *Configuration) findPullRequestIndex(pull *types.PullRequest) int {
54
56
return - 1
55
57
}
56
58
57
- // FindPullRequests find a pull request by number.
59
+ // FindPullRequests finds a pull request by number.
58
60
func (c * Configuration ) FindPullRequests (number int ) (* types.PullRequest , error ) {
59
61
for _ , prs := range c .PullRequests {
60
62
for _ , pr := range prs {
@@ -93,7 +95,7 @@ func Find(configurations []Configuration, directory string) (*Configuration, err
93
95
return nil , fmt .Errorf ("no existing configuration for: %s" , directory )
94
96
}
95
97
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.
97
99
func ReadFile () ([]Configuration , error ) {
98
100
var configs []Configuration
99
101
@@ -146,13 +148,17 @@ func ReadFile() ([]Configuration, error) {
146
148
return configs , nil
147
149
}
148
150
149
- // Save save the configuration into a file.
151
+ // Save saves the configuration into a file.
150
152
func Save (configs []Configuration ) error {
151
153
filePath , err := getPathFunc ()
152
154
if err != nil {
153
155
return err
154
156
}
155
157
158
+ slices .SortFunc (configs , func (a , b Configuration ) int {
159
+ return strings .Compare (a .Directory , b .Directory )
160
+ })
161
+
156
162
confJSON , err := json .MarshalIndent (configs , "" , " " )
157
163
if err != nil {
158
164
return err
0 commit comments