(root *rootCmd)
| 83 | } |
| 84 | |
| 85 | func (c *updateOpenAPICmd) Run(root *rootCmd) error { |
| 86 | ctx := context.Background() |
| 87 | if c.ValidateGithub && c.Ref != "main" { |
| 88 | return errors.New("--validate and --ref are mutually exclusive") |
| 89 | } |
| 90 | filename, opsFile, err := root.opsFile() |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | origOps := make([]*operation, len(opsFile.OpenapiOps)) |
| 95 | copy(origOps, opsFile.OpenapiOps) |
| 96 | for i := range origOps { |
| 97 | origOps[i] = origOps[i].clone() |
| 98 | } |
| 99 | client, err := githubClient(root.GithubURL, root.UploadURL) |
| 100 | if err != nil { |
| 101 | return err |
| 102 | } |
| 103 | ref := c.Ref |
| 104 | if c.ValidateGithub { |
| 105 | ref = opsFile.GitCommit |
| 106 | if ref == "" { |
| 107 | return errors.New("openapi_operations.yaml does not have an openapi_commit field") |
| 108 | } |
| 109 | } |
| 110 | err = opsFile.updateFromGithub(ctx, client, ref) |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | if !c.ValidateGithub { |
| 115 | return opsFile.saveFile(filename) |
| 116 | } |
| 117 | if !operationsEqual(origOps, opsFile.OpenapiOps) { |
| 118 | return errors.New("openapi_operations.yaml does not match the OpenAPI descriptions in github.com/github/rest-api-description") |
| 119 | } |
| 120 | return nil |
| 121 | } |
| 122 | |
| 123 | type formatCmd struct{} |
| 124 |
nothing calls this directly
no test coverage detected