diff options
author | Wouter Admiraal <wouter.admiraal@sonarsource.com> | 2019-03-26 12:01:16 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-03-29 09:44:58 +0100 |
commit | 496a64705bb03ea7748d140698b5dbbc1af31325 (patch) | |
tree | 2f95389bad9ec095ce7d71758fd03760139807fa /server | |
parent | fab2c03c220b71afaa441f38bb81637a1cdfd4ce (diff) | |
download | sonarqube-496a64705bb03ea7748d140698b5dbbc1af31325.tar.gz sonarqube-496a64705bb03ea7748d140698b5dbbc1af31325.zip |
Unwrap the projectStatus property from the /api/qualitygates/project_status WS
Instead of continuously unwrapping this property from the payload in calling code,
immediately use it when receving the result from the API call.
Diffstat (limited to 'server')
5 files changed, 26 insertions, 28 deletions
diff --git a/server/sonar-web/src/main/js/api/quality-gates.ts b/server/sonar-web/src/main/js/api/quality-gates.ts index c6310ae13b7..29809c00691 100644 --- a/server/sonar-web/src/main/js/api/quality-gates.ts +++ b/server/sonar-web/src/main/js/api/quality-gates.ts @@ -173,5 +173,7 @@ export function getQualityGateProjectStatus( projectId?: string; } & T.BranchParameters ): Promise<T.QualityGateProjectStatus> { - return getJSON('/api/qualitygates/project_status', data).catch(throwGlobalError); + return getJSON('/api/qualitygates/project_status', data) + .then(r => r.projectStatus) + .catch(throwGlobalError); } diff --git a/server/sonar-web/src/main/js/app/types.d.ts b/server/sonar-web/src/main/js/app/types.d.ts index 340ebfa96c6..92aefb08734 100644 --- a/server/sonar-web/src/main/js/app/types.d.ts +++ b/server/sonar-web/src/main/js/app/types.d.ts @@ -655,11 +655,9 @@ declare namespace T { } export interface QualityGateProjectStatus { - projectStatus: { - conditions?: QualityGateProjectStatusCondition[]; - ignoredConditions: boolean; - status: Status; - }; + conditions?: QualityGateProjectStatusCondition[]; + ignoredConditions: boolean; + status: Status; } export interface QualityGateStatusCondition { diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/ReviewApp.tsx b/server/sonar-web/src/main/js/apps/overview/pullRequests/ReviewApp.tsx index f1d413efed9..fb9a2869579 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/ReviewApp.tsx +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/ReviewApp.tsx @@ -92,11 +92,11 @@ export class ReviewApp extends React.Component<Props, State> { }), getQualityGateProjectStatus(data) ]).then( - ([measures, qualityGateStatus]) => { - if (this.mounted && measures && qualityGateStatus) { - const { status } = qualityGateStatus.projectStatus; + ([measures, projectStatus]) => { + if (this.mounted && measures && projectStatus) { + const { status } = projectStatus; this.setState({ - conditions: extractStatusConditionsFromProjectStatus(qualityGateStatus), + conditions: extractStatusConditionsFromProjectStatus(projectStatus), loading: false, measures, status diff --git a/server/sonar-web/src/main/js/helpers/qualityGates.ts b/server/sonar-web/src/main/js/helpers/qualityGates.ts index ebdb09f172e..11c63b2ed97 100644 --- a/server/sonar-web/src/main/js/helpers/qualityGates.ts +++ b/server/sonar-web/src/main/js/helpers/qualityGates.ts @@ -18,9 +18,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ export function extractStatusConditionsFromProjectStatus( - status: T.QualityGateProjectStatus + projectStatus: T.QualityGateProjectStatus ): T.QualityGateStatusCondition[] { - const { conditions } = status.projectStatus; + const { conditions } = projectStatus; return conditions ? conditions.map(c => ({ actual: c.actualValue, diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts index 5ba89478c2d..f324b833caf 100644 --- a/server/sonar-web/src/main/js/helpers/testMocks.ts +++ b/server/sonar-web/src/main/js/helpers/testMocks.ts @@ -294,24 +294,22 @@ export function mockQualityProfile(overrides: Partial<Profile> = {}): Profile { } export function mockQualityGateProjectStatus( - overrides: Partial<T.QualityGateProjectStatus['projectStatus']> = {} + overrides: Partial<T.QualityGateProjectStatus> = {} ): T.QualityGateProjectStatus { return { - projectStatus: { - conditions: [ - { - actualValue: '0', - comparator: 'GT', - errorThreshold: '1.0', - metricKey: 'new_bugs', - periodIndex: 1, - status: 'OK' - } - ], - ignoredConditions: false, - status: 'OK', - ...overrides - } + conditions: [ + { + actualValue: '0', + comparator: 'GT', + errorThreshold: '1.0', + metricKey: 'new_bugs', + periodIndex: 1, + status: 'OK' + } + ], + ignoredConditions: false, + status: 'OK', + ...overrides }; } |