aberlaas-setup 2.14.1 → 2.16.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/lib/circleci.js +7 -5
- package/lib/github.js +46 -14
- package/lib/helpers/github.js +7 -0
- package/lib/renovate.js +37 -9
- package/package.json +2 -2
package/lib/circleci.js
CHANGED
|
@@ -16,21 +16,23 @@ export default {
|
|
|
16
16
|
|
|
17
17
|
// Fail early if no token available
|
|
18
18
|
if (!circleCiHelper.hasToken()) {
|
|
19
|
-
this.__consoleError(
|
|
20
|
-
|
|
21
|
-
);
|
|
19
|
+
this.__consoleError(`CircleCI: ABERLAAS_CIRCLECI_TOKEN environment variable must be set`);
|
|
20
|
+
this.__consoleInfo(` Create a token at CircleCI account settings`);
|
|
21
|
+
this.__consoleInfo(` https://circleci.com/account/api\n`);
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Do nothing if already enabled
|
|
26
26
|
if (await this.isEnabled()) {
|
|
27
|
-
this.
|
|
27
|
+
this.__consoleSuccess(`CircleCI: Already configured`);
|
|
28
|
+
this.__consoleInfo(` ${projectUrl}\n`);
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
// Follow the repo
|
|
32
33
|
await this.followRepo();
|
|
33
|
-
this.__consoleSuccess(`CircleCI
|
|
34
|
+
this.__consoleSuccess(`CircleCI: Repository configured`);
|
|
35
|
+
this.__consoleInfo(` ${projectUrl}\n`);
|
|
34
36
|
return true;
|
|
35
37
|
},
|
|
36
38
|
/**
|
package/lib/github.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { consoleError, consoleSuccess } from 'firost';
|
|
1
|
+
import { consoleError, consoleInfo, consoleSuccess } from 'firost';
|
|
2
|
+
import { _ } from 'golgoth';
|
|
2
3
|
import githubHelper from './helpers/github.js';
|
|
3
4
|
|
|
5
|
+
const gitHubSettings = {
|
|
6
|
+
allow_merge_commit: false,
|
|
7
|
+
allow_rebase_merge: true,
|
|
8
|
+
allow_squash_merge: true,
|
|
9
|
+
delete_branch_on_merge: true,
|
|
10
|
+
};
|
|
11
|
+
|
|
4
12
|
export default {
|
|
5
13
|
/**
|
|
6
14
|
* Configure the GitHub repo with default settings:
|
|
@@ -10,33 +18,57 @@ export default {
|
|
|
10
18
|
*/
|
|
11
19
|
async enable() {
|
|
12
20
|
const { username, repo } = await githubHelper.repoData();
|
|
13
|
-
const
|
|
14
|
-
const manualUrl = `${repoUrl}/settings`;
|
|
21
|
+
const settingsUrl = `https://github.com/${username}/${repo}/settings`;
|
|
15
22
|
|
|
16
23
|
// Fail early if no token available
|
|
17
24
|
if (!githubHelper.hasToken()) {
|
|
18
|
-
this.__consoleError(
|
|
19
|
-
|
|
20
|
-
);
|
|
25
|
+
this.__consoleError(`GitHub: ABERLAAS_GITHUB_TOKEN environment variable must be set`);
|
|
26
|
+
this.__consoleInfo(` Create a Classic token with 'repo' scope`);
|
|
27
|
+
this.__consoleInfo(` https://github.com/settings/tokens\n`);
|
|
21
28
|
return false;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
// Check if already configured
|
|
32
|
+
try {
|
|
33
|
+
if (await this.isAlreadyConfigured()) {
|
|
34
|
+
this.__consoleSuccess(`GitHub: Already configured`);
|
|
35
|
+
this.__consoleInfo(` ${settingsUrl}\n`);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error.status === 401) {
|
|
40
|
+
this.__consoleError(`GitHub: ABERLAAS_GITHUB_TOKEN is invalid`);
|
|
41
|
+
this.__consoleInfo(` Create a Classic token with 'repo' scope`);
|
|
42
|
+
this.__consoleInfo(` https://github.com/settings/tokens\n`);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
30
47
|
|
|
31
48
|
await githubHelper.octokit('repos.update', {
|
|
32
49
|
owner: username,
|
|
33
50
|
repo,
|
|
34
|
-
...
|
|
51
|
+
...gitHubSettings,
|
|
35
52
|
});
|
|
36
53
|
|
|
37
|
-
this.__consoleSuccess(`GitHub
|
|
54
|
+
this.__consoleSuccess(`GitHub: Repository configured`);
|
|
55
|
+
this.__consoleInfo(` ${settingsUrl}\n`);
|
|
38
56
|
return true;
|
|
39
57
|
},
|
|
58
|
+
/**
|
|
59
|
+
* Check if GitHub repo is already configured with desired settings
|
|
60
|
+
* @returns {boolean} True if already configured, false otherwise
|
|
61
|
+
*/
|
|
62
|
+
async isAlreadyConfigured() {
|
|
63
|
+
const { username, repo } = await githubHelper.repoData();
|
|
64
|
+
const repoData = await githubHelper.octokit('repos.get', {
|
|
65
|
+
owner: username,
|
|
66
|
+
repo,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return _.isMatch(repoData, gitHubSettings);
|
|
70
|
+
},
|
|
40
71
|
__consoleSuccess: consoleSuccess,
|
|
72
|
+
__consoleInfo: consoleInfo,
|
|
41
73
|
__consoleError: consoleError,
|
|
42
74
|
};
|
package/lib/helpers/github.js
CHANGED
|
@@ -58,6 +58,12 @@ export default {
|
|
|
58
58
|
const githubToken = this.token();
|
|
59
59
|
this.__cache.octokit = new this.__Octokit({
|
|
60
60
|
auth: githubToken,
|
|
61
|
+
log: {
|
|
62
|
+
debug: this.__noOp,
|
|
63
|
+
info: this.__noOp,
|
|
64
|
+
warn: this.__noOp,
|
|
65
|
+
error: this.__noOp
|
|
66
|
+
}
|
|
61
67
|
});
|
|
62
68
|
}
|
|
63
69
|
|
|
@@ -69,4 +75,5 @@ export default {
|
|
|
69
75
|
__run: run,
|
|
70
76
|
__Octokit: Octokit,
|
|
71
77
|
__cache: {},
|
|
78
|
+
__noOp: () => {},
|
|
72
79
|
};
|
package/lib/renovate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { consoleError, consoleSuccess } from 'firost';
|
|
1
|
+
import { consoleError, consoleInfo, consoleSuccess } from 'firost';
|
|
2
2
|
import githubHelper from './helpers/github.js';
|
|
3
3
|
|
|
4
4
|
export default {
|
|
@@ -23,16 +23,23 @@ export default {
|
|
|
23
23
|
async enable() {
|
|
24
24
|
const { username, repo } = await githubHelper.repoData();
|
|
25
25
|
const manualUrl = `https://github.com/settings/installations/${this.renovateId}`;
|
|
26
|
-
const renovateDashboardUrl = `https://
|
|
26
|
+
const renovateDashboardUrl = `https://developer.mend.io/github/${username}/${repo}`;
|
|
27
27
|
|
|
28
28
|
// Fail early if no token available
|
|
29
29
|
if (!githubHelper.hasToken()) {
|
|
30
|
-
this.__consoleError(
|
|
31
|
-
|
|
32
|
-
);
|
|
30
|
+
this.__consoleError(`Renovate: ABERLAAS_GITHUB_TOKEN environment variable must be set`);
|
|
31
|
+
this.__consoleInfo(` Create a Classic token with 'repo' scope`);
|
|
32
|
+
this.__consoleInfo(` https://github.com/settings/tokens\n`);
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// Check if already enabled
|
|
37
|
+
if (await this.isAlreadyEnabled()) {
|
|
38
|
+
this.__consoleSuccess(`Renovate: Already configured`);
|
|
39
|
+
this.__consoleInfo(` ${renovateDashboardUrl}\n`);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
try {
|
|
37
44
|
const repositoryId = await this.getRepositoryId();
|
|
38
45
|
await githubHelper.octokit('apps.addRepoToInstallation', {
|
|
@@ -40,15 +47,36 @@ export default {
|
|
|
40
47
|
repository_id: repositoryId,
|
|
41
48
|
});
|
|
42
49
|
} catch (_err) {
|
|
43
|
-
this.__consoleError(
|
|
44
|
-
|
|
45
|
-
);
|
|
50
|
+
this.__consoleError(`Renovate is not installed with this GitHub account`);
|
|
51
|
+
this.__consoleInfo(` Please visit the installation page to install it first`);
|
|
52
|
+
this.__consoleInfo(` ${manualUrl}\n`);
|
|
46
53
|
return false;
|
|
47
54
|
}
|
|
48
55
|
|
|
49
|
-
this.__consoleSuccess(`Renovate
|
|
56
|
+
this.__consoleSuccess(`Renovate: Repository configured`);
|
|
57
|
+
this.__consoleInfo(` ${renovateDashboardUrl}\n`);
|
|
50
58
|
return true;
|
|
51
59
|
},
|
|
60
|
+
/**
|
|
61
|
+
* Check if Renovate is already enabled for this repository
|
|
62
|
+
* @returns {boolean} True if already enabled, false otherwise
|
|
63
|
+
*/
|
|
64
|
+
async isAlreadyEnabled() {
|
|
65
|
+
try {
|
|
66
|
+
const { username, repo } = await githubHelper.repoData();
|
|
67
|
+
const installations = await githubHelper.octokit('apps.listReposAccessibleToInstallation', {
|
|
68
|
+
installation_id: this.renovateId,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return installations.repositories.some(
|
|
72
|
+
repoData => repoData.owner.login === username && repoData.name === repo
|
|
73
|
+
);
|
|
74
|
+
} catch {
|
|
75
|
+
// API call fails if Renovate app is not installed - treat as not enabled
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
52
79
|
__consoleSuccess: consoleSuccess,
|
|
80
|
+
__consoleInfo: consoleInfo,
|
|
53
81
|
__consoleError: consoleError,
|
|
54
82
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "aberlaas-setup",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "aberlaas setup helper: Setup third parties like GitHub, Netlify or CircleCI",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.16.0",
|
|
6
6
|
"repository": "pixelastic/aberlaas",
|
|
7
7
|
"homepage": "https://projects.pixelastic.com/aberlaas/",
|
|
8
8
|
"author": "Tim Carry (@pixelastic)",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"golgoth": "3.0.0",
|
|
41
41
|
"parse-github-repo-url": "1.4.1"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "804fd02ef9f200681b17ff72e226078d49619e9c"
|
|
44
44
|
}
|