| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 default: | 97 default: |
| 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(build *buildbucket.ApiBuildMessage, params *buildParameters,
resultDetails *resultDetails) *resp.Commit { | 107 func getChangeList( |
| 108 » var result *resp.Commit | 108 » build *buildbucket.ApiBuildMessage, params *buildParameters, |
| 109 » resultDetails *resultDetails) (result *resp.Commit) { |
| 109 | 110 |
| 110 prop := ¶ms.Properties | 111 prop := ¶ms.Properties |
| 111 switch prop.PatchStorage { | 112 switch prop.PatchStorage { |
| 112 case "rietveld": | 113 case "rietveld": |
| 113 if prop.RietveldURL != "" && prop.Issue != 0 { | 114 if prop.RietveldURL != "" && prop.Issue != 0 { |
| 114 result = &resp.Commit{ | 115 result = &resp.Commit{ |
| 115 Revision: resultDetails.Properties.GotRev
ision, | 116 Revision: resultDetails.Properties.GotRev
ision, |
| 116 RequestRevision: prop.Revision, | 117 RequestRevision: prop.Revision, |
| 117 Changelist: &resp.Link{ | 118 Changelist: &resp.Link{ |
| 118 Label: fmt.Sprintf("Rietveld CL %d", pro
p.Issue), | 119 Label: fmt.Sprintf("Rietveld CL %d", pro
p.Issue), |
| 119 URL: fmt.Sprintf("%s/%d/#ps%d", prop.R
ietveldURL, prop.Issue, prop.PatchSet), | 120 URL: fmt.Sprintf("%s/%d/#ps%d", prop.R
ietveldURL, prop.Issue, prop.PatchSet), |
| 120 }, | 121 }, |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 | 124 |
| 124 case "gerrit": | 125 case "gerrit": |
| 125 » » if prop.GerritURL != "" && prop.GerritChangeNumber != 0 { | 126 » » if prop.GerritPatchURL != "" && prop.GerritPatchIssue != 0 { |
| 127 » » » path := fmt.Sprintf("%d", prop.GerritPatchIssue) |
| 128 » » » if prop.GerritPatchSet != 0 { |
| 129 » » » » path = fmt.Sprintf("%d/%d", prop.GerritPatchIssu
e, prop.GerritPatchSet) |
| 130 » » » } |
| 126 result = &resp.Commit{ | 131 result = &resp.Commit{ |
| 127 Revision: prop.GerritPatchRef, | |
| 128 RequestRevision: prop.GerritPatchRef, | |
| 129 Changelist: &resp.Link{ | 132 Changelist: &resp.Link{ |
| 130 » » » » » Label: fmt.Sprintf("Gerrit CL %d", prop.
GerritChangeNumber), | 133 » » » » » Label: fmt.Sprintf("Gerrit CL %d", prop.
GerritPatchIssue), |
| 131 » » » » » URL: prop.GerritChangeURL, | 134 » » » » » URL: fmt.Sprintf( |
| 135 » » » » » » "%s/c/%s", prop.GerritPatchURL,
path), |
| 132 }, | 136 }, |
| 133 } | 137 } |
| 134 } | 138 } |
| 135 } | 139 } |
| 136 | 140 |
| 137 if result != nil && len(params.Changes) != 0 { | 141 if result != nil && len(params.Changes) != 0 { |
| 138 // tryjobs have one change and it is the CL author | 142 // tryjobs have one change and it is the CL author |
| 139 result.AuthorEmail = params.Changes[0].Author.Email | 143 result.AuthorEmail = params.Changes[0].Author.Email |
| 140 } | 144 } |
| 141 | 145 |
| 142 » return result | 146 » return |
| 143 } | 147 } |
| OLD | NEW |