Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted the ckeditor5-dev-ci package to ESM #997

Merged
merged 8 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const circleUpdateAutoCancelBuilds = require( '../lib/circle-update-auto-cancel-builds' );
import circleUpdateAutoCancelBuilds from '../lib/circle-update-auto-cancel-builds';

/**
* This script updates CircleCI settings to disable the "Auto-cancel redundant workflows" option.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const circleUpdateAutoCancelBuilds = require( '../lib/circle-update-auto-cancel-builds' );
import circleUpdateAutoCancelBuilds from '../lib/circle-update-auto-cancel-builds';

/**
* This script updates CircleCI settings to enable the "Auto-cancel redundant workflows" option.
Expand Down
10 changes: 4 additions & 6 deletions packages/ckeditor5-dev-ci/bin/circle-workflow-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

/* eslint-env node */

'use strict';

const { execSync } = require( 'child_process' );
const fetch = require( 'node-fetch' );
const minimist = require( 'minimist' );
const processJobStatuses = require( '../lib/process-job-statuses' );
import { execSync } from 'child_process';
import fetch from 'node-fetch';
import minimist from 'minimist';
import processJobStatuses from '../lib/process-job-statuses';

// This script allows the creation of a new job within a workflow that will be executed
// in the end, when all other jobs will be finished or errored.
Expand Down
4 changes: 1 addition & 3 deletions packages/ckeditor5-dev-ci/bin/is-job-triggered-by-member.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const isJobTriggeredByMember = require( '../lib/is-job-triggered-by-member' );
import isJobTriggeredByMember from '../lib/is-job-triggered-by-member';

/**
* This script checks if a user that approved an approval job could do that.
Expand Down
6 changes: 3 additions & 3 deletions packages/ckeditor5-dev-ci/bin/notify-circle-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

/* eslint-env node */

const fetch = require( 'node-fetch' );
const slackNotify = require( 'slack-notify' );
const formatMessage = require( '../lib/format-message' );
import fetch from 'node-fetch';
import slackNotify from 'slack-notify';
import formatMessage from '../lib/format-message';

// This script assumes that is being executed on Circle CI.
// Step it is used on should have set value: `when: on_fail`, since it does not
Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-dev-ci/bin/notify-travis-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

/* eslint-env node */

const formatMessage = require( '../lib/format-message' );
const slackNotify = require( 'slack-notify' );
import formatMessage from '../lib/format-message';
import slackNotify from 'slack-notify';

const ALLOWED_BRANCHES = [
'stable',
Expand Down
4 changes: 1 addition & 3 deletions packages/ckeditor5-dev-ci/bin/trigger-circle-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const triggerCircleBuild = require( '../lib/trigger-circle-build' );
import triggerCircleBuild from '../lib/trigger-circle-build';

/**
* This script triggers a new CircleCI build.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const fetch = require( 'node-fetch' );
import nodeFetch from 'node-fetch';

/**
* @param options
Expand All @@ -15,7 +13,7 @@ const fetch = require( 'node-fetch' );
* @param {Boolean} options.newValue
* @return {Promise.<Boolean>}
*/
module.exports = async function circleUpdateAutoCancelBuilds( options ) {
export default async function circleUpdateAutoCancelBuilds( options ) {
const {
circleToken,
githubOrganization,
Expand All @@ -38,6 +36,6 @@ module.exports = async function circleUpdateAutoCancelBuilds( options ) {

const settingsUpdateUrl = `https://circleci.com/api/v2/project/github/${ githubOrganization }/${ githubRepository }/settings`;

return fetch( settingsUpdateUrl, circleRequestOptions )
return nodeFetch( settingsUpdateUrl, circleRequestOptions )
.then( r => r.json() );
};
}
14 changes: 6 additions & 8 deletions packages/ckeditor5-dev-ci/lib/format-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

/* eslint-env node */

'use strict';

const fetch = require( 'node-fetch' );
const bots = require( './data/bots.json' );
const members = require( './data/members.json' );
import nodeFetch from 'node-fetch';
import bots from './data/bots.json';
import members from './data/members.json';

const REPOSITORY_REGEXP = /github\.com\/([^/]+)\/([^/]+)/;

Expand All @@ -29,7 +27,7 @@ const REPOSITORY_REGEXP = /github\.com\/([^/]+)\/([^/]+)/;
* @param {Number} options.endTime
* @param {Boolean} options.shouldHideAuthor
*/
module.exports = async function formatMessage( options ) {
export default async function formatMessage( options ) {
const commitDetails = await getCommitDetails( options.triggeringCommitUrl, options.githubToken );
const repoUrl = `https://github.com/${ options.repositoryOwner }/${ options.repositoryName }`;

Expand Down Expand Up @@ -63,7 +61,7 @@ module.exports = async function formatMessage( options ) {
} ]
} ]
};
};
}

/**
* Returns the additional message that will be added to the notifier post.
Expand Down Expand Up @@ -196,7 +194,7 @@ function getCommitDetails( triggeringCommitUrl, githubToken ) {
}
};

return fetch( apiGithubUrlCommit, options )
return nodeFetch( apiGithubUrlCommit, options )
.then( response => response.json() )
.then( json => ( {
githubAccount: json.author ? json.author.login : null,
Expand Down
4 changes: 1 addition & 3 deletions packages/ckeditor5-dev-ci/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* For licensing, see LICENSE.md.
*/

'use strict';

