From 1a9e70a4b47d8f7e2f5fa5f7e11130e2540b58c0 Mon Sep 17 00:00:00 2001 From: Max Flintoff <146855155+maxflintoff-tomtom@users.noreply.github.com> Date: Thu, 12 Sep 2024 11:54:23 +0200 Subject: [PATCH] feat: add feature flag for team creation (#12) * feat: add feature flag for team creation Current behaviour creates a secret team if a team doesn't exist. This adds a feature flag to prevent creating teams unless the feature flag is set * fixup! feat: add feature flag for team creation --- lib/env.js | 4 +++- lib/plugins/teams.js | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/env.js b/lib/env.js index fbc2afed..c613cf4f 100644 --- a/lib/env.js +++ b/lib/env.js @@ -5,5 +5,7 @@ module.exports = { DEPLOYMENT_CONFIG_FILE: process.env.DEPLOYMENT_CONFIG_FILE || 'deployment-settings.yml', CREATE_PR_COMMENT: process.env.CREATE_PR_COMMENT || 'true', CREATE_ERROR_ISSUE: process.env.CREATE_ERROR_ISSUE || 'true', - BLOCK_REPO_RENAME_BY_HUMAN: process.env.BLOCK_REPO_RENAME_BY_HUMAN || 'false' + BLOCK_REPO_RENAME_BY_HUMAN: process.env.BLOCK_REPO_RENAME_BY_HUMAN || 'false', + // If set to true, then when a team is defined in the settings file, it will be created if it does not exist. + FEATURE_CREATE_TEAMS_IF_NOT_EXIST: process.env.FEATURE_CREATE_TEAMS_IF_NOT_EXIST || 'false' } diff --git a/lib/plugins/teams.js b/lib/plugins/teams.js index eaabc468..dd2fbd0c 100644 --- a/lib/plugins/teams.js +++ b/lib/plugins/teams.js @@ -1,5 +1,6 @@ const Diffable = require('./diffable') const NopCommand = require('../nopcommand') +const env = require('../env') const teamRepoEndpoint = '/orgs/:owner/teams/:team_slug/repos/:owner/:repo' module.exports = class Teams extends Diffable { @@ -43,6 +44,10 @@ module.exports = class Teams extends Diffable { }) }).catch(e => { if (e.status === 404) { + if (env.FEATURE_CREATE_TEAMS_IF_NOT_EXIST == 'false') { + this.log.info(`Feature to create teams is disabled. Team ${attrs.name} not found`) + return + } const createParam = { org: this.repo.owner, name: attrs.name