screwdriver-api 7.0.20 → 7.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "7.0.20",
3
+ "version": "7.0.22",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "pretest": "eslint . --quiet",
8
8
  "test": "nyc --report-dir ./artifacts/coverage --reporter=lcov mocha --reporter mocha-multi-reporters --reporter-options configFile=./mocha.config.json --recursive --timeout 10000 --retries 1 --exit --allow-uncaught true --color true",
9
- "test-debug": "mocha --inspect ./test/**/*.js",
9
+ "test-debug": "mocha --inspect-brk ./test/**/*.js",
10
10
  "start": "./bin/server",
11
11
  "debug": "node --nolazy ./bin/server",
12
12
  "profile": "node --prof ./bin/server",
@@ -105,7 +105,7 @@
105
105
  "screwdriver-config-parser": "^8.0.1",
106
106
  "screwdriver-coverage-bookend": "^2.0.0",
107
107
  "screwdriver-coverage-sonar": "^4.1.1",
108
- "screwdriver-data-schema": "^22.9.3",
108
+ "screwdriver-data-schema": "^22.9.8",
109
109
  "screwdriver-datastore-sequelize": "^8.0.0",
110
110
  "screwdriver-executor-base": "^9.0.1",
111
111
  "screwdriver-executor-docker": "^6.0.0",
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  const boom = require('@hapi/boom');
4
- const COVERAGE_SCOPE_ANNOTATION = 'screwdriver.cd/coverageScope';
5
-
4
+ const logger = require('screwdriver-logger');
6
5
  const CoveragePlugin = require('screwdriver-coverage-bookend');
7
6
 
7
+ const COVERAGE_SCOPE_ANNOTATION = 'screwdriver.cd/coverageScope';
8
+
8
9
  module.exports = config => ({
9
10
  method: 'GET',
10
11
  path: '/coverage/token',
@@ -53,10 +54,11 @@ module.exports = config => ({
53
54
  ? job.permutations[0].annotations[COVERAGE_SCOPE_ANNOTATION]
54
55
  : null;
55
56
  }
57
+ let pipeline;
56
58
 
57
59
  // Get pipeline name
58
60
  if (pipelineId && (!projectName || projectName.includes('undefined'))) {
59
- const pipeline = await pipelineFactory.get(pipelineId);
61
+ pipeline = await pipelineFactory.get(pipelineId);
60
62
 
61
63
  if (!pipeline) {
62
64
  throw boom.notFound(`Pipeline ${pipelineId} does not exist`);
@@ -80,6 +82,45 @@ module.exports = config => ({
80
82
 
81
83
  const selfSonar = new CoveragePlugin(selfSonarConfig);
82
84
  const data = await selfSonar.coveragePlugin.getAccessToken(tokenConfig);
85
+ const projectUrl = selfSonar.coveragePlugin.getProjectData(tokenConfig);
86
+
87
+ if (pipeline && projectUrl) {
88
+ try {
89
+ const pipelineSonarBadge = {
90
+ defaultName: pipelineId,
91
+ defaultUri: projectUrl
92
+ };
93
+ let shouldPipelineUpdate = true;
94
+
95
+ if (
96
+ pipeline.badges &&
97
+ pipeline.badges.sonar &&
98
+ pipeline.badges.sonar.defaultName === pipelineId &&
99
+ pipeline.badges.sonar.defaultUri === projectUrl
100
+ ) {
101
+ shouldPipelineUpdate = false;
102
+ }
103
+
104
+ if (shouldPipelineUpdate) {
105
+ if (pipeline.badges) {
106
+ pipeline.badges.sonar = pipelineSonarBadge;
107
+ } else {
108
+ pipeline.badges = {
109
+ sonar: pipelineSonarBadge
110
+ };
111
+ }
112
+
113
+ await pipeline.update();
114
+ logger.info(
115
+ `update pipeline:${pipeline.id}'s sonar badge with defaultName:${pipelineId}, defaultUri: ${projectUrl}`
116
+ );
117
+ }
118
+ } catch (err) {
119
+ logger.error(`Failed to update pipeline:${pipelineId}`, err);
120
+
121
+ throw err;
122
+ }
123
+ }
83
124
 
84
125
  return h.response(data);
85
126
  }
@@ -147,7 +147,16 @@ module.exports = () => ({
147
147
  }
148
148
 
149
149
  if (badges) {
150
- oldPipeline.badges = { ...oldPipeline.badges, ...badges };
150
+ if (!oldPipeline.badges) {
151
+ oldPipeline.badges = badges;
152
+ } else {
153
+ Object.keys(oldPipeline.badges).forEach(badgeKey => {
154
+ oldPipeline.badges[badgeKey] = {
155
+ ...oldPipeline.badges[badgeKey],
156
+ ...badges[badgeKey]
157
+ };
158
+ });
159
+ }
151
160
  }
152
161
 
153
162
  // update pipeline