module.exports = {
export default {
getJobApprover: require( './utils/get-job-approver' ),
members: require( './data/members.json' )
przemyslaw-zan marked this conversation as resolved.
Show resolved Hide resolved
};
10 changes: 4 additions & 6 deletions packages/ckeditor5-dev-ci/lib/is-job-triggered-by-member.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const { Octokit } = require( '@octokit/rest' );
const getJobApprover = require( './utils/get-job-approver' );
import { Octokit } from '@octokit/rest';
import getJobApprover from './utils/get-job-approver';

/**
* @param options
Expand All @@ -18,7 +16,7 @@ const getJobApprover = require( './utils/get-job-approver' );
* @param {String} options.githubToken
* @return {Promise.<Boolean>}
*/
module.exports = async function isJobTriggeredByMember( options ) {
export default async function isJobTriggeredByMember( options ) {
const {
circleToken,
circleWorkflowId,
Expand All @@ -41,4 +39,4 @@ module.exports = async function isJobTriggeredByMember( options ) {
return data
.map( ( { login } ) => login )
.includes( login );
};
}
6 changes: 2 additions & 4 deletions packages/ckeditor5-dev-ci/lib/process-job-statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* For licensing, see LICENSE.md.
*/

'use strict';

/**
* The function aims to determine a proper build status for children's jobs based on their parent's statuses.
*
Expand All @@ -19,7 +17,7 @@
* @param {Array.<WorkflowJob>} jobs
* @returns {Array.<WorkflowJob>}
*/
module.exports = function processJobStatuses( jobs ) {
export default function processJobStatuses( jobs ) {
// To avoid modifying the original object, let's clone.
const jobsClone = clone( jobs );

Expand Down Expand Up @@ -55,7 +53,7 @@ module.exports = function processJobStatuses( jobs ) {
}

return jobsClone;
};
}

/**
* @param {WorkflowJob} job
Expand Down
8 changes: 4 additions & 4 deletions packages/ckeditor5-dev-ci/lib/trigger-circle-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* eslint-env node */

const fetch = require( 'node-fetch' );
import nodeFetch from 'node-fetch';
przemyslaw-zan marked this conversation as resolved.
Show resolved Hide resolved

/**
* @param options
Expand All @@ -17,7 +17,7 @@ const fetch = require( 'node-fetch' );
* @param {String|null} [options.triggerRepositorySlug=null] A repository slug (org/name) that triggers a new build.
* @return {Promise}
*/
module.exports = async function triggerCircleBuild( options ) {
export default async function triggerCircleBuild( options ) {
const {
circleToken,
commit,
Expand Down Expand Up @@ -51,7 +51,7 @@ module.exports = async function triggerCircleBuild( options ) {
body: JSON.stringify( { branch, parameters } )
};

return fetch( requestUrl, requestOptions )
return nodeFetch( requestUrl, requestOptions )
.then( res => res.json() )
.then( response => {
if ( response.error_message ) {
Expand All @@ -62,4 +62,4 @@ module.exports = async function triggerCircleBuild( options ) {
throw new Error( `CI trigger failed: "${ response.message }".` );
}
} );
};
}
12 changes: 5 additions & 7 deletions packages/ckeditor5-dev-ci/lib/utils/get-job-approver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* For licensing, see LICENSE.md.
*/

'use strict';

const fetch = require( 'node-fetch' );
import nodeFetch from 'node-fetch';

/**
* Returns a promise that resolves to GitHub name of a developer who approved the `jobName` job.
Expand All @@ -15,7 +13,7 @@ const fetch = require( 'node-fetch' );
* @param {String} jobName
* @returns {Promise.<String>}
*/
module.exports = async function getJobApprover( circleCiToken, workflowId, jobName ) {
export default async function getJobApprover( circleCiToken, workflowId, jobName ) {
const circleRequestOptions = {
method: 'get',
headers: {
Expand All @@ -27,12 +25,12 @@ module.exports = async function getJobApprover( circleCiToken, workflowId, jobNa

// Find an identifier of a developer who approved an approval job.
const workflowJobsUrl = `https://circleci.com/api/v2/workflow/${ workflowId }/job`;
const workflowJobs = await fetch( workflowJobsUrl, circleRequestOptions ).then( r => r.json() );
const workflowJobs = await nodeFetch( workflowJobsUrl, circleRequestOptions ).then( r => r.json() );
const { approved_by: approvedBy } = workflowJobs.items.find( job => job.name === jobName );

// Find a username based on the identifier.
const userDetailsUrl = `https://circleci.com/api/v2/user/${ approvedBy }`;
const { login } = await fetch( userDetailsUrl, circleRequestOptions ).then( r => r.json() );
const { login } = await nodeFetch( userDetailsUrl, circleRequestOptions ).then( r => r.json() );

return login;
};
}
11 changes: 4 additions & 7 deletions packages/ckeditor5-dev-ci/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"node": ">=18.0.0",
"npm": ">=5.7.1"
},
"type": "module",
"main": "lib/index.js",
"files": [
"bin",
Expand All @@ -39,14 +40,10 @@
"slack-notify": "^2.0.6"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^7.1.2",
"proxyquire": "^2.1.3",
"mockery": "^2.1.0",
"sinon": "^9.2.4"
"vitest": "^2.0.5"
},
"scripts": {
"test": "mocha './tests/**/*.js' --timeout 10000",
"coverage": "nyc --reporter=lcov --reporter=text-summary yarn run test"
"test": "vitest run --config vitest.config.js",
"coverage": "vitest run --config vitest.config.ts --coverage"
pomek marked this conversation as resolved.
Show resolved Hide resolved
}
}

This file was deleted.

Loading