-
Notifications
You must be signed in to change notification settings - Fork 332
/
bisect_start.go
52 lines (47 loc) · 1.4 KB
/
bisect_start.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"net/http"
"time"
"github.com/spf13/cobra"
)
// bisectStartCmd represents the start command
var bisectStartCmd = &cobra.Command{
Use: "start <bad ref URI> <good ref URI>",
Short: "Start a bisect session",
Args: cobra.ExactArgs(bisectStartCmdArgs),
Run: func(cmd *cobra.Command, args []string) {
badURI := MustParseRefURI("bad ref URI", args[0])
goodURI := MustParseRefURI("good ref URI", args[1])
if goodURI.Repository != badURI.Repository {
Die("Two references doesn't use the same repository", 1)
}
repository := goodURI.Repository
// resolve repository and references
client := getClient()
ctx := cmd.Context()
// check repository exists
repoResponse, err := client.GetRepositoryWithResponse(ctx, repository)
DieOnErrorOrUnexpectedStatusCode(repoResponse, err, http.StatusOK)
if repoResponse.JSON200 == nil {
Die("Bad response from server", 1)
}
state := &Bisect{
Created: time.Now().UTC(),
Repository: repoResponse.JSON200.Id,
BadCommit: resolveCommitOrDie(ctx, client, badURI.Repository, badURI.Ref),
GoodCommit: resolveCommitOrDie(ctx, client, goodURI.Repository, goodURI.Ref),
}
// resolve commits
if err := state.Update(ctx, client); err != nil {
DieErr(err)
}
if err := state.Save(); err != nil {
DieErr(err)
}
state.PrintStatus()
},
}
//nolint:gochecknoinits
func init() {
bisectCmd.AddCommand(bisectStartCmd)
}