Skip to content

Commit 17c654c

Browse files
authored
Merge pull request #4862 from cloud-gov/feat-create-workshop-site-build-flow-4856
Feat create workshop site build flow 4856
2 parents c0ee107 + 0ce6b62 commit 17c654c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+870
-197
lines changed

.cloudgov/manifest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ applications:
3939
CLOUD_FOUNDRY_OAUTH_TOKEN_URL: https://login.fr.cloud.gov/oauth/token
4040
DOMAIN: ((domain))
4141
FEATURE_FILE_STORAGE_SERVICE: ((feature_file_storage_service))
42+
FEATURE_WORKSHOP_INTEGRATION: ((feature_workshop-integration))
4243
HOMEPAGE_URL: https://cloud.gov/pages
4344
LOG_LEVEL: ((log_level))
4445
NEW_RELIC_APP_NAME: ((new_relic_app_name))

.cloudgov/vars/pages-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ domain: pages-dev.cloud.gov
33
env: dev
44
env_postfix: -dev
55
feature_file_storage_service: "true"
6+
feature_workshop-integration: "true"
67
instances: 2
78
log_level: verbose
89
name: pages-dev

.cloudgov/vars/pages-production.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ domain: pages.cloud.gov
33
env: production
44
env_postfix: -production
55
feature_file_storage_service: "true"
6+
feature_workshop-integration: "false"
67
instances: 4
78
log_level: info
89
name: pages-production

.cloudgov/vars/pages-staging.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ domain: pages-staging.cloud.gov
33
env: staging
44
env_postfix: -staging
55
feature_file_storage_service: "true"
6+
feature_workshop-integration: "false"
67
instances: 2
78
log_level: verbose
89
name: pages-staging

admin-client/src/components/SiteFormWebhook.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
1111
const hookData = hooks.map((hook) => ({
1212
id: hook?.id,
13-
url: hook?.config?.url,
14-
status: hook?.last_response?.status,
15-
message: hook?.last_response?.message,
13+
url: hook?.config?.url || hook?.url,
14+
status: hook?.last_response?.status || hook?.alert_status,
15+
message: hook?.last_response?.message || '',
1616
}));
1717
</script>
1818

