| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package buildbucket | 5 package buildbucket |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "net/http" | 9 "net/http" |
| 10 "strings" | 10 "strings" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 client, err := buildbucket.New(&http.Client{Transport: t}) | 64 client, err := buildbucket.New(&http.Client{Transport: t}) |
| 65 if err != nil { | 65 if err != nil { |
| 66 return nil, err | 66 return nil, err |
| 67 } | 67 } |
| 68 client.BasePath = fmt.Sprintf("https://%s/api/buildbucket/v1/", server) | 68 client.BasePath = fmt.Sprintf("https://%s/api/buildbucket/v1/", server) |
| 69 return client, nil | 69 return client, nil |
| 70 } | 70 } |
| 71 | 71 |
| 72 // parseStatus converts a buildbucket build status to resp.Status. | 72 // parseStatus converts a buildbucket build status to resp.Status. |
| 73 func parseStatus(build *buildbucket.ApiBuildMessage) (resp.Status, error) { | 73 func parseStatus(build *buildbucket.ApiCommonBuildMessage) (resp.Status, error)
{ |
| 74 switch build.Status { | 74 switch build.Status { |
| 75 case StatusScheduled: | 75 case StatusScheduled: |
| 76 return resp.NotRun, nil | 76 return resp.NotRun, nil |
| 77 | 77 |
| 78 case StatusStarted: | 78 case StatusStarted: |
| 79 return resp.Running, nil | 79 return resp.Running, nil |
| 80 | 80 |
| 81 case StatusCompleted: | 81 case StatusCompleted: |
| 82 switch build.Result { | 82 switch build.Result { |
| 83 case "SUCCESS": | 83 case "SUCCESS": |
| (...skipping 14 matching lines...) Expand all Loading... |
| 98 return 0, fmt.Errorf("unexpected buildbucket build resul
t %q", build.Result) | 98 return 0, fmt.Errorf("unexpected buildbucket build resul
t %q", build.Result) |
| 99 } | 99 } |
| 100 | 100 |
| 101 default: | 101 default: |
| 102 return 0, fmt.Errorf("unexpected buildbucket build status %q", b
uild.Status) | 102 return 0, fmt.Errorf("unexpected buildbucket build status %q", b
uild.Status) |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 // getChangeList tries to extract CL information from a buildbucket build. | 106 // getChangeList tries to extract CL information from a buildbucket build. |
| 107 func getChangeList( | 107 func getChangeList( |
| 108 » build *buildbucket.ApiBuildMessage, params *buildParameters, | 108 » build *buildbucket.ApiCommonBuildMessage, params *buildParameters, |
| 109 resultDetails *resultDetails) (result *resp.Commit) { | 109 resultDetails *resultDetails) (result *resp.Commit) { |
| 110 | 110 |
| 111 prop := ¶ms.Properties | 111 prop := ¶ms.Properties |
| 112 switch prop.PatchStorage { | 112 switch prop.PatchStorage { |
| 113 case "rietveld": | 113 case "rietveld": |
| 114 if prop.RietveldURL != "" && prop.Issue != 0 { | 114 if prop.RietveldURL != "" && prop.Issue != 0 { |
| 115 result = &resp.Commit{ | 115 result = &resp.Commit{ |
| 116 RequestRevision: &resp.Link{Label: prop.Revision
}, | 116 RequestRevision: &resp.Link{Label: prop.Revision
}, |
| 117 Changelist: &resp.Link{ | 117 Changelist: &resp.Link{ |
| 118 Label: fmt.Sprintf("Rietveld CL %d", pro
p.Issue), | 118 Label: fmt.Sprintf("Rietveld CL %d", pro
p.Issue), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 if result != nil && len(params.Changes) != 0 { | 145 if result != nil && len(params.Changes) != 0 { |
| 146 // tryjobs have one change and it is the CL author | 146 // tryjobs have one change and it is the CL author |
| 147 result.AuthorEmail = params.Changes[0].Author.Email | 147 result.AuthorEmail = params.Changes[0].Author.Email |
| 148 } | 148 } |
| 149 | 149 |
| 150 return | 150 return |
| 151 } | 151 } |
| OLD | NEW |