screwdriver-api 7.0.243 → 7.0.244
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 +1 -1
- package/plugins/builds/update.js +17 -2
package/package.json
CHANGED
package/plugins/builds/update.js
CHANGED
|
@@ -37,7 +37,6 @@ async function getBuildToUpdate(id, buildFactory) {
|
|
|
37
37
|
async function validateUserPermission(build, request) {
|
|
38
38
|
const { jobFactory, userFactory, bannerFactory, pipelineFactory } = request.server.app;
|
|
39
39
|
const { username, scmContext, scmUserId } = request.auth.credentials;
|
|
40
|
-
|
|
41
40
|
const { status: desiredStatus } = request.payload;
|
|
42
41
|
|
|
43
42
|
const scmDisplayName = bannerFactory.scm.getDisplayName({ scmContext });
|
|
@@ -66,6 +65,20 @@ async function validateUserPermission(build, request) {
|
|
|
66
65
|
await getUserPermissions({ user, scmUri, level: 'push', isAdmin: adminDetails.isAdmin });
|
|
67
66
|
}
|
|
68
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Prevent duplicate builds with the same build ID
|
|
70
|
+
* @param {Object} build Build object
|
|
71
|
+
* @param {Object} request hapi request object
|
|
72
|
+
* @throws boom.forbidden error
|
|
73
|
+
*/
|
|
74
|
+
async function preventDuplicateBuild(build, request) {
|
|
75
|
+
const { status: desiredStatus } = request.payload;
|
|
76
|
+
|
|
77
|
+
if (build.status === 'RUNNING' && desiredStatus === 'RUNNING') {
|
|
78
|
+
throw boom.forbidden(`Can not update status to RUNNING. Build Id: ${build.id} is still running.`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
69
82
|
module.exports = () => ({
|
|
70
83
|
method: 'PUT',
|
|
71
84
|
path: '/builds/{id}',
|
|
@@ -91,7 +104,9 @@ module.exports = () => ({
|
|
|
91
104
|
|
|
92
105
|
const build = await getBuildToUpdate(id, buildFactory);
|
|
93
106
|
|
|
94
|
-
if (
|
|
107
|
+
if (isBuild) {
|
|
108
|
+
await preventDuplicateBuild(build, request);
|
|
109
|
+
} else {
|
|
95
110
|
await validateUserPermission(build, request);
|
|
96
111
|
}
|
|
97
112
|
|