aberlaas-setup 2.10.0

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/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Tim Carry (tim@pixelastic.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ import { _ } from 'golgoth';
2
+ import { consoleError, consoleInfo, consoleSuccess } from 'firost';
3
+ import circleCiHelper from './helpers/circleci.js';
4
+ import githubHelper from './helpers/github.js';
5
+
6
+ export default {
7
+ /**
8
+ * Attempt to automatically follow the repo in CircleCI if possible, otherwise
9
+ * display the link to follow it manually
10
+ * @returns {boolean} True if enabled, false otherwise
11
+ */
12
+ async enable() {
13
+ const { username, repo } = await githubHelper.repoData();
14
+ const projectUrl = `https://app.circleci.com/pipelines/github/${username}/${repo}`;
15
+ const followUrl = `https://app.circleci.com/projects/project-setup/github/${username}/${repo}`;
16
+
17
+ // Fail early if no token available
18
+ if (!circleCiHelper.hasToken()) {
19
+ this.__consoleError(
20
+ `[circleci]: No CIRCLECI_TOKEN found, please visit ${followUrl} to enable manually.`,
21
+ );
22
+ return false;
23
+ }
24
+
25
+ // Do nothing if already enabled
26
+ if (await this.isEnabled()) {
27
+ this.__consoleInfo(`CircleCI already enabled: ${projectUrl}`);
28
+ return true;
29
+ }
30
+
31
+ // Follow the repo
32
+ await this.followRepo();
33
+ this.__consoleSuccess(`CircleCI enabled: ${projectUrl}`);
34
+ return true;
35
+ },
36
+ /**
37
+ * Check if CircleCI is already enabled for this project
38
+ * @returns {boolean} True if already enabled, false otherwise
39
+ */
40
+ async isEnabled() {
41
+ // There is no endpoint to check if a project is followed or not, so we get
42
+ // the list of all followed projects and check if the current one is in it
43
+ const allProjects = await circleCiHelper.api('projects');
44
+ const { username, repo } = await githubHelper.repoData();
45
+ const thisProject = _.find(allProjects, { username, reponame: repo });
46
+ return !!thisProject;
47
+ },
48
+ /**
49
+ * Automatically follow the repo on CircleCI.
50
+ */
51
+ async followRepo() {
52
+ const { username, repo } = await githubHelper.repoData();
53
+ await circleCiHelper.api(`project/github/${username}/${repo}/follow`, {
54
+ method: 'post',
55
+ });
56
+ },
57
+ __consoleInfo: consoleInfo,
58
+ __consoleSuccess: consoleSuccess,
59
+ __consoleError: consoleError,
60
+ };
package/lib/github.js ADDED
@@ -0,0 +1,42 @@
1
+ import { consoleError, consoleSuccess } from 'firost';
2
+ import githubHelper from './helpers/github.js';
3
+
4
+ export default {
5
+ /**
6
+ * Configure the GitHub repo with default settings:
7
+ * - Do not enable merge commits on PR
8
+ * - Automatically delete branches after PR merge
9
+ * @returns {boolean} True if enabled, false otherwise
10
+ */
11
+ async enable() {
12
+ const { username, repo } = await githubHelper.repoData();
13
+ const repoUrl = `https://github.com/${username}/${repo}`;
14
+ const manualUrl = `${repoUrl}/settings`;
15
+
16
+ // Fail early if no token available
17
+ if (!githubHelper.hasToken()) {
18
+ this.__consoleError(
19
+ `[github]: No GITHUB_TOKEN found, please visit ${manualUrl} to configure manually.`,
20
+ );
21
+ return false;
22
+ }
23
+
24
+ const settings = {
25
+ allow_merge_commit: false,
26
+ allow_rebase_merge: true,
27
+ allow_squash_merge: true,
28
+ delete_branch_on_merge: true,
29
+ };
30
+
31
+ await githubHelper.octokit('repos.update', {
32
+ owner: username,
33
+ repo,
34
+ ...settings,
35
+ });
36
+
37
+ this.__consoleSuccess(`GitHub repo configured: ${repoUrl}`);
38
+ return true;
39
+ },
40
+ __consoleSuccess: consoleSuccess,
41
+ __consoleError: consoleError,
42
+ };
package/lib/main.js ADDED
@@ -0,0 +1,52 @@
1
+ import { _ } from 'golgoth';
2
+ import github from './github.js';
3
+ import circleci from './circleci.js';
4
+ import renovate from './renovate.js';
5
+
6
+ export default {
7
+ /**
8
+ * Enable external services.
9
+ * Will enable CircleCI, GitHub and Renovate by default.
10
+ * @param {object} cliArgs CLI Argument object, as created by minimist
11
+ */
12
+ async run(cliArgs = {}) {
13
+ const defaultServices = {
14
+ circleci: true,
15
+ renovate: true,
16
+ github: true,
17
+ };
18
+ const cliServices = _.omit(cliArgs, ['_']);
19
+ const servicesToEnable = {
20
+ ...defaultServices,
21
+ ...cliServices,
22
+ };
23
+
24
+ if (servicesToEnable.github) {
25
+ await this.github();
26
+ }
27
+ if (servicesToEnable.circleci) {
28
+ await this.circleci();
29
+ }
30
+ if (servicesToEnable.renovate) {
31
+ await this.renovate();
32
+ }
33
+ },
34
+ /**
35
+ * Configure GitHub
36
+ */
37
+ async github() {
38
+ await github.enable();
39
+ },
40
+ /**
41
+ * Enable CircleCI
42
+ */
43
+ async circleci() {
44
+ await circleci.enable();
45
+ },
46
+ /**
47
+ * Enable renovate
48
+ */
49
+ async renovate() {
50
+ await renovate.enable();
51
+ },
52
+ };
@@ -0,0 +1,54 @@
1
+ import { consoleError, consoleSuccess } from 'firost';
2
+ import githubHelper from './helpers/github.js';
3
+
4
+ export default {
5
+ renovateId: 2471197,
6
+ /**
7
+ * Returns the GitHub repository Id
8
+ * @returns {number} Repository Id
9
+ */
10
+ async getRepositoryId() {
11
+ const { username, repo } = await githubHelper.repoData();
12
+ const { id } = await githubHelper.octokit('repos.get', {
13
+ owner: username,
14
+ repo,
15
+ });
16
+ return id;
17
+ },
18
+ /**
19
+ * Attempt to automatically add the current repo to renovate, otherwise
20
+ * display the link to do it manually
21
+ * @returns {boolean} True if enabled, false otherwise
22
+ */
23
+ async enable() {
24
+ const { username, repo } = await githubHelper.repoData();
25
+ const manualUrl = `https://github.com/settings/installations/${this.renovateId}`;
26
+ const renovateDashboardUrl = `https://app.renovatebot.com/dashboard#github/${username}/${repo}`;
27
+
28
+ // Fail early if no token available
29
+ if (!githubHelper.hasToken()) {
30
+ this.__consoleError(
31
+ `[renovate]: No GITHUB_TOKEN found, please visit ${manualUrl} to enable manually.`,
32
+ );
33
+ return false;
34
+ }
35
+
36
+ try {
37
+ const repositoryId = await this.getRepositoryId();
38
+ await githubHelper.octokit('apps.addRepoToInstallation', {
39
+ installation_id: this.renovateId,
40
+ repository_id: repositoryId,
41
+ });
42
+ } catch (_err) {
43
+ this.__consoleError(
44
+ `Renovate is not installed with this GitHub account, please visit ${manualUrl} to install it first.`,
45
+ );
46
+ return false;
47
+ }
48
+
49
+ this.__consoleSuccess(`Renovate enabled: ${renovateDashboardUrl}`);
50
+ return true;
51
+ },
52
+ __consoleSuccess: consoleSuccess,
53
+ __consoleError: consoleError,
54
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "aberlaas-setup",
3
+ "type": "module",
4
+ "description": "aberlaas setup helper: Setup third parties like GitHub, Netlify or CircleCI",
5
+ "version": "2.10.0",
6
+ "repository": "pixelastic/aberlaas",
7
+ "homepage": "https://projects.pixelastic.com/aberlaas/",
8
+ "author": "Tim Carry (@pixelastic)",
9
+ "license": "MIT",
10
+ "files": [
11
+ "lib/*.js"
12
+ ],
13
+ "exports": {
14
+ ".": "./lib/main.js"
15
+ },
16
+ "main": "./lib/main.js",
17
+ "engines": {
18
+ "node": ">=18.18.0"
19
+ },
20
+ "scripts": {
21
+ "build": "../../scripts/local/build",
22
+ "build:prod": "../../scripts/local/build-prod",
23
+ "cms": "../../scripts/local/cms",
24
+ "serve": "../../scripts/local/serve",
25
+ "ci": "../../scripts/local/ci",
26
+ "release": "../../scripts/local/release",
27
+ "update": "node ../../scripts/meta/update.js",
28
+ "test:meta": "../../scripts/local/test-meta",
29
+ "test": "../../scripts/local/test",
30
+ "test:watch": "../../scripts/local/test-watch",
31
+ "compress": "../../scripts/local/compress",
32
+ "lint": "../../scripts/local/lint",
33
+ "lint:fix": "../../scripts/local/lint-fix"
34
+ },
35
+ "dependencies": {
36
+ "@octokit/rest": "21.0.2",
37
+ "aberlaas-helper": "^2.10.0",
38
+ "firost": "4.3.0",
39
+ "golgoth": "2.4.0",
40
+ "parse-github-repo-url": "1.4.1"
41
+ },
42
+ "gitHead": "bcdaf87c198a588e02b5539c222f611e356d3079"
43
+ }