@ckeditor/ckeditor5-dev-release-tools 61.0.0 → 61.1.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/index.js CHANGED
@@ -32,3 +32,4 @@ export { default as executeInParallel } from './utils/executeinparallel.js';
32
32
  export { default as validateRepositoryToRelease } from './utils/validaterepositorytorelease.js';
33
33
  export { default as getNpmTagFromVersion } from './utils/getnpmtagfromversion.js';
34
34
  export { default as provideToken } from './utils/providetoken.js';
35
+ export { default as validateGithubToken } from './utils/validategithubtoken.js';
@@ -26,6 +26,7 @@ const { normalizeTrim } = upath;
26
26
  * for a dependency. It receives a package name as an argument and should return a boolean value.
27
27
  * @param {UpdateDependenciesPackagesDirectoryFilter|null} [options.packagesDirectoryFilter=null] An optional callback allowing
28
28
  * filtering out directories/packages that should not be touched by the task.
29
+ * @param {boolean} [options.includeCwd=true] Whether to update dependencies in the package located directly in `options.cwd`.
29
30
  * @param {string} [options.packagesDirectory] Relative path to a location of packages to update their dependencies. If not specified,
30
31
  * only the root package is checked.
31
32
  * @param {string} [options.cwd=process.cwd()] Current working directory from which all paths will be resolved.
@@ -37,6 +38,7 @@ export default async function updateDependencies( options ) {
37
38
  packagesDirectory,
38
39
  shouldUpdateVersionCallback,
39
40
  packagesDirectoryFilter = null,
41
+ includeCwd = true,
40
42
  cwd = process.cwd()
41
43
  } = options;
42
44
 
@@ -45,7 +47,7 @@ export default async function updateDependencies( options ) {
45
47
  packagesDirectory ? normalizeTrim( packagesDirectory ) : null,
46
48
  {
47
49
  includePackageJson: true,
48
- includeCwd: true,
50
+ includeCwd,
49
51
  packagesDirectoryFilter
50
52
  }
51
53
  );
@@ -4,23 +4,32 @@
4
4
  */
5
5
 
6
6
  import inquirer from 'inquirer';
7
+ import validateGithubToken from './validategithubtoken.js';
7
8
 
8
9
  /**
9
10
  * Asks a user for providing the GitHub token.
10
11
  *
12
+ * @param {object} [options]
13
+ * @param {string} [options.cwd=process.cwd()] Current working directory from which the repository will be resolved.
11
14
  * @returns {Promise.<string>}
12
15
  */
13
- export default async function provideToken() {
16
+ export default async function provideToken( { cwd = process.cwd() } = {} ) {
14
17
  const tokenQuestion = {
15
18
  type: 'password',
16
19
  name: 'token',
17
20
  message: 'Provide the GitHub token:',
18
- validate( input ) {
19
- return input.length === 40 ? true : 'Please provide a valid token.';
21
+ async validate( input ) {
22
+ try {
23
+ await validateGithubToken( input, { cwd } );
24
+
25
+ return true;
26
+ } catch ( error ) {
27
+ return error.message;
28
+ }
20
29
  }
21
30
  };
22
31
 
23
32
  const { token } = await inquirer.prompt( [ tokenQuestion ] );
24
33
 
25
- return token;
34
+ return token.trim();
26
35
  }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md.
4
+ */
5
+
6
+ import { Octokit } from '@octokit/rest';
7
+ import { workspaces } from '@ckeditor/ckeditor5-dev-utils';
8
+
9
+ const VALIDATION_TAG_NAME = 'ckeditor5-dev-release-tools-token-validation';
10
+
11
+ /**
12
+ * Verifies that a GitHub token can create a release in the current repository.
13
+ *
14
+ * @param {string} token Token used to authenticate with GitHub.
15
+ * @param {object} options
16
+ * @param {string} options.cwd=process.cwd() Current working directory from which the repository will be resolved.
17
+ * @returns {Promise.<string>} The normalized token.
18
+ */
19
+ export default async function validateGithubToken( token, { cwd } ) {
20
+ const normalizedToken = token.trim();
21
+
22
+ if ( !normalizedToken ) {
23
+ throw new Error( 'The token cannot be empty.' );
24
+ }
25
+
26
+ const repositoryUrl = workspaces.getRepositoryUrl( cwd );
27
+ const [ repositoryName, repositoryOwner ] = repositoryUrl.split( '/' ).reverse();
28
+ const repository = `${ repositoryOwner }/${ repositoryName }`;
29
+ const github = new Octokit( { auth: normalizedToken } );
30
+
31
+ let repositoryDetails;
32
+
33
+ try {
34
+ repositoryDetails = await github.repos.get( {
35
+ owner: repositoryOwner,
36
+ repo: repositoryName
37
+ } );
38
+ } catch ( error ) {
39
+ throw createValidationError( error, repository );
40
+ }
41
+
42
+ try {
43
+ // This endpoint only computes and returns proposed release notes. It does not persist a release, tag, or any other data.
44
+ // See: https://docs.github.com/en/rest/releases/releases#generate-release-notes-content-for-a-release
45
+ await github.repos.generateReleaseNotes( {
46
+ owner: repositoryOwner,
47
+ repo: repositoryName,
48
+ tag_name: VALIDATION_TAG_NAME,
49
+ target_commitish: repositoryDetails.data.default_branch
50
+ } );
51
+ } catch ( error ) {
52
+ throw createValidationError( error, repository );
53
+ }
54
+
55
+ return normalizedToken;
56
+ }
57
+
58
+ /**
59
+ * @param {Error & { status?: number, response?: { data?: { message?: string } } }} error
60
+ * @param {string} repository
61
+ * @returns {Error}
62
+ */
63
+ function createValidationError( error, repository ) {
64
+ const githubMessage = error.response?.data?.message || error.message;
65
+
66
+ if ( error.status ) {
67
+ return new Error( `GitHub API request for the "${ repository }" repository failed ` +
68
+ `with HTTP ${ error.status }: ${ githubMessage }` );
69
+ }
70
+
71
+ return new Error( `Could not verify the token for the "${ repository }" repository: ${ githubMessage }` );
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-dev-release-tools",
3
- "version": "61.0.0",
3
+ "version": "61.1.0",
4
4
  "description": "Tools used for releasing CKEditor 5 and related packages.",
5
5
  "keywords": [],
6
6
  "author": "CKSource (http://cksource.com/)",
@@ -22,7 +22,7 @@
22
22
  "lib"
23
23
  ],
24
24
  "dependencies": {
25
- "@ckeditor/ckeditor5-dev-utils": "^61.0.0",
25
+ "@ckeditor/ckeditor5-dev-utils": "^61.1.0",
26
26
  "@octokit/rest": "^22.0.1",
27
27
  "cli-columns": "^4.0.0",
28
28
  "glob": "^13.0.6",