api/admin/controllers/site.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
} = require('../../models');
1010
const SiteDestroyer = require('../../services/SiteDestroyer');
1111
const GithubBuildHelper = require('../../services/GithubBuildHelper');
12+
const GitLabHelper = require('../../services/GitLabHelper');
1213
const { fetchModelById } = require('../../utils/queryDatabase');
1314
const { paginate, pick, wrapHandlers } = require('../../utils');
1415
const { serializeNew, serializeMany } = require('../../serializers/site');
@@ -71,7 +72,10 @@ module.exports = wrapHandlers({
7172

7273
const site = await Site.findOne({ where: { id } });
7374
const users = await site.getOrgUsers();
74-
const hook = await GithubBuildHelper.createSiteWebhook(site, users);
75+
const hook =
76+
site.sourceCodePlatform === Site.Platforms.Workshop
77+
? await GitLabHelper.createSiteWebhook(req.user, site)
78+
: await GithubBuildHelper.createSiteWebhook(site, users);
7579

7680
return res.json(hook || []);
7781
},
@@ -83,7 +87,10 @@ module.exports = wrapHandlers({
8387

8488
const site = await Site.findOne({ where: { id } });
8589
const users = await site.getOrgUsers();
86-
const hooks = await GithubBuildHelper.listSiteWebhooks(site, users);
90+
const hooks =
91+
site.sourceCodePlatform === Site.Platforms.Workshop
92+
? await GitLabHelper.listSiteWebhooks(req.user, site)
93+
: await GithubBuildHelper.listSiteWebhooks(site, users);
8794

8895
return res.json(hooks);
8996
},

api/controllers/site.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,15 @@ module.exports = wrapHandlers({
8282

8383
async create(req, res) {
8484
const {
85-
body: { owner, template, organizationId, repository, engine },
85+
body: {
86+
owner,
87+
template,
88+
organizationId,
89+
repository,
90+
engine,
91+
sourceCodePlatform,
92+
sourceCodeUrl,
93+
},
8694
user,
8795
} = req;
8896

@@ -92,6 +100,8 @@ module.exports = wrapHandlers({
92100
organizationId: toInt(organizationId),
93101
repository,
94102
engine,
103+
sourceCodePlatform,
104+
sourceCodeUrl,
95105
};
96106

97107
await authorizer.create(user, siteParams);

api/features.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const Flags = {
88
FEATURE_AWESOME_FEATURE: 'FEATURE_AWESOME_FEATURE',
99
*/
1010
FEATURE_FILE_STORAGE_SERVICE: 'FEATURE_FILE_STORAGE_SERVICE',
11+
FEATURE_WORKSHOP_INTEGRATION: 'FEATURE_WORKSHOP_INTEGRATION',
1112
};
1213

1314
const TRUTHY_VALUES = [true, 'True', 'true', 'TRUE'];

api/models/site.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
const { Op } = require('sequelize');
22
const { toInt } = require('../utils');
3+
const { buildEnum } = require('../utils');
4+
const { buildSourceCodeUrl } = require('../utils/site');
35
const {
46
isEmptyOrBranch,
57
isEmptyOrUrl,
68
isValidSubdomain,
79
} = require('../utils/validators');
810

11+
const SOURCE_CODE_PLATFORM_GITHUB = 'github';
12+
const SOURCE_CODE_PLATFORM_WORKSHOP = 'workshop';
13+
14+
const Platforms = buildEnum([SOURCE_CODE_PLATFORM_GITHUB, SOURCE_CODE_PLATFORM_WORKSHOP]);
15+
const DEFAULT_SOURCE_CODE_PLATFORM = Platforms.Github;
16+
917
const afterValidate = (site) => {
1018
if (site.defaultBranch === site.demoBranch) {
1119
const error = new Error('Default branch and demo branch cannot be the same');
@@ -27,6 +35,33 @@ const validationFailed = (site, options, validationError) => {
2735
throw error;
2836
};
2937

38+
function defaultSourceCodePlatform(site) {
39+
if (!site.sourceCodePlatform) {
40+
site.sourceCodePlatform = DEFAULT_SOURCE_CODE_PLATFORM;
41+
}
42+
}
43+
44+
function defaultSourceCodeUrl(site) {
45+
if (!site.sourceCodeUrl) {
46+
site.sourceCodeUrl = buildSourceCodeUrl(
47+
site.owner,
48+
site.repository,
49+
site.sourceCodePlatform,
50+
Platforms.GitHub,
51+
);
52+
}
53+
}
54+
55+
const beforeCreate = (site) => {
56+
defaultSourceCodePlatform(site);
57+
defaultSourceCodeUrl(site);
58+
};
59+
60+
const beforeUpdate = (site) => {
61+
defaultSourceCodePlatform(site);
62+
defaultSourceCodeUrl(site);
63+
};
64+
3065
const associate = ({
3166
Build,
3267
Domain,
@@ -133,6 +168,9 @@ const beforeValidate = (site) => {
133168
if (site.owner) {
134169
site.owner = site.owner.toLowerCase();
135170
}
171+
172+
defaultSourceCodePlatform(site);
173+
defaultSourceCodeUrl(site);
136174
};
137175

138176
async function getOrgUsers() {
@@ -267,13 +305,28 @@ module.exports = (sequelize, DataTypes) => {
267305
webhookId: {
268306
type: DataTypes.INTEGER,
269307
},
308+
sourceCodePlatform: {
309+
type: DataTypes.ENUM,
310+
values: Platforms.values,
311+
defaultValue: Platforms.Github,
312+
allowNull: false,
313+
validate: {
314+
isIn: [Platforms.values],
315+
},
316+
},
317+
sourceCodeUrl: {
318+
type: DataTypes.STRING,
319+
allowNull: false,
320+
},
270321
},
271322
{
272323
tableName: 'site',
273324
hooks: {
274325
beforeValidate,
275326
afterValidate,
276327
validationFailed,
328+
beforeCreate,
329+
beforeUpdate,
277330
},
278331
paranoid: true,
279332
},
@@ -296,5 +349,6 @@ module.exports = (sequelize, DataTypes) => {
296349
Site.branchFromContext = (context) =>
297350
context === 'site' ? 'defaultBranch' : 'demoBranch';
298351
Site.prototype.getOrgUsers = getOrgUsers;
352+
Site.Platforms = Platforms;
299353
return Site;
300354
};

api/routers/auth.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const router = require('express').Router();
22
const { Event, User } = require('../models');
33
const passport = require('../services/passport');
44
const EventCreator = require('../services/EventCreator');
5+
const Features = require('../features');
56

67
function redirectIfAuthenticated(req, res, next) {
78
req.session.authenticated ? res.redirect('/') : next();
@@ -72,23 +73,25 @@ router.get(
7273
onGithubSuccess,
7374
);
7475

75-
router.get('/auth/gitlab', passport.authenticate('gitlab'));
76-
router.get(
77-
'/auth/gitlab/callback',
78-
passport.authenticate('gitlab', { session: false }),
79-
async (req, res) => {
80-
await EventCreator.audit(
81-
Event.labels.AUTHENTICATION_PAGES_GL_TOKEN,
82-
req.user,
83-
'GitLab authentication for token',
84-
);
76+
if (Features.enabled(Features.Flags.FEATURE_WORKSHOP_INTEGRATION)) {
77+
router.get('/auth/gitlab', passport.authenticate('gitlab'));
78+
router.get(
79+
'/auth/gitlab/callback',
80+
passport.authenticate('gitlab', { session: false }),
81+
async (req, res) => {
82+
await EventCreator.audit(
83+
Event.labels.AUTHENTICATION_PAGES_GL_TOKEN,
84+
req.user,
85+
'GitLab authentication for token',
86+
);
8587

86-
res.send(`
88+
res.send(`
8789
<script nonce="${res.locals.cspNonce}">
8890
window.opener.postMessage("success", "*")
8991
</script>
9092
`);
91-
},
92-
);
93+
},
94+
);
95+
}
9396

9497
module.exports = router;

0 commit comments

Comments
 (